Linux Basic Instruction Set


This article mainly introduces some basic commands of Linux, and each command will be matched with several command options.

1. ls command

For directories, display all subdirectories and files under the directory. For files, the filename is listed along with other information.
1. The ls command
insert image description here
only displays the name of the file or directory.

2, -l lists the detailed information of the file
insert image description here
3, -a lists all files or directories under the directory, including hidden files beginning with . You
insert image description here
can see that compared with the ls -l command, there are more . and . . Directories, where they respectively represent the current directory and the parent directory.
4, -R lists files in all subdirectories
insert image description here
5, -S sorts files by file size
insert image description here

Common options:

-a 列出目录下的所有文件,包括以 . 开头的隐含文件。
-d 将目录象文件一样显示,而不是显示其下的文件。 如:ls –d 指定目录
-i 输出文件的 i 节点的索引信息。 如 ls –ai 指定文件
-k 以 k 字节的形式表示文件的大小。ls –alk 指定文件
-l 列出文件的详细信息。
-n 用数字的 UID,GID 代替名称。 (介绍 UID, GID)
-F 在每个文件名后附上一个字符以说明该文件的类型,“*”表示可执行的普通文件;“/”表示目录;“@”表
示符号链接;“|”表示FIFOs;“=”表示套接字(sockets)。(目录类型识别)
-r 对目录反向排序。
-t 以时间排序。
-s 在l文件名后输出该文件的大小。(大小排序,如何找到目录下最大的文件)
-R 列出所有子目录下的文件。(递归) 
-1 一行只输出一个文件。

2. pwd command

Displays the directory the user is currently in.
insert image description here

3,whoami

see who am i
insert image description here

4. cd command

cd + directory name
Change the working directory. Change the current working directory to the specified working directory.
1, cd .. returns to the parent directory
insert image description here
2, cd + command path
(1) adopts an absolute path
insert image description here

(2) Use a relative path
insert image description here

3, cd ~ returns to the home directory
insert image description here
4, cd - returns to the previous working directory
insert image description here

5, touch command

1. Create a normal file
insert image description here
Other common options:

-a   或--time=atime或--time=access或--time=use只更改存取时间。
-c   或--no-create  不建立任何文档。
-d  使用指定的日期时间,而非现在的时间。
-f  此参数将忽略不予处理,仅负责解决BSD版本touch指令的兼容性问题。
-m   或--time=mtime或--time=modify  只更改变动时间。
-r  把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。
-t  使用指定的日期时间,而非现在的时间。

6. mkdir command

1, mkdir directory name to create a directory
insert image description here
2, -p recursively create a directory
insert image description here

7. rmdir and rm commands

1, rmdir deletes an empty directory
insert image description here
2, rm: deletes a file or directory
insert image description here
3, -r deletes a directory and its files recursively

insert image description here
4, -f force delete

Common options:

-f 即使文件属性为只读(即写保护),亦直接删除
-i 删除前逐一询问确认
-r 删除目录及其下所有文件

8, man command

Consult the manual
Linux provides us with 9 manuals for us to consult

insert image description here
Man directly adds the things to be queried, and the query starts from the first chapter by default.
You can also specify a chapter to query

insert image description here

9, cp command

Copy a file or directory

cp src dst

insert image description here
1. -r recursive processing, processing subdirectories and files under the command directory together.

insert image description here
2, -f Forces copying, regardless of whether the destination directory or file exists

insert image description here
3. Commonly used options:

-f 或 --force 强行复制文件或目录, 不论目的文件或目录是否已经存在
-i 或 --interactive 覆盖文件之前先询问用户
-r递归处理,将指定目录下的文件与子目录一并处理。若源文件或目录的形态,不属于目录或符号链
接,则一律视为普通文件处理
-R 或 --recursive递归处理,将指定目录下的文件及子目录一并处理

10. tree command

Show directory tree structure

insert image description here

11. mv command

1. Move a file or directory

insert image description here
2. Rename the file or directory
When the second parameter is a file or a directory that does not exist, it will be renamed.

insert image description here
3. Commonly used options:

-f :force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖
-i :若目标文件 (destination) 已经存在时,就会询问是否覆盖

12. cat command

view the contents of the file

insert image description here
1, -n display the number of lines of text

insert image description here
2. Commonly used options:

-b 对非空输出行编号
-n 对输出的所有行编号
-s 不输出多行空行

3, Add nothing after the input redirection cat, the default is to read data from the keyboard and output to the screen

insert image description here
cat < file prints the contents of the file to the screen

insert image description here

13. echo command

1. Output the content of the string to the screen
insert image description here
2. Output redirection echo "" >

Originally output the string to the screen, but now output it to a file
insert image description here
3, append redirection>>
insert image description here

14. more command

This is a tool for viewing the content of the file, and it will display the file in pages. Press the enter key to scroll down, but not to scroll up.
insert image description here

15. less command

The function of this command is similar to the more command, but it is more powerful than the more command. Use [pageup][pagedown] and other key functions to browse files back and forth, and also supports search and other functions, which can search up and down.

-i  忽略搜索时的大小写
-N  显示每行的行号
/字符串:向下搜索“字符串”的功能
?字符串:向上搜索“字符串”的功能
n:重复前一个搜索(与 / 或 ? 有关)
N:反向重复前一个搜索(与 / 或 ? 有关)
q:quit 

16, head command

It is used to display a certain number of text blocks at the beginning or end, head is used to display
the beginning of the file to the standard output, and tail is taken for granted to see the end of the file.
Common options: -n number of lines to display
insert image description here

17. tail command

View the last few lines of the file
Common options: -n The number of lines displayed
insert image description here

18, date command

1. Date specifies the format to display time: date+%Y:%m:%d
More display formats:

%H : 小时(00..23) 
%M : 分钟(00..59) 
%S : 秒(00..61) 
%X : 相当于 %H:%M:%S 
%d : 日 (01..31) 
%m : 月份 (01..12) 
%Y : 完整年份 (0000..9999) 
%F : 相当于 %Y-%m-%d

insert image description here

2. Timestamp
Time -> Timestamp: date +%s
Timestamp -> Time: date -d@1508749502
insert image description here
insert image description here

19, cal command

Calendar
Common options:

-3 显示系统前一个月,当前月,下一个月的月历
-j  显示在当年中的第几天(一年日期按天算,从1月1号算起,默认显示当前月在一年中的天数)
-y  显示当前年份的日历

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

20, find command

This is a very important command. Here we mainly introduce its function of searching by name, which is the -name option:

find start directory -name file name

1, -name
insert image description here
2, -maxdepth option, limit the depth of search
insert image description here
3, -mindepth is similar to max

21, which command

Find the path of a command
insert image description here

22, whereis command

Search documentation, files, programs, etc. for instructions.
insert image description here

23, alias command

Alias ​​the command.

24. grep command

Search for a string in a file and print the found lines

grep string filename

insert image description here
1. The -i option ignores case when searching.
2, -n outputs the line number by the way when outputting
3, -v reverses the selection, that is, displays the line without the content of the 'search string'
4, the -E option can be used to expand the option to a regular expression
, for example: find the following Strings beginning or ending with a character
grep -E ^a test.txt Find strings beginning with a character
grep -E a$ test.txt Find strings ending with character a

insert image description here

25, did


Write a file, similar to Notepad nano under Windows, file name
insert image description here
ctrl+x to exit

26,sort

Sort the contents of the file in ascending order according to the ascll code of the first element in each line.
insert image description here

27,wc

Commonly used -l option: count the number of lines of text
insert image description here

28,uniq

Text line deduplication function, for example, we deduplicate the above sorted text and display:

The previous text has been slightly modified, and a few lines of the same text appear.

insert image description here

29,zip unzip

Pack and compress files or directories.
-r: recursive processing

Package compression: zip test2.zip test2
decompression: unzip test2.zip

Unzip to the corresponding directory: -d option unzip test2.zip -d /tmp Unzip to the tmp directory
insert image description here
insert image description here
zip -sf test2.zip View the contents of the compressed package

zip -d test2.zip test2/test1 delete the specified file in the compressed file

30,tar

tar -czf package and compress
tar -xzf decompress
tar -xzf -C decompress to the specified directory
tar -tzf view the contents of the compressed package
tar -zvtf view the more detailed content of the compressed package
insert image description here

31,bc

Calculator
insert image description here
can also calculate the value of a string of strings

insert image description here

32

View the kernel information of the system
-r: view the kernel information
-a: view more detailed kernel information
insert image description here
3 represents the major version number
10 represents the minor version number
0 represents the number of revisions
el7: commercial version Centos7
x86_64: represents a 64-bit machine (cpu architecture)
added:

top任务管理器 
netstat查看网络连接状态 
free 查看内存资源状态 
df 查看磁盘分区资源状态

33, | command line pipe

The role of | is to pipe the results of the previous command to the next command.
insert image description here

34, several hotkeys

tab 自动补全功能
上下键:翻阅历史使用的命令
ctrl +r 在历史使用的指令中查询 左右键选中
history 查看历史使用过的指令
ctrl + c 强制结束当前程序
ctrl+ d 退出
alt+enter 全屏

Guess you like

Origin blog.csdn.net/Djsnxbjans/article/details/128005724