Summary of 97 common Linux commands

1.ls [Options] [Directory Name| List all directories and files in the relevant directory

-a List all files including hidden files starting with .a -A pass -a, but do not list "." and ".." -l List the detailed information of the files -c Sort according to ctime display -t According to the file Modification time sorting---color[=WHEN] Use color to identify file types. WHEN can be one of'never','always' or'auto'. White: normal files. Blue: directories. Green: executable files. Red: indicates the compressed file Light blue: the link file flashes red: indicates the linked file has a problem Yellow: indicates the device file Gray: indicates other files

2.mv [options] source file or directory or multiple source files | move or rename files

-b Make a backup before overwriting -f if it exists, do not ask and force overwrite -i if it exists, ask whether to overwrite -u overwrite when newer -t move multiple source files to a unified directory, the directory parameter is first, the file parameter is After eg: mv a /tmp/ Move file a to /tmp directory mv ab Name a b mv /home/zenghao test1.txt test2.txt test3.txt

Summary of 97 common Linux commands

3.cp [Options] Source file or directory directory or multiple source files | Copy the source file to the target file, or copy multiple source files to the target directory.

-r -R copy the contents of the directory and its subdirectories recursively -p copy the past together with the file attributes -f force copy without asking -s generate a shortcut -a copy all the characteristics of the file together

4.scp [parameter] [original path] [target path] | Copy files and directories between Linux servers

-v Display the details of the output in detail -r Copy the entire directory recursively (1) Copy files: Command format: scp local_file remote_username@remote_ip:remote_folder or scp local_file remote_username@remote_ip:remote_file or scp local_file remote_ip:remote_folder or scp local_file remote_ip: The first and second ones specify the user name, and the user password is required after the command is executed. The first one only specifies the remote directory and the file name remains unchanged. The second one specifies the file name and the third and fourth do not specify the user name. After the command is executed, you need to enter the user name and password, the third only specifies the remote directory, the file name remains unchanged, the fourth specifies the file name (2) Copy the directory: Command format: scp -r local_folder remote_username@remote_ip:remote_folder or scp -r local_folder remote_ip:remote_folder The first one specifies the user name, and the user password is required after the command is executed; the second one does not specify the user name, and the user name and password need to be entered after the command is executed; eg: copy from local to remote scp /home /daisy/full.tar.gz .2.75:/home/root copy from remote to local scp root@/172.19.2.75:/home/root/full.tar.gz /home/daisy/full.tar.gz

5.rm [options] file | delete file

-r delete folder -f delete without prompt -i delete prompt -v show detailed steps

6.touch [Options] File | Create empty file or update file time

-a only modify the access time -m value modify the change time -r eg:touch -rab, make the time of b the same as a -t specify a specific time eg:touch -t 201211142234.50 log.log -t time [[CC] YY]MMDDhhmm[.SS],C: the first two digits

7.pwd view the current path

8.cd to change the current directory

-: Return to the upper directory..: return to the upper directory and press Enter: return to the main directory /: root directory

9.mkdir [Options] Directory... | Create new directory

-p Recursively create a directory, if the parent directory does not exist, create one by one -m Customize the permissions for creating the directory eg:mkdir -m 777 hehe-v Display the detailed information of the created directory

10.rmdir delete empty directory

-v Display the execution process -p If the parent directory is empty after the parent is deleted, delete it

11.rm [Options] File... | One or more files or directories

-f Ignore non-existent files, do not give a prompt -i interactive delete -r recursively delete the listed directory and its subdirectories -v list detailed information

12.echo: display content

-n do not wrap after output -e special treatment when escape characters are encountered eg: echo "hehe" displays hehe ehco -e "hehe" displays he (line break) he

13.cat [Options] [File]..| Display the entire file at once or create a file from the keyboard or merge several files into one file

-n number the content of the file and then output -E prompt $ at the end line

14.tac | reverse display

15.more | View the content of the article by page, read the file from front to back, so the entire file is loaded at startup

+n Display from the nth line -n ​​View n lines of data each time +/String Search for the position of the String character string, and view from the first two lines -c Clear the screen and then display -p Clear the screen when changing pages

16.less | You can move forward and backward to view the content of the article screen by screen, the entire file will not be loaded before viewing

-m Displays the percentage similar to the more command -N Displays line number/string: the function of searching down "string"? String: the function of searching up "string" n Repeat the previous search (related to / or? ) N Repeat the previous search in reverse (related to/or ?) b Turn one page backward d Turn half a page backward

17.nl [Option]… [File]… | Automatically add line numbers to the output

-b -ba lists the line number regardless of whether there is a blank line (similar to cat -n) -bt does not list the line number for a blank line (default) -n has three parameters ln rn rz, which are displayed on the left , The far right display does not add 0, the far right display adds 0

18.head [Parameter]… [File]… | Show the beginning of the file, the default first 10 lines

-v display file name -c number display the first number characters, if number is negative, display everything except the last number characters -number/n (+)number display the contents of the previous number line, -n number if number is negative , Then display all the contents except the last number line of data

19.tail [Required parameter] [Select parameter] [File] | Show the end of the file

-v displays detailed processing information -q does not display processing information -num/-n (-)num displays the content of the last num line -n ​​+num displays the following data from the num line -c displays the last c characters -f loop Read

20.vi edit files

:w filename Save the article with the specified file name: wq Save and exit: q! Force exit command line mode without saving function key 1) Insert mode press "i" to switch to insert mode "insert mode", press "i "After entering the insert mode, the file is entered from the current position of the cursor; after pressing "a" to enter the insert mode, the text is entered from the position next to the current cursor position; after pressing "o" to enter the insert mode, it is to insert a new One line, input text from the beginning of the line. 2) Switch from insert mode to command line mode Press the "ESC" key. 3) Move the cursor vi can directly use the cursor on the keyboard to move up, down, left, right, but the regular vi uses lowercase English letters "h", "j", "k", "l" to control the cursor left, down, and up respectively , Move one space right. Press "ctrl" + "b": the screen moves one page "back". Press "ctrl" + "f": the screen moves one page "forward". Press "ctrl" + "u": the screen moves half a page "back". Press "ctrl" + "d": the screen moves half a page "forward". Press the number "0": Move to the beginning of the article. Press "G": Move to the end of the article. Press "$": Move to the "end of line" of the line where the cursor is located. Press "^": move to the "start of the line" of the line where the cursor is. Press "w": the cursor jumps to the beginning of the next word and press "e": the cursor jumps to the end of the next word and press "b": the cursor returns Press "#l" at the beginning of the last word: the cursor moves to the #th position of the line, such as: 5l, 56l. 4) Delete the character "x": Each time you press it, the character "behind" the cursor is deleted. "#X": For example, "6x" means to delete 6 characters "behind" at the cursor position. "X": Uppercase X. Each time you press it, the "before" character at the cursor position is deleted. "#X": For example, "20X" means to delete the 20 characters "before" at the cursor position. "Dd": Delete the line where the cursor is located. "#Dd": Delete the # line from the line where the cursor is located. 5) Copy "yw": Copy the characters from the cursor position to the end of the word to the buffer. "#Yw": Copy # words to the buffer "yy": Copy the line where the cursor is located to the buffer. "#Yy": For example, "6yy" means to copy 6 lines of text "counting down" from the line where the cursor is located. "P": Paste the characters in the buffer to the cursor position. Note: All copy commands related to "y" must cooperate with "p" to complete the copy and paste functions. 6) Replace "r": Replace the character at the cursor position. "R": Replace the character where the cursor is, until the "ESC" key is pressed. 7) Revert to the last operation "u": If you execute a command by mistake, you can press "u" immediately to return to the previous operation. Press "u" multiple times to perform multiple responses. 8) Change "cw": Change the word at the cursor to the end of the word "c#w": For example, "c3w" means change 3 characters 9) Jump to the specified line "ctrl" + "g" to list the cursor The line number of the line. "#G": For example, "15G" means to move the cursor to the beginning of the 15th line of the article.

21.which executable file name | view the location of the executable file, check whether the system command exists and its location in the path specified by the PATH variable

22.whereis [-bmsu] [BMS directory name-f] File name | Locate the location of executable files, source code files, and help files in the file system

-b locate executable files. -m locate the help file. -s locate the source code file. -u Search for files other than executable files, source code files, and help files in the default path. -B specifies the path to search for executable files. -M specifies the path to search for help files. -S Specifies the path to search for source code files.

23.locate | Quickly search files by searching the database

-r Use regular expressions to find conditions

24.find find [PATH] [option] [action] | Find files in the file tree, and deal with them accordingly

Options and parameters: 1. Time-related options: a total of -atime, -ctime and -mtime and -amin, -cmin and -mmin, with -mtime description -mtime n: n is a number, meaning is before n days "Within one day" the files whose content has been changed; -mtime +n: List the file names of the files whose content has been changed n days before (not including n days itself); -mtime -n: List in n The name of the file whose content has been changed within days (including n days itself). -newer file: file is an existing file, lists file names that are newer than file 2. Parameters related to user or group names: -uid n: n is a number, this number is the user’s account ID, That is, UID -gid n: n is a number, this number is the ID of the group name, that is, GID -user name: name is the user account name! For example, dmtsai -group name: name is the group name, such as users; -nouser: find the owner of the file who does not exist in /etc/passwd! -nogroup: Find files whose owning group does not exist in /etc/group! 3. Parameters related to file permissions and names: -name filename: search for files whose file name is filename (wildcards can be used) -size [+-]SIZE: search for files larger (+) or smaller (-) than SIZE file. The SIZE specifications are: c: represents byte k: represents 1024bytes. Therefore, to find a file larger than 50KB, it is "-size +50k" -type TYPE: The type of the search file is TYPE, and the main types are: normal file (f) device file (b, c) directory ( d) Link file (l) socket (s) FIFO (p) -perm mode: Search for files with file permissions "just equal to" mode. This mode is an attribute value similar to chmod. For example, -rwsr-xr-x The attribute is 4755! -perm -mode: Search for files with file permissions "must include all mode permissions". For example, we want to search for -rwxr--r--, which is 0744 files, and use -perm -0744, as a file When the permission is -rwsr-xr-x, that is, 4755, it will also be listed, because the attributes of -rwsr-xr-x already include the attributes of -rwxr--r--. -perm +mode: Search for files with file permissions "including the permissions of any mode". For example, when we search for -rwxr-xr-x, that is, -perm +755, but a file attribute is -rw--- ---- will also be listed, because it has the -rw.... attribute! 4. Additional actions that can be performed: -exec command: command is other instructions, additional instructions can be followed by -exec to process the search results. -print: Print the result to the screen, this action is the default action! eg: find / -perm +7000 -exec ls -l {};, the extra instruction starts with -exec, ends with {} instead of the previously found content | xargs -i The default front output is {} instead of eg: find. -name "*.log" | xargs -i mv {} test4

25.grep'regular expression' file name | search text with regular expression and print out the matching lines

-c Only output the count of matching lines. -I is not case sensitive (only applies to single characters). -l displays only file names -v displays all lines that do not contain matching text. -n display matching line data and its line number

25.file | Determine file type

26.gzip [-cdtv#] File name | Compress, decompress, source files no longer exist

-d to decompress -c to output the compressed data to the screen -v: display information such as the compression ratio of the original file/compressed file case -#: compression level, -1 is the fastest, but the compression ratio is the worst, = 9 is the most Slow, but the compression ratio is best

27.gunzip | Unzip

28.bzip2 | Compress, decompress

-d: unzip -z: compress -k: keep the source file -c: output the data generated by the compression process to the screen! -v: can display information such as the compression ratio of the original file/compressed file case; -#: same as gzip, it is the parameter for calculating the compression ratio, -9 is the best, -1 is the fastest!

29.bzcat read data without decompression

30.tar [main option + auxiliary option] file or directory | multiple directories or files are packaged and compressed into a large file

Main options: -c to create a packaged file, you can use -v to view the packaged file name (filename) in the process -t to view which file names are contained in the content of the packaged file, the focus is on the "file name"; -x solution The function of packaging or decompression can be used with -C (uppercase) to decompress in a specific directory. Auxiliary options: -j Compress/decompress through the support of bzip2: at this time, the file name is preferably *.tar.bz2 -z transparent Compress/decompress with the support of gzip: at this time, the file name is best *.tar.gz -v During the compression/decompression process, the file name being processed will be displayed! -f filename -f is followed by the file name to be processed immediately! -C directory This option is used for decompression, if you want to decompress in a specific directory, you can use this option. --exclude FILE: Ignore a file during the compression and packaging process eg: tar --exclude /home/zenghao -zcvf myfile.tar.gz /home/* /etc -p Keep the original permissions and attributes of the backup data, often used for backup (-c) Important configuration file -P (uppercase) Keep the absolute path, which means that the root directory exists in the backup data; eg: Compression: tar -jcvf filename.tar.bz2 The name of the file or directory to be compressed Query: tar -jtvf filename.tar.bz2 Decompression: tar -jxvf filename.tar.bz2 -C The directory to be decompressed

31.exit exit the current shell

32.logout Exit the login shell

33.shutdown -h now

34.users displays the users currently logged into the system

35. Who logged in the user and source of this machine

-H or --heading Display the header information row of each field.

36.w Users who log in to this machine and the programs they run

-s uses a concise format list, does not display the user login time, the CPU time consumed by terminal phase operations and programs. -h Does not display the header information row of each column.

37.write Send messages to users who are currently online

38.wall send messages to all users who log in to this machine

39.last View the user's login log

40.lastlog View the last login time of each user

41.finger [Options] [User] [User@Host] | View user information

-s displays the user's registered name, actual name, terminal name, writing status, dead time, login time and other information -l in addition to the information displayed with the -s option, it also displays the user's home directory, login shell, mail status and other information, And the contents of the .plan, .project, and .forward files in the user's home directory. -p is the same as the -l option except that the .plan file and .project file are not displayed

42.hostname view hostname

43.alias ii = "ls -l" | Add alias

44.unalias ii | clear alias

45.useradd [-u UID] [-g initial group] [-G secondary group] [-c description column] [-d home directory absolute path] [-s shell] user account name | new user

-M Do not create user home directories! (System account default value) -m Create user home directory! (General account default value) -r Create a system account, the UID of this account will be restricted -e Account expiration date, the format is "YYYY-MM-DD" -D View the default values ​​of useradd

46.passwd | Change password

-l to invalidate the password -u and -l, user unlock -S lists the relevant parameters in the login user passwd file -n followed by the number of days, the fourth field of shadow, how long the password cannot be changed -x followed by the number of days, shadow The 5th field of the password must be changed within how long -w followed by the number of days, the 6th field of shadow, the number of warning days before the password expires -i is followed by "date", the 7th field of shadow, the password expiration date uses the channel Liu Set password: echo "zeng" | passwd --stdin zenghao

47.userdel delete user

-r delete user files

48.chage [-ldEImMW] account name | modify the attributes of the user password

-l lists the detailed password parameters of the account; -d followed by the date, modify the third field of shadow (the date of the last password change), format YYYY-MM-DD-E followed by the date, modify the eighth field of shadow (account Expiration date), format YYYY-MM-DD-I followed by the number of days, modify the seventh field of shadow (password expiration date) -m followed by the number of days, modify the fourth field of shadow (minimum password retention days) -M followed by the number of days, modify Shadow fifth field (how long does the password need to be changed) -W followed by the number of days, modify the shadow sixth field (warning date before password expiration)

49.usermod [-cdegGlsuLU] username | Modify user attributes

-c followed by the account description, that is, the description column of the fifth column of /etc/passwd, you can add some account descriptions. -d followed by the home directory of the account, that is, modify the sixth column of /etc/passwd; -e followed by the date, the format is YYYY-MM-DD, which is the eighth field data in /etc/shadow! -f is followed by the seventh field with the number of days as shadow. -g followed by the initial group, modify the fourth field of /etc/passwd, which is the field of GID! -G followed by the secondary group, modify the group that this user can support -l followed by the account name. That is to modify the account name, the first column of /etc/passwd! -s is followed by the actual file of the Shell, such as /bin/bash or /bin/csh and so on. -u is followed by UID numbers! That is the data in the third column of /etc/passwd; -L freeze password -U unfreeze password

50.id [username] | View user-related id information, and can also be used to determine whether the user exists

51.groups View the groups supported by the login user, the first output group is a valid group

52.newgrp switch valid group

53.groupadd [-g gid] group name | add group

-g set the specific group id of the added group

54.groupmod [-g gid] [-n group_name] group name | modify group information

-g modify the existing GID number -n modify the existing group name

55.groupdel [groupname] | Delete group

56.gpasswd | Group Administrator Function

Root administrator action: -gpasswd groupname set password -gpasswd [-A user1,...] [-M user3,...] groupname -A transfer the master control of groupname to the subsequent users (the group Group administrator) -M Add some accounts to this group -gpasswd [-r] groupname -r Remove the password of groupname. Group administrator action:-gpasswd [-ad] user groupname -a Add the user to the group groupname -d Remove a user from the group groupname

57.chfn modify personal information

58.mount [-t vfstype] [-o options] device dir

-ro mount the device in read-only mode -rw mount the device in read-write mode eg:mount /home/mydisk.iso /tmp/mnt access the content in mydisk through mnt

59.umount Unmount

60.cut

-b: Split in bytes. These byte positions will ignore multibyte character boundaries unless the -n flag is also specified. -c: Split in character units. -d: Custom delimiter, the default is a tab character. -f: Used with -d to specify which area to display.

61.sort

-n Sort according to the magnitude of the value. -o Save the sorted results to the specified file. -r Sort in reverse order. -t Specifies the field separator character used when sorting. -k Select which interval to sort by.

62.wc Count the number of bytes, words, and lines in the specified file, and display and output the statistical results

-l filename reports the number of lines -c filename reports the number of bytes -m filename reports the number of characters -w filename reports the number of words

63.uniq remove adjacent duplicate lines in the file

-c or-count: display the number of repeated occurrences of the row next to each column; -d or --repeated: display only the repeated rows and columns; -f or --skip-fields=: ignore the comparison specified field; -s or --skip-chars=: ignore the characters specified by the comparison; -u or --unique: display the ranks only once; -w or --check-chars=: specify the characters to be compared.

64.set display environment variables and ordinary variables

65.env display environment variables

66.export turns ordinary variables into environment variables

67.unset delete an environment variable

aaa(){} defines the function

68.read

-p is the prompt character -t is the number of seconds to wait

69.declare, typeset

-i declared as an integer -a declared as an array -f declared as a function -r declared as read-only

70.ulimit restricts certain system resources of the user

-f The maximum file size that this shell can create (generally may be set to 2GB), the unit is Kbytes eg: ulimit -f 1024 limits users to only create files with a capacity of less than 1MBytes

71.df [Options] [File] | Display the available space of the specified disk file, if no file name is specified, the available space of all currently mounted file systems will be displayed

-a Display all file systems -h File size friendly display -l Only display local file systems -i Display inode information -T Display file system type

72.du [Options] [File] | Display the disk space used by each file and directory

-h is a convenient way to read -s only displays the size of the sum

73.ln [Parameter] [Source file or directory] [Target file or directory] | A file establishes a synchronization link in another location

-s establish a soft connection -v show detailed processing

74.diff [Parameter] [File 1 or Directory 1] [File 2 or Directory 2] | Compare the contents of a single file or directory

-b does not check for differences in space characters. -B does not check for blank lines. -i does not check case -q only displays the differences without displaying detailed information eg: diff a b> parch.log compares the differences between two files and generates a patch

75.date [Parameter]… [+Format] | Display or set the date and time of the system

%H hours (expressed as 00-23). %M minutes (expressed in 00-59). %P AM or PM. %D Date (including year, month and day) %U Week number of the year. date -s "2015-10-17 01:01:01" //Time setting date +%Y%m%d //Display the day before yesterday date +%Y%m%d --date="+1 day/month/year" //Display the date of the previous day/month/year date +%Y%m%d --date="-1 day/month/year" //Display the date of the next day/month/year date -d '2 weeks' date after 2 weeks

76.cal [Parameter] Month] [Year] | View calendar

-1 Display the monthly calendar of the current month-3 Display the calendar of the previous, current, and next month -m Display Monday as the first day of the week -s (default) Sunday as the first day -j Display the current month as the first day of the year Calendar of days -y displays the calendar of the current year

77.ps | List snapshots of the current process

a Display all processes -a Display all programs under the same terminal e Display environment variables f Display the relationship between processes -H Display tree structure r Display programs of the current terminal T Display all programs of the current terminal -au Display more detailed information -aux show all itineraries that include other users -u all processes of the specified user

78.top [Parameter] | Display the relevant information of the process currently being executed by the system, including process ID, memory usage, CPU usage, etc.

79.kill [Parameter] [Process ID] | Kill the process

80.free [Parameter] | Display free, used physical memory and swap memory in the Linux system, and the buffer used by the kernel

81.vmstat | Monitor the virtual memory, process, and CPU activities of the operating system

82.iostat [Parameter] [Time t] [Number of times n] (refresh once every t time, up to n times) | Monitor the disk operation activity of the system, report disk activity statistics, and also report CPU usage Happening

-p[disk] displays the status of disks and partitions

83.watch [Parameter] [Command] | Repeat a command to observe changes

-n How many seconds to refresh -d highlight dynamic changes

84.at [Parameter] [Time] | Execute a specified task at a specified time, only once

HH:MM[am|pm] + number [minutes|hours|days|weeks] Force the task to be carried out at a certain time on a certain day of a certain year atq View tasks not executed by the system atrm n Delete tasks with number n at -cn display the content of the task number n

85. crontab | Timing task scheduling

file Load crontab -e Edit the contents of a user's crontab file -l Display the contents of a user's crontab file -r Delete a user's crontab file

86.ifconfig [Network Equipment] [Parameter] | View and configure network equipment

87.route | Display and operate IP routing table

88.ping [Parameter] [Host name or IP address] | Test the connectivity with the target host

-q only displays the final result

89.netstat | Display statistics related to IP, TCP, UDP and ICMP protocols

90.telnet [parameter] [host] | Used for remote login, using clear text to transmit messages, security is not good

91.rcp [parameter] [source file] [target file] | remote file copy

-r copy recursively -p retain the attributes of the source file usage: rcp --r remote_hostname:remote_dir local_dir

92.wget [Parameter] [URL address] | Download files directly from the Internet

-o FILE write records to FILE file eg: wget -O a.txt URLwget --limit-rate=300k URL speed limit download

93.awk

-F Separator Separate the content with a separator {} The contents of the script to be executed eg:cat /etc/passwd |awk -F':''{print $1""$7}'

94.sed performs operations such as replacing, deleting, adding, and selecting data rows

a Add, replace with c in the new next line, replace the line between n1 and n2 eg: sed '1,2c Hi' abd delete i and insert, appear in the new previous line

95.paste merge files, you need to ensure that the number of lines in the two merged files is the same

-d Specify a field separator different from the space or tab key -s merge by line, a single file is a line

96.su [Parameter] user | Switch login

-l Change along with environment variables and working directory when switching -c command Execute command and change back to the original user

97.sudo | Execute specific commands with specific user permissions

-l List the commands executable by the current user -u username#uid to specify the user to execute the command

Portable Energy Storage Outdoor

Langrui Energy (Shenzhen) Co.,Ltd , https://www.langruibattery.com