Study notes-commonly used basic commands in Linux

Record your own process of learning Linux


Preface

本篇命令基于Centos Linux


Common commands in Linux

1. Files and Directories

1.ls (list directory)

Insert image description here-l :长数据串列出,包含文件的属性与权限等等数据;(常用)
Insert image description here

2.cd (switch directory)

使用绝对路径切换到test目录
Insert image description here使用相对路径切换到test目录
Insert image description here回到自己的家目录,即是 /root 这个目录
Insert image description here

3.pwd (displays the current directory)

显示目前所在目录的命令
Insert image description here

4.mkdir (create new directory)/rmdir (delete empty directory)

创建新的目录的命令
Insert image description here
删除目录的命令
Insert image description herermdir 仅能删除空的目录,可以使用 rm 命令来删除非空目录。

5.cp (copy files or directories)

即拷贝文件和目录的命令
Insert image description here

6.mv (move files and directories, or change names)

复制一文件 — 创建一目录 — 将文件移动纸至新目录 — 重命名目录
Insert image description here

7.Linux file content viewing

Linux系统中使用以下命令来查看文件的内容:
cat prints the file content to the console
more and displays the file content page by page
less. Based on more, you can perform search and other operations.
head displays the first few lines.
tail displays the last few lines
. tail -f catalina.out will dynamically obtain the log file. renew

Example: Show /etc/passwd on lines 6-10: head -10 /etc/passwd tail -5


2. Management of Linux system user/user group accounts

1. Add a new user account using the useradd command

此命令创建了一个用户sam,其中-d和-m选项用来为登录名sam产生一个主目录 /home/sam
Insert image description here

2. Delete the account using the userdel command

删除一个已有的用户账号使用userdel+【用户名】命令,命令如下:
Insert image description here

3. Modify the account using the usermod command

修改已有用户的信息使用usermod+【用户名】命令,命令如下:
Insert image description here

Commonly used options include -c, -d, -m, -g, -G, -s, -u and -o, etc.

4. To add a new user group, use the groupadd command

Insert image description here

The options available are:

-g GID Specifies the group identification number (GID) of the new user group.
-o is generally used together with the -g option, indicating that the GID of the new user group can be the same as the GID of the existing user group in the system.

5. To delete an existing user group, use the groupdel command

Insert image description here

6. To delete an existing user group, use the groupdel command

Insert image description here

Commonly used options are:

-g GID Specifies a new group identification number for the user group.
-o is used with the -g option at the same time. The new GID of the user group can be the same as the GID of the existing user group in the system.
-n new user group changes the name of the user group to a new name

三.Linux vi/vim

Vim is a text editor developed from vi. It is particularly rich in functions that facilitate programming, such as code completion, compilation, and error jumping, and is widely used among programmers.

To put it simply, vi is an old-fashioned word processor, but its functions are already very complete, but there is still room for improvement. vim can be said to be a very useful tool for program developers.

Even vim's official website (https://www.vim.org/) itself says that vim is a program development tool rather than a word processing software.

1.Usage of vi/vim

基本上 vi/vim 共分为三种模式,分别是命令模式(Command mode),输入模式(Insert mode)和底线命令模式(Last line mode)。 这三种模式的作用分别是:

Command mode:

Start vi/vim and enter the command mode

The following are some commonly used commands:

i Switch to input mode to enter characters.
x Delete the character at the current cursor position.
: Switch to bottom line command mode to enter commands on the bottom line.

若想要编辑文本:启动Vim,进入了命令模式,按下i/a,切换到输入模式。

Input mode:

Press i/a in command mode to enter input mode.

In input mode, the following keys are available:

Character keys and Shift combination, input characters
ENTER, enter key, line feed
BACK SPACE, backspace key, delete the character before the cursor
DEL, delete key, delete the character after the
cursor Direction keys, move the cursor in the text
HOME/END, move the cursor
Page Up/Page Down to the beginning/end of the line ,
Insert to turn the page up/down, switch the cursor to the input/replacement mode, the cursor will become a vertical bar/underline
ESC, exit the input mode, switch to the command mode

Bottom line command pattern:

In the bottom line command mode, the basic commands are:

:q Exit the program
:w Save the file
:wq Save and exit
:x Save and exit

按ESC键可随时退出底线命令模式。

Guess you like

Origin blog.csdn.net/weixin_50564363/article/details/131377219