First, the command basic format
-[[email protected] ~] #含义
Where: (1) Root: Current login user (2) localhost: hostname (3) ~: Current directory (home directory, you can find the current location through the PWD command.) Root user default is/root, other users such as test is/home/test) (4) #: Super User prompt, ordinary user's prompt is $.
-command [options] [parameters] (option to adjust the function or result of the command, [] to indicate optional)
Note: The individual commands used do not follow this format when there are multiple options that can be written together to simplify the options with the full option-a equals--all
Example: querying the contents of a directory: LS
ls [options] [file or directory]
Option:-A displays all files, including hidden files (. Starts with hidden files)
-L Display Details (ls-l command alias LL)
-D View Directory properties
-H humanized Display file size
-I display Inode
-rw-r--r--. 1 root root 28250 May 09:48 install.log anatomy
(1)-rw-r--r--(for permissions, user-to-file relationship, divided into two parts)
--File type (-file d directory l soft link file)
-Rw-(u owner, owners) r--(g belongs to group, same identity with same permissions divided by group) r--(o others)
R Read W write X Execute
(2) 1 means that the reference count is the number of calls
(3) root indicates the owner of the file
(4) The following root is the owning group
(5) 28250 indicates the file size, in bytes
(6) May 21 09:48 Last modified
Ii. File processing commands
- Directory processing commands
mkdir-p [directory Name]
(1)-P recursive creation command English willing: make directories
Switch directory: CD
(1) CD [catalogue]
Command English original: Change directory
(2) Simplified operation
CD ~ Enter the current user's home directory
CD into the current user's home directory
CD-Go to last directory
Cd.. Go to the top level directory
Cd. Go to current directory
-> Path
-Relative Path: Refer to the current directory to find, such as: [[email protected] ~]# CD. /usr/local/src/
-Absolute path: Starting from the root directory, first-level recursive lookup. In any directory, you can enter the specified location, such as [[email protected] ~] #cd/etc/
Query Directory location: pwd
-pwd Command English original: Print working directory
--Delete Empty directory: RmDir
-rmdir [directory name] command English original: Remove empty directories
Delete files or directories: RM
-RM-RF [file or directory] command English original: remove
Option:-R Remove Directory-F Mandatory
Copy command: CP
-CP [Options] [Original file or directory] [target directory] command English original: copy
Option:-R copy Directory
-P Joint File attribute copy
-D If the source file is a linked file, copy the link property
-A equals-pdr
Cut or rename command: MV
-MV [Original file or directory] [target directory] command English intent: move
Example: Cut MV japan//tmp/japan1 renamed MV Rme ABC
The original file and the target directory in the same directory is renamed, the different directory is cut
* Common Directory role
-/root directory
-/bin Command Save directory (commands that normal users can read)
-/sbin command to save directory (a directory that can be used by super users)
-/boot directory to launch related files
-Save directory for/dev device files
-/etc configuration File Save Directory
-/root Super User's home directory
-Home directory for normal users
-/lib system function library Save directory
-/MNT System Mount Directory
-/media Mount Directory
-/tmp Temp directory
-/proc directly to memory (cannot be manipulated)
-/sys directly to memory (cannot be manipulated)
-/USR system software Resources directory
/usr/bin/system command (normal user)
/usr/sbin/system command (super User)
-/var system related document content
- File processing commands
- Link command
-> Link command: ln
-Ln-s [Original file] [target file]
-Command English original meaning: link
-Function Description: Generate link file
Option:-S creates a soft link without creating a hard link (note: The path to the original file of the soft link is best with an absolute path, otherwise there will be a problem in different directories)
Hard Link Features:
1, have the same I node and storage block block, can be seen as the same file
2, can be identified by the I node
3. Cannot cross partition
4. Cannot be used for directory
Soft Link Features:
1. Windows-like shortcuts
2, the soft link has its own I node and block blocks, but the data block only save the original file name and I node number, and no actual file data
3, lrwxrwxrwx l Soft link
Soft link file permissions are rwxrwxrwx, but the actual permissions need to see the original file permissions
4, modify any file, the other changes
5, delete the original file, soft links can not be used
Note: Soft link Original file path is best with absolute path, otherwise there will be a problem in different directories
Third, File Search command
- File Search Command Locate
-Locate command format
-Locate file name
Search by file name in the background database, search faster
-/var/lib/mlocate
#locate命令搜索的后台数据库
-UpdateDB
Update Database
Locate search by configuration file rules under the diagram
- Command Search command Whereis and which
Command for the search command Whereis
-Whereis Command name
#搜索命令所在路径及帮助文档所在位置
Option:-B: Find only executable files
-M: Find only Help files
Command for the search command which
-which command name
#搜索命令所在路径及别名
PATH environment variable
-Path environment variable: Defines the paths of the system search command
[Email protected] ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
-A Find command
-Find [Search Range] [search criteria]
#搜索文件
-Find/-name Install.log
#避免大范围搜索, system resources are very expensive
#find是在系统当中搜索符合条件的文件名. If a match is required, wildcard matches are used, and the wildcard character is an exact match
-Find/root-iname Install.log
#不区分大小写
-Find/root-user Root
#按照所有者搜索
-Find/root-nouser
#查找没有所有者的文件
-find/var/log/-mtime +10
#查找10天前修改的文件
-10 10 days to modify the file
10 10 days of modified files on the same day
+10 files modified 10 days ago
Atime File access time
CTime modifying file attribute time
Mtine Modifying file content time
-Find. -size 25k
#查找文件大小是25kb的文件(. Current directory)
-25k files less than 25KB
25k equals 25KB of File
+25k files larger than 25KB
-Find. -inum 262422
#查找i节点是262422的文件(. Current directory)
-Find/etc-size +20k-a-size-50k
#查找/etc/directory, files larger than 20KB and less than 50KB
-A and logic with, two conditions are met
-O or logic or, two conditions satisfy one can
-Find/etc-size +20k-a-size-50-exec ls-lh {}\;
#查找 files larger than 20KB and less than 50KB in the/etc/directory, and displays detailed information
#-exec/-ok Command {} \; Perform action on search results
Wildcard characters in Linux
* Match any Content
? Match any one character
[] matches any one of the characters in brackets
- String Search command grep
--Search string command grep
-grep [Options] string file name
#在文件当中匹配符合条件的字符串
Option:-I ignores case
-V excludes the specified string
- The difference between the Find command and the grep command
-A Find command: Search the system for eligible file names, if matching is required, wildcard matches are used, wildcards are exact matches
grep command: Searches the file for qualifying strings, matches with regular expressions if required, and matches with regular expressions
Iv. Help Commands
Man command
#获取指定命令的帮助
, main LS
#查看ls的帮助
Level of Man
1: View Help for a command
2: See Help for functions that can be called by the kernel
3: View Help for functions and function libraries
4: See Help for special files (mostly files in the/dev directory)
5: View Help for the configuration file
6: See the game's help
7: See other miscellaneous Help
8: See Help for commands available to system administrators
9: View and kernel-related files Help
View commands have that level of help
-man-f Command
Equivalent
-Whatis command
Example:
Man-5 passwd
Man-4 NULL
Man-8 ifconfig
View all help related to commands
-man-k Command
Equivalent
-Apropos command
For example
-Apropos passwd
Options Help
-Command--help
#获取命令选项的帮助
Example: LS--help
Shell Internal Command Help
-Help Shell internal commands
#获取shell内部命令的帮助
For example:
-Whereis CD
#确定是否是shell内部命令
-Help CD
#获取内部命令帮助
Detailed command Help info
-Enter: Go to sub-help page (with * sign)
-U: Go to the upper page
-N: Go to the next Help section
-P: Go to the previous Help section
-Q: Exit
V. Compression and DECOMPRESSION commands
- Common compression formats:. zip. gz. bz2
. zip Format compression
-Zip Compressed file name source file
#压缩文件
-Zip-r Compressed file name source directory
#压缩目录
. zip Format Decompression
-Unzip compressed files
#解压缩. zip file
. gz format Compression
-Gzip Source files
#压缩为. GZ-formatted compressed file, the source file disappears
-Gzip-c source files > Compressed files
#压缩为. gz format, source file reserved (> means write output to a file)
Example: Gzip-c Cangls > cangls.gz
-Gzip-r Directory
#压缩目录下所有的子文件, but cannot compress the directory
. gz Format Decompression
-Gzip-d Compressed Files
#解压缩文件
-Gunzip Compressed Files
#解压缩文件
-bz2 format compression
-Bzip2 Source file
#压缩为. bz2 format, do not retain source files
-Bzip2-k Source file
#压缩之后保留源文件
-Note: The BZIP2 command cannot compress the directory
. bz2 Format Decompression
-Bzip2-d Compressed Files
#解压缩,-K Reserved Compressed files
-Bunzip2 Compressed Files
#解压缩,-K Reserved Compressed files
- Commonly used compression formats:. tar.gz. tar.bz2
-Pack Command tar
-TAR-CVF Package file name source file
-Option:-C: Pack
-V: Display procedure
-F: Specifies the file name after packaging
-Example: TAR-CVF Longzls.tar longzls
--Unpacking commands
-TAR-XVF Package file name
-Option:-X: Unpack
-Example: TAR-XVF Longzls.tar
. tar.gz compression format
-Actually. The. tar.gz format is packaged in. tar format and then compressed into. gz format
-TAR-ZCVF Compressed package name. tar.gz Source File
Option:-Z: Compress to. tar.gz format
-TAR-ZXVF Compressed package name. tar.gz
Option:-x: Unzip. tar.gz format
. TAR.BZ2 compression format
-TAR-JCVF Compressed package name. tar.bz2 Source File
Option:-j: Compress to. tar.bz2 format
-TAR-JXVF Compressed package name. tar.bz2
Option:-x: Unzip. tar.bz2 format
Special Example:
1. Compress to the specified directory:
2, view the contents of compressed files, do not pressure:
3. Compress multiple Files
Six, shutdown and restart commands
[[Email protected] ~]# shutdown [Options] Time (now is immediate)
Option:-C: Cancels the previous shutdown command
-H: Shutdown
-R: Restart
[Email protected] ~]# halt
[Email protected] ~]# Poweroff
[[Email protected] ~]# init 0
[Email protected] ~]# reboot
[[Email protected] ~]# Init 6
0 Turn off the machine
1 Single User
2 not fully multiuser, no NFS service included
3 Full Multi-user
4 Not assigned
5 graphical interface
6 restart
[Email protected] ~]# Logout
Vii. Other common commands
Linux Common commands