Linux system: A complete list of commonly used Linux commands (everyone here should collect it quickly, funny.jpg)

1. File directory commands

1)浏览目录命令:cd、dir、ls、ll2)浏览文件命令:cat、more、less  3)目录操作命令:mkdir、rmdir  4)文件操作命令:touch、rm、cp、mv、ln、tar、gzip、gunzip、whereis、whatis     
1. ls command to list files

》The command to display the contents contained in the specified working directory is ls. It should be noted that the ls command lists the names of files, not the contents of the files. The command is used as follows:

ls [选项] [文件目录列表] 
ls命令中的常用选项如下:
     	-a:显示所有文件及目录 (ls规定将文件名或目录名中开头为                    	"."的视为隐藏档,不会列出) 
        -c:按列输出,纵向排序
        -x:按列输出,横向排序
        -l:除文件名外,也将文件状态、权限、拥有者、文件大小	等信息详细列出 
        -t :根据文件建立时间的先后次序列出 
        -A :同 -a ,但不列出 "." (目前目录)".." (父目录) 
        -X:按扩展名排序显示
        -R:递归显示下层子目录
        --help:显示帮助信息
        --version:显示版本信息

Insert image description here
Linux supports multiple file types, each type is represented by one character, and its description is as follows:

-:常规文件
d:目录
b:块特殊设备
c:字符特殊设备
p:有名管道
s:信号灯
m:共享存储器

The characters of the file type represent the permissions of the file. The permissions consist of three strings, which represent respectively:

该文件所有者的权限、组中其他人的权限和系统中其人的权限;
每个字符串又由三个字符组成,依次表示对文件的读(用字符r表示)、写(用字符W表示)和执行权限(用字符x表示)。当用户没有相应的权限时,该权限的对应位置用短线“-”来表示。 
例如:
drwxr-x---
表示的含义是:
d表示这条信息是目录;
目录拥有者的权限是rwx(表示有读、写和执行权限);
组中其他人对该目录的权限是r-x(表示有读和执行权限,没有写权限),系统中其他人对该目录的权限是---(表示读、写和执行权限都没有)。

The following is a command to display help and version information. The command is as follows:

#ls --version
#l ls --help |more
2. cd command to switch directories

The cd (change directory) command allows users to change the current directory.

范例如下:
[pp@linux home]$ cd pp             切换到当前目录下的pp子目录
[pp@linux pp]$ cd ..     切换到上一层目录
[pp@linux home]$ cd /    切换到系统根目录
[pp@linux /]$ cd             切换到用户自家目录(或执行cd ~)
[pp@linux pp]$ cd /usr/bin          切换到/usr/bin目录
3. mkdir to create a directory and rmdir to delete a directory.

The mkdir(make directory) command can be used to create subdirectories.

下面的范例会在所在目录内创建子目录:
格式:mkdir [参数] <目录名>
[pp@linux pp]$ mkdir  dir         	在当前目录下建立dir目录
[pp@linux pp]$ mkdir  -p dir1/dir2 在当前目录下创建dir1目录,并在dir1目录下创建dir2目录,也就是连续创建两个目录(dir1/和dir1/dir2)
格式:rmdir [参数]<目录名>
rmdir(remove directory)命令可用来删除“空”的子目录:
[pp@linux pp]$ rmdir dir                删除“空”的子目录dir
[pp@linux pp]$ rmdir –p dir1/dir2       删除dir1下的dir2目录,若dir1目录为空也删除它
4. cp command to copy files

The cp(copy) command can copy files from one place to another. Generally, when using the cp command to copy a file to another file or to a directory, you need to specify the source file name and target file name or directory.

格式:cp[参数]<源文件路径><目标文件路径>
[pp@linux pp]$ cp test1.txt  test2.txt 
将test1.text复制成test2.txt

[pp@linux pp]$ cp test3.txt  /tmp 
将test3.txt复制到/tmp目录中

5. Delete files or directories with rm command
功能:删除文件或目录
格式:rm[参数] <目标文件路径>
[pp@linux pp]$ rm  myfiles     删除一个文件
[pp@linux pp]$ rm  *
删除当前目录下的所有文件
-f参数:强迫删除文件
[pp@linux pp]$ rm –f   *.txt
强迫删除所有以后缀名为txt文件
(1) rm command parameter -i usage
-i参数:删除文件时询问
[pp@linux pp]$ rm –i  * 
删除当前目录下的所有文件
rm:backup: is a directory     遇到目录会略过
rm : remove ‘myfiles.txt’ ? Y
删除文件时会询问,可按Y或N键表示允许或拒绝删除文件 
注意:在系统的默认状态下,rm命令会对每个删除的文件一一询问。如果用户确定要删除这些文件,则可以使用参数-f来避免询问。

(2) Use of rm command parameters -r and -f
-r参数:递归删除(连子目录一同删除,这是一个相当常用的参数。
[pp@linux pp]$ rm  -r  test 
删除test目录(含test目录下所有文件和子目录)
[pp@linux pp]$ rm  -r  *
删除所有文件(含当前目录所有文件、所有子目录和子目录下的文件)一般在删除目录时r和f一起用,避免麻烦。
[pp@linux pp]$ rm  -rf  test
强行删除、不加询问  
6. cat command
功能:用于显示文件的内容,也可以将数个文件合并成一个文件。
格式:cat[参数]<文件名>
[pp@linux pp]$pp  cat  test.txt
显示test.txt文件内容
[pp@linux pp]$pp  cat  test.txt  | more
逐页显示test.txt文件中的内容
[pp@linux pp]$pp  cat  test.txt  >>test1.txt
将test.txt的内容附加到test1.txt文件之后
[pp@linux pp]$pp  cat  test.txt  test2.txt >readme.txt  
将test.txt和test2.txt文件合并成readme.txt文件

7. more command

The more command is generally used when the content to be displayed exceeds the length of one screen. In order to prevent the screen from flashing away instantly when it is displayed, the user can use the more command to pause the screen when it displays a full page. At this time, you can press the space key to continue displaying the next screen, or press the Q key to stop displaying.

[pp@linux pp]$ more  /etc/named.conf 
显示 etc/named.conf文本文件的内容
当用ls命令查看文件列表时,如果文件太多,则可配合more命令
使用:
[pp@linux etc]$ ls  -al  | more
以长格形式显示etc目录下的文件列表,显示满一个画面便暂停,可按空格键继续显示下一画面,或按Q键跳离
8. less command

The usage of the less command is similar to the more command, and can also be used to browse files that exceed one page. The difference is that in addition to pressing the space bar to display files downwards, the less command can also use the up and down keys to scroll files. When you want to end browsing, just press the Q key at the prompt ":" of the less command.

[pp@linux etc]$less  named.conf
显示/etc/named.conf的文本文件内容
[pp@linux etc]$ls  -al | less
以长格形式列出/etc目录中所有的内容。用户可按上下键浏览或按Q键跳离
9. Display commands head and tail
1)head功能:用于显示文件前几行的内容
格式:head[参数]<文件名>
[root@linux root]# head -10 /etc/passwd
显示/etc/passwd/文件的前10行内容2)tail功能:用于显示文件后几行的内容
格式:tail[参数]<文件名>
[root@linux root]# tail -10 /etc/passwd
显示/etc/passwd/文件的倒数10行内容
10. mv command to move or change file and directory names
功能:可以将文件及目录移到另一目录下,或更改文件及目录的名称
格式:[参数]<源文件或目录> <目标文件或目录>
[pp@linux dir1]$ mv a.txt ../
将a.txt文件移动上层目录
[pp@linux dir1]$ mv a.txt  b.txt
将a.txt改名为b.txt
[pp@linux dir1]$ mv dir2 ../
将dir2目录上移一层
11. Display the pwd command of the current directory
功能:显示用户正在工作或当前所在的目录
格式:pwd
[pp@linux pp]$ pwd /home/pp                     
显示用户pp所在的当前目录是/home/pp   

12. grep command
[root@linux root]# grep linux test.txt
搜索test.txt文件中字符串linux并输出
[root@linux root]# rpm  -qa | grep httpd
搜索rpm包中含有httpd包的文件名
例:who | grep tty1
13. touch command
功能:生成一个空文件或修改文件的存取/修改的时间记录值。
格式:touch[参数]<文件名>
[pp@linux pp]$ touch *                         
将当前下的文件时间修改为系统的当前时间
[pp@linux pp]$ touch –d 20040210 test
将test文件的日期改为20040210
[pp@linux pp]$ touch abc   若abc文件存在,则修改为系统的当前时间;若不存在,则生成一个为当前时间的空文件
14. who or w command
功能:查看当前系统中有哪些用户登录 
格式:who/w[参数]
[root@linux root]# who 
root tty1              1个本地用户登录
pp pts/0               1个远程登录用户

15. ln command
功能:在文件和目录之间建立链接
格式:ln [参数] <源文件或目录> <目标文件或目录> 
链接分“软链接”和“硬链接”1)软链接:
[root@linux pp]# ln –s /usr/share/doc  doc
创建一个链接文件doc,并指向目录/usr/share/do2)硬链接:
[root@linux pp]# ln  /usr/share/test  hard
创建一个硬链接文件hard,这时对于test文件对应的存储区域来说,又多了一个文件指向它。
16. Software package management

(1) Installation of software packages

使用RPM命令的安装模式可以将软件包内所有的组件放到系统中的正确路径,安装软件包的命令是: 
[root@linux root]#rpm –ivh wu-ftpd-2.6.2-8.i386.rpm
i:作用rpm的安装模式
v: 校验文件信息
h: 以#号显示安装进度

(2) Deletion of software packages

删除模式会将指定软件包的内容全部删除,但并不包括已更改过的配置文件,删除RPM软件包的命令如下:
[root@linux /]# rpm –e  wu-ftpd
删除参数 软件包名称
注意:这里必须使用软件名“wu-ftpd”或”wu-ftpd-2.6.2-8而不是使用当初安装时的软件包名.
 wu-ftpd-2.6.2-8.i386.rpm

(3) Software package upgrade

升级模式会安装用户所指定的更新版本,并删除已安装在系统中的相同软件包,升级软件包命令如下:
[root@linux /]# rpm –Uvh wu-ftpd-2.6.2-8.i386.rpm

(4) Software package update

更新模式下,rpm命令会检查在命令行中所指定的软件包是否比系统中原有的软件包更新。如果情况属实,rpm命令会自动更新指定的软件包;反之,若系统中并没有指定软件包的较旧版本,rpm命令并不会安装此软件包。而在升级模式下,不管系统中是否有较旧的版本,rpm命令都会安装指定的软件包。
[root@linux /]# rpm –Fvh wu-ftpd-2.6.2-8.i386.rpm

(5) Software package query

若要获取RPM软件包的相关信息,可以使用查询模式。使用-q参数可查询一个已安装的软件包的内容。
[root@linux /]# rpm  –q  wu-ftpd
wu-ftpd-2.6.2-8          显示软件包的名称、版本及次版本
查询软件包所安装的文件:安装某个软件包之后,常常困扰用户是,不知道该软件包究竟安装到哪里,此时执行rpm –ql package-name命令可得知
[root@linux /]# rpm –ql xv (l参数:显示文件列表)
/etc/x11/wmconfig/xv
/usr/x11R6/bin/bggen          查询结果 
/usr/X11R6/bin/vdcomp       

17. Packaging command tar

The tar command is located in the /bin directory. It can package the files or directories specified by the user into a file, but does not compress it. Generally, the commonly used compression method on Unix is ​​to use tar to package many files into one file, and then use the gizp compression command to compress it into a file of xxx.tar.gz (or xxx.tgz).
Note: tar can not only package files, but also back up hard disk data.

常用参数:
-c:创建一个新tar文件
-v:显示运行过程的信息
-f:指定文件名
-z:调用gzip压缩命令进行压缩
-t:查看压缩文件的内容
-x:解开tar文件

(1) tar command example

[root@linux pp]# tar  -cvf  test.tar   *
将所有文件打包成test.tar,扩展名.tar需自行加上

[root@linux pp]# tar  -zcvf  test.tar.gz  *
将所有文件打包成test.tar,再用gzip命令压缩

[root@linux ljr]# tar  -tf   test.tar
查看test.tar文件中包括了哪些文件

[root@linux pp]# tar  -xvf test.tar       将test.tar解开
[root@linux pp]# tar  -zxvf foo.tar.gz   将foo.tar.gz解压缩

18. gzip and gunzip

In addition to the compression format of .zip files, the more common compression format of .gz files under Linux systems is generally generated by the gzip command. The zip command has the function of compressing many files into one file, but gzip cannot, so gzip is generally used together with tar. Currently, most of the compressed files we see use tar to package all files into one file, and then use gzip to compress them. Therefore, most of the files we see with the extension .tar.gz or .tgz are this type of file.

gzip各gunzip命令:
[root@linux test]# gzip test.txt    
压缩文件时,不需要任何参数

[root@linux test]# gizp –l test.txt.gz     
显示压缩率

[root@linux test]# gunzip test.txt.gz            
解压缩
19、date、cal、clock
date命令可以显示/修改当前的日期时间
[root@linux root]# date 121010232004
将时间更改为121010232004[MMDDhhmmYY]
[root@linux root]# cal      显示日历
[root@linux root]# clock    显示日期时间
20. Cal command to display calendar or annual calendar
cal(calendar)
功能:显示一个日历
格式:cal [参数] 月 年
[root@linux root]# cal
显示当月的日历
[root@linux root]# cal 4 2004  
显示20044月的日历
[root@linux root]# cal - y 2003
显示2003年的日历

2. System information commands

(1) dmesg command
function: display system diagnostic information, operating system version number, physical memory size and other information
Insert image description here

(2) df command
function: used to check the occupancy of each partition of the file system
Insert image description here

(3) du command
Function: View the amount of hard disk space used by subdirectories at all levels in a directory Format
: du [parameter] <directory name>
Insert image description here

(4) free command
function: used to check the size and occupancy of system memory and virtual memory (swap space)
Insert image description here

Guess you like

Origin blog.csdn.net/Mr_zhang1911116/article/details/123478835
Recommended