Linux common and commonly used commands (2)


提示:以下是本篇文章正文内容,下面案例仅供参考

1. cd command

1. Command format

cd [目录]

2. Function description

  • cd changes from the current directory to the user's home directory.
  • cd ~ also switches from the current directory to the user's home directory .
  • Two "." indicate the upper directory (parent directory).
  • "." indicates the current directory.
  • cd - returns to the last directory you were in, not the previous directory.

Two, the tree command

1. Command format

tree

2. Function description

  • Displays the contents of a directory in a tree view.
  • The software package containing this command is not installed by default. You must first upload this software package to Linux, and then execute the command to # rpm -ivh tree-1.5.3-2.e16.i686.rpminstall it. 软件具体安装之后再详情叙述。Or click Install in the graphical interface instead of using commands.

Three, mkdir command

1. Command format

mkdir [-p] 目录名

2. Function description

  • Create a subdirectory named by "directory name".
  • -p: will create a multi-level directory structure at the same time.

3. Function demonstration

insert image description here

Fourth, the rmdir command

1. Command format

rmdir [-p] 目录名

2. Function description

  • The "directory name" to delete must be an empty directory.

  • -p: After deleting the specified directory, if the upper directory of the directory becomes an empty directory, it will be deleted together.

3. Function demonstration

insert image description here

Five, touch command

1. Command format

touch [-d yyyyMMdd] [-t yyyyMMddHHmm.ss] [文件名]

2. Function description

  • When the specified file does not exist, use touch to create an empty file; when the file exists, you can modify the time of the file or directory, or add parameters to specify the time.

3. Function demonstration

insert image description here

Six, rm command

1. Command format

rm 文件名或目录名

2. Function description

  • delete specified file or directory
  • -f: Do not prompt the user when deleting files or directories.
  • -r: If you want to delete the directory, you must add it.

3. Function demonstration

insert image description here

Seven, cp command

1. Command format

cp [-r] [-p] 源文件或源目录  目标文件或目标目录

2. Function description

  • Copy a file or directory and put it in the specified location. In fact, what is completed is copy and paste under the windows graphical interface.
  • If a file name is written later, it means that the original file will be renamed during the copy process, and the copied directory can also be renamed.
  • -r : If you want to copy the directory, you must add it.
  • -p : Preserve the attributes of the source file, including the owner, user group to which it belongs, permissions and time.

3. Function demonstration
copy file:

insert image description here
insert image description here

insert image description here

Copy directory:

insert image description here
insert image description here

Eight, mv command

1. Command format

mv  源文件或源目录  目标文件或目标目录 

2. Function description

  • Move a file or directory.
  • It is still possible to rename during the moving process, such as moving a directory to a directory that does not exist, then the directory name will change.

3. Function demonstration

insert image description here
insert image description here

Nine, echo command

1. Command format

echo 字符串

2. Function description

  • Strings with double quotes " " or single quotes ' ' can keep the format unchanged.
  • Output the string as-is to the display.
  • It is mainly used to prompt input information in Shell programming, and is usually used in combination with redirecting output ">" command.

10. cat command

1. Command format

cat [-n] [-b] [-E] 文本文件名

2. Function description

  • Display all the content in the text file at one time, suitable for files whose content does not exceed one screen.
  • -n: Display line numbers, including line numbers for empty lines.
  • -b: Display line numbers, excluding blank line numbers.
  • -E: A newline symbol "$" will be displayed at the end of each line.

Eleven, more command

1. Command format

more 文本文件名

2. Function description

  • Display the content of the text file in split screens. This command is more suitable for displaying files with more than one screen. When displaying the content of the file, it will pause the display screen by screen. Use the following three keys to operate.
  • Press the space bar to display the next screen.
  • Press Enter to display the next line.
  • Press the q key to exit.

Twelve, less command

1. Command format

less 文本文件名

2. Function description

在上面more命令的基础上能够上、下翻屏,能够查找。

Thirteen, head command

1. Command format

head [-n] 文本文件名

2. Function description

  • Display the content at the beginning of the text file, and the first 10 lines are displayed by default.
  • -n: Specifies to display the first few lines.
  • Good for when you just want to see the beginning of the file.

Fourteen, tail command

1. Command format

tail [-n] [-f] 文本文件名

2. Function description

  • Display the content at the end of the text file, and display the last 10 lines by default.
  • -n: Specify the next few lines to display.
  • -f: Monitor changes in file content in real time.
  • Good for when you just want to see the end of the file.

15. grep command

1. Command format

grep -n -color=auto [-v "字符"] ["^字符"] ["字符$"] 要搜索的字符串 文件名

2. Function description

  • Finds the searched string in a text file and displays the lines containing it.
  • -n: Display the line number where it is located.
  • –color=auto: Mark the searched string with a special color.
  • -v: Reverse lookup, that is, filtering, showing lines other than the string in the command.
  • "^ char": Find lines beginning with "char".
  • Fifth option: Find lines ending with the "character $".

3. Function demonstration

insert image description here
insert image description here
insert image description here
insert image description here

Sixteen, wc command

1. Command format

wc [-l] [-w] [-c] 文本文件名

2. Function description

  • Count and display the number of lines, words, and bytes of a file.
  • -l: Only count the number of lines.
  • -w: Only count words.
  • -c: Only count the number of bytes.

insert image description here
insert image description here
insert image description here

Summarize

I used two articles to summarize some common and commonly used commands. The demonstrations given in the commands may be incomplete and there may be errors. Everyone is welcome to point out and criticize. There are many and complicated Linux commands, and only by typing and practicing can we master them proficiently and encourage each other.

Guess you like

Origin blog.csdn.net/ATTAIN__/article/details/124241075