rw-r--r--file Type: U owner, G belongs to Group, o others 3 letters a group, R read W write x execute. (-D is a directory file, and L is a soft link file).
-rw-r--r--. 1 root root 9.8K November 21:39 Install.log.syslog Example: 1 refers to the number of calls, root operator, root group,
The point opening file is a hidden file,
mkdir-p[Directory Name]
-P Recursive creation if you create a serial directory with this
RmDir Deleting a blank directory
RM-RF file Delete File
-R Remove Directory-F coercion
CD switch directory CD ~ Switch home directory CD-go to the last directory
Relative path: Refer to the current directory to find,
Absolute path: From the root directory, first-level recursive lookup. In any directory, you can enter the location of the establishment.
CP "Options" "Original file" "Destination directory" copy option
-r Copy Directory-p file attribute copy-D if the source file is a linked file, copy the link property
-a equivalent to-pdr three options together, identical to the original file
MV "original file" "Target directory" cut or rename command
Not in the same directory as cut, under the same directory for renaming
/root directory
/bin Command Save directory (directory that normal users can use)
/boot directory to start related files
/dev Device File save directory
/etc configuration File Save Directory
/home directory for ordinary users
/lib System Library Save Directory
/MNT System Mount Directory
/media Mount Directory
/root Super User home Directory
/tmp Temp directory
/sbin command to save directory (super User can use directory)
/proc Direct Write memory
/usr/bin/system command (normal user)
/usr/bin/system command (super User)
/var system related document content
Root or tmp can be free to put files, others can not
Ln-s "Original file" "Destination file" link
-S Create soft links
Hard link: Has the same I node and storage block block, can be regarded as the same file;
Can be identified by the I node
Cannot span partitions
cannot be used for directories;
Soft connect: Equivalent to a shortcut
Own the I node and block blocks, the data block only save the file name and I node number, and no actual file data
lrwxrwxrwx | Soft link
Modify any file and the other changes
Delete the original file, soft link can not be used
File Search command: Locate file name in/var/lib/mlocate/directory search for one day update
In the background database search by file name, fast
-updatedb Updating the database
Can search local-local
Weak function, can only be searched by file name
Whereis Search System command path and help document location options
-B Find only executable files
-M only find help files
which file name
Find "Search scope" "Search criteria"
#搜索文件
Find/-name Install.log
#避免大范围搜索, system resources are very expensive
#find是在系统当中搜索符合条件的文件名. If a match is required, use the wildcard character to find
Wildcard characters
- Match any Content
? Match any one character
[] matches one of the contents of any one of the brackets
find/var/log/-mtime +10
#查找10天前修改的文件
-10 files modified within 10 days
10 10 days of modified files on the same day
+10 files modified 10 days ago
atime 文件访问时间ctime 改变文件属性mtime 修改文件内容
Find. Size 25k
#查找文件大小是25kb的文件
-25k files less than 25kb
25k equals 25kb of File
+25k files larger than 25kb
Find. -inum ID Node number
Files #查找i节点是 xx
Find/etc-size +20k-a-size-50k-exec ls-lh{}\;
Files larger than 20kb and less than 50kb #查找 the/etc/directory
-A and logic with
-O or Logical OR
grep "Options" string file name
#在文件当中匹配符合条件的字符串
-I ignores case
-V excludes the specified string
man+ command, Help command (with help level)
The Man-f command is equivalent to the Whatis command
Additional Help commands
Command Plus--help
Help Shell//get helper for Shell internal commands "Display Chinese help document"
Whereis//Determine if the shell internal command
Help CD//get INTERNAL command assistance
Detailed help Command info
-Enter the child help page
-U go to Upper page
-N Go to the next Help section
-P Enter the previous help section
-Q exit
。 Zip format compression (and Window Universal)
. zip compressed file name source files//Compressed files
. zip-r compressed file name source directory//Compressed directory
. Unzip//Unzip zip file
。 GZ format compression
Gzip source files//compressed files in. gz format, source files disappear
. gzip-c source Files > Compressed files//compressed into. gz format, source files are preserved
. gzip-r all sub-files in directory//compression directory, but cannot compress directory 4
. gzip-d compressed files//Unzip files
. gunzip compressed files//Unzip files
。 BZ2 format compression
. bzip2 source file//compressed to. bz2 format without preserving source files
. bzip2-k source file//Compress preserve source file after
Note the command cannot compress the directory
. tar.gz. tar.bz2
Package Command Tar
TAR-CVF package file name source file
-C Packaging
-V Display procedure
-f Specifies the file name after packaging
. tar-xvf package file name//unpack command
-X Solution Pack
Shutdown command (save data when shutdown and restart)
Shutdown "Options" time
-C cancels the previous shutdown command
-H shutdown
-R Restart//shutdown-r now
Cat/etc/inittab//Modify system default Run level
Id:3:initdefault
Runlever//Querying system RunLevel
Logout//Exit Login command
Mount Command (Assignment letter)
Mount "-T file System"-O Special Options "device file name mount point
Mount//Query the device that is already mounted in the system
Mount-a//Automatically mount according to the contents of the profile/etc/fstab
MOUNT-T File System: Add the file system type to specify the type of mount, you can use the file system such as ext4.iso9660
Mount-o Special Options: You can specify additional options for mounting
Parameter description
Exec/noexec: Sets whether executable files are allowed in the file system
To mount a CD instance:
Mkdir/mnt/cdrom//#建立挂载点/Create an empty directory
MOUNT-T Iso9660/dev/cdrom/mnt/cdrom//mounting discs
Uninstall command
#umount device file name or mount point
such as Umount/mnt/cdrom
Mount USB Drive
FDISK-L//view USB drive device file name
Mount-t vfat/dev/sdb1/mnt/usb///#linux默认是不支持NTFS文件系统
View User Login Information
①W User Name
Command output
User: Login username
TTY Landing Terminal
From: Login from that IP
[Email protected] Login time
Idle: User idle time
JCPU: Refers to the time taken by all processes connected to the terminal
PCPU refers to the time that the current process takes
What is the command that is currently running
②who User Name
③last//query user information for current login and past login
Read the/var/log/wtmp file data by default
1. Echo output command and script execution
Format: Echo [options] [Output CONTENT]
Option:-E: Character conversions that support backslash control
echo "Bols He cangls ni Xihuan nayige"
\a-Output warning tone
\b-Backspace
\ n-Line break
\ r-Enter
\ t-tab, which is the TAB key
\v-Vertical tab
\0NNN-Output characters according to octal ASCII code
\XHH-output characters in hexadecimal ASCII table
#输出颜色 \e[1;# #m-turn on color display; \e[0m-Turn off color display
#30m = black, 31m= red, 32m= Green, 33m=xxx
#34m = blue, 35m= magenta, 36m= cyan, 37m= White
2. Script execution:
Method 1: Give execute permission to run directly
chmod 755 hello.sh
./hello.sh (or absolute path execution/root/hello.sh)
Method 2: Execute the script through bash calls
Bash hello.sh
Two
#号代表注释
But #! /bin/bash is not a comment, but rather a standard script written in Linux, which must be added when writing a script.
If the script is completed with a pure shell statement, do not add #! /bin/bash, run no problem.
However, if the script calls other languages, it will get an error.
Basic features of Bash
* * Use aliases * * * *
alias--viewing aliases in the system that are in effect by default
Alias ls = ' ls--color=never '--set alias (expires temporarily, restarts or re-login)
VI ~/.BASHRC (more than one environment variable file)--Write environment variable configuration file (used to update user environment variable ~ on behalf of user home directory) I
VI/ROOT/.BASHRC--add alias ls = ' ls--color=never ' (the system is permanently active after reboot)
Source. bashrc--enables the current environment variable setting to take effect (does not require a system restart after a permanent effect)
Unalias ls--delete alias
Command effective Order
A command that performs an absolute or relative path in the first place
Second cis-execute alias
Third-level execution of bash internal commands
The first command to perform the directory order defined by the $PATH environment variable setting
Shortcut keys
CTRL + C forced termination
CTRL + L clear screen equivalent to clear
CTRL + A cursor quickly returns to the beginning of the line
CTRL + E cursor quickly goes to the end of the line
Ctrl + U delete from the cursor position to the beginning of the row
CTRL + Z put commands in the background-this command is very discreet.
CTRL + R History command Search
Historical command
history[options [history command Save file]
-C Empty History command
-W writes the history command in the cache to the history command to save the file ~/.bash_history
Modify a History command's Hangover Save Number: Edit/etc/profile (This is also a system environment variable profile), modify the Historysize parameter.
The historical order suggests not to be deleted, it is an important means of tracing our history. You can use the History-c Clear History command to save history commands using History-w. Historical commands are saved in the file ~./bash_history file
Standard input Device: Keyboard/dev/stdin description 0 standard output:
Display/dev/stdout Description 1 standard output:
The display/dev/stderr describes the 2 standard error output:
Output redirection
Command > File "override method to output the correct output of a command to a specified file or device"
Command >> file append the correct output of the command to the specified file or device "//" There are spaces around
Error command 2> (2>>) file "Overwrite (append) the output of the command error output to the specified file or device"//Error output >> no spaces around
Command > (>>) file 2>&1 overwrite (append) to output the correct output of the command to the specified file or device
Command &> (&>>) file overwrite (append) to output the correct output of the command to the specified file or device
Command >> file 1 2>> file 2 Append the correct output to file 1, append the wrong output to file 2
Command &>/dev/null throws the result of the command into null (acting like a dumpster) only executes, does not display
Input redirection (use less, understand)
After WC execution, input ctrl+d end will count the number of words in the input line number of letters
WC [option] [file name]-C byte number-L line number-W word number
Commands < filenames Use the contents of the file as input
The character between the command << identifier statistic identifier and the occurrence of the identifier again
";" Connection command Sequence execution
The "&&" connection command logic executes with the first execution of the second execution of the first error second article does not execute
"||" Connect the command logic or perform the first execution of the second article do not perform the first error the second one executes
Applications in scripts: Commands && echo yes | | echo no command correct yes error no
"|" pipe character command 1| command 2 command 1 correct result as command 2 action object
wildcard character (file name or directory name)//Find a file
1.? Match any one character
2.* Match 0 or any number of characters
3.[] matches any one of the characters in parentheses
4.[-] matches any one of the characters in parentheses--represents a range
5.[^] Match is not any one of the characters in parentheses
Other special symbols in bash
' Single quotes, special symbols around single quotes, such as $,&, have no special meaning
"" Double quotes, the special symbols around the double quotes have no special meaning, but "$", "'", "\" are exceptions. Has the special meaning of "value of the calling variable", "Reference command" and "escape character"
The "anti-quote, inverted quote is a system command that executes first in bash." and $ () function.
$ () to refer to system commands
In the shell script, #开头的行代表注释
$ is used to invoke the value of a variable, such as when the value of the variable name needs to be called, the value of the variable needs to be $name
\ escape character, the special symbol that follows \ will lose its special meaning and become a normal character. such as \$ will output the "$" symbol
Vim Editor
1, VIM ABC (if the existence of the ABC file is open, does not exist to create)
2, in the command mode, two consecutive strokes D can delete the position of the cursor line, percussion U is withdrawn, vim can be multistage withdrawal, VI can only be recalled once
3, tapping I, enter the input mode, can operate on ABC
4. Tap ESC, enter: Wq, exit and save ABC text
Bottom-line mode common directives
: W Save
: Q exit
:! Force exit
: Wq Save Exit
: q! Do not save exit
: LS lists all open files
: N switches to the next file
: N switches to previous file
: 15 (number) cursor switch to line 15th
/xxx switch to the position of the first XXX after the cursor
? XXX switch to the position of the first XXX before the cursor
DD deletes the cursor in the row
o Insert a row below the line where the cursor is located and switch to input mode
YY the line where the cursor is copied
P paste below the line where the cursor is located
P (uppercase) is pasted above the line where the cursor is located
Command mode common directives
H Cursor Shift Left
J Cursor Move Down
K Move Cursor up
L MOVE the cursor right
Ctrl+f PAGE DOWN (front)
Ctrl+b page Up (back)
Ctrl+d down half page (down)
Ctrl+u up half page (UP)
Disk Management
DF: View Disk partition usage
-L: Show only local default disks (default)
-A: Displays disk usage for all file systems
-h displays disk capacity in the most appropriate unit for 1024 binary (default KB display)
-H: Display disk Capacity in the most appropriate unit for 1000 binary calculation
-t display disk partition type
-T displays disk partitions for the specified type of file system//such as: Df-t EXT4
-X does not display disk partitions for the specified type of file system
The file size on the DU statistics disk
-B Statistics files in bytes//statistics are rounded size
-K statistics files in kilobytes//statistics are rounded size
-M in MB statistics file//statistics are rounded size
-H according to 1024 binary in the most appropriate unit statistics file
-H according to 1000 binary in the most appropriate unit statistics file
-s Specifies the statistic target//such as: Du-s tmp or Du-s *.zip
Summary of Common Linux commands