In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "summary of common commands in Linux". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "summary of common commands in Linux".
1.ls [option] [directory name | list all directories and files under the relevant directory
-a lists all files that include hidden files starting with .a
-A through-a, but does not list "." And ".."
-l list details of the file
-c display according to ctime sort
-t sort according to file modification time
-color [= WHEN] identify file types by color WHEN can be one of 'never',' always', or 'auto'
White: represents a normal file
Blue: indicates directory
Green: indicates executable file
Red: indicates a compressed file
Light blue: linked fil
Flashing red: indicates that there is a problem with the linked file
Yellow: indicates the device file
Gray: indicates other files
2.mv [options] Source file or directory directory or multiple source files | move or rename files
-b make a backup before overwriting
-f forcibly overwrite without asking if it exists
-I ask whether to overwrite if it exists
-u newer coverage
-t move multiple source files to a unified directory, with directory parameters first and file parameters later.
Eg:
Mv a / tmp/ moves file a to the / tmp directory
Mv a b named a b
Mv / home/zenghao test1.txt test2.txt test3.txt
3.cp [options] Source file or directory directory or multiple source files | copy the source file to the destination file, or copy multiple source files to the destination directory.
-r-R recursively copy the contents of this directory and its subdirectories
-p is copied along with the file properties.
-f force copy without asking
-s generate shortcuts
-a copy all the features of the file together
4.scp [parameters] [original path] [destination path] | copy files and directories between Linux servers
-v show the details of the output
-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:remote_file
The first and second specify the user name, and the user password is required after the command is executed. The first one only specifies the remote directory, the file name remains the same, and the second specifies the file name.
The third and fourth do not specify a user name, and you need to enter a user name and password after the command is executed, the third only specifies a remote directory, the file name remains the same, and the fourth specifies a 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 a user name. You need to enter a user name and password after the command is executed.
Eg:
Copy from local to remote
Scp / home/daisy/full.tar.gz root@172.19.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 a file
-r Delete a folder
-f deletion does not prompt
-I delete prompt
-v detailed display to proceed with steps
6.touch [options] file | time when an empty file is created or updated
-a modify access time only
-m value modification change time
-r eg:touch-r a b to make b the same time as a
-t specify a specific time eg:touch-t 201211142234.50 log.log
-t time [[CC] YY] MMDDhhmm [.SS], C: top two of the year
7.pwd to view the current path
8.cd changes the current directory
-: return to the last directory
.. Return to the upper directory
Enter: return to the home directory
/: root directory
9.mkdir [options] directory … | | create new directory |
-p create a directory recursively, or in turn if the parent directory does not exist
-m customize the permission to create a directory eg:mkdir-m 777 hehe
-v displays the details of the creation directory
10.rmdir delete empty directory
-v shows the execution process
-p delete if the parent directory is empty after the parent has deleted it.
11.rm [options] file... | | one or more files or directories |
-f ignores files that do not exist and does not give prompts
-I Interactive deletion
-r Recursively delete the listed directory and its subdirectories
-v list details
12.echo: displaying content
No line wrapping after-n output
-e encountered special handling of escape characters
Eg:
Echo "hehe" displays hehe
Ehco-e "hehe" displays he (new line) he
13.cat [options] [File].. | display the entire file at a time or create one file from the keyboard or merge several files into one file
-n numbered file contents are output again
-E prompt $at the end of the line
14.tac | display in reverse
15.more | View the content of the article by page and read the file from front to back, so the whole file is loaded at startup
+ n starts from the nth line
-n view n rows of data at a time
+ / String searches for the location of the String string, starting with the first two lines
-c clear the screen and then display it
-p clear the screen when changing pages
16.less | the content of the article can be viewed screen by screen before and after viewing. The entire file will not be loaded before viewing.
-m displays a percentage similar to the more command
-N display line number
/ string: the ability to search down for "string"
? Strings: the ability to search up for "strings"
N repeat the previous search (and / or? Related)
N reverse repeat the previous search (and / or? Related)
B turn back one page
D turn back half a page
17.nl [options]... [document]... | | automatically add a line number to the output content |
-b
-b a lists line numbers regardless of whether there are blank lines (similar to cat-n)
-b t blank lines do not list line numbers (default)
-n has three parameters of ln rn rz, which are displayed on the leftmost side, zero on the rightmost side and 0 on the rightmost side.
18.head [parameters]... [document]... | | displays the beginning of the file. It starts with 10 lines by default. |
-v displays the file name
-c number displays the first number characters. If number is negative, it displays everything except the last number character.
-number/n (+) number displays the contents of the previous number line
-n number if number is negative, all contents except the last number row are displayed.
19.tail [required parameters] [Select parameters] [File] | display the end of the file
-v displays detailed processing information
-Q does not display processing information
-num/-n (-) num displays the last num line content
-n + num displays the following data starting from the num line
-c displays the last c characters
-f loop read
20.vi Editing Fil
W filename saves the article with the specified file name
Wq saves and exits
: q! Force exit without saving
Command line mode function key
1) insert mode
Press "I" to switch to insert mode "insert mode". Press "I" to enter the file from the current position of the cursor after entering insert mode
After pressing "a" to enter insert mode, the text is entered from the next position where the current cursor is located.
When you press "o" to enter insert mode, insert a new line and enter text at 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 and down, but the regular vi uses lowercase letters "h", "j", "k" and "l" to control the cursor to move left, down, up and right respectively.
Press "ctrl" + "b": move the screen one page back.
Press "ctrl" + "f": the screen moves one page forward.
Press "ctrl" + "u": move the screen to "back" half a page.
Press "ctrl" + "d": move the screen half a page to the front.
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 the line where the cursor is located.
Press "^": move to the beginning of the line where the cursor is located
Press "w": the cursor jumps to the beginning of the next word
Press "e": the cursor jumps to the suffix of the next word
Press "b": the cursor goes back to the beginning of the previous word
Press "# l": move the cursor to the # th position on the line, for example: 5lMagne56l
4) Delete text
"x": each time you press, delete the "after" character of the cursor location.
"# x": for example, "6x" means to delete "after" 6 characters where the cursor is located.
"X": uppercase X. each time you press it, one character in front of the cursor is deleted.
"# X": for example, "20X" means to delete the "first" 20 characters where the cursor is located.
"dd": delete the line of the cursor.
"# dd": delete # lines from the line where the cursor is located
5) copy
"yw": copies the character where the cursor is located to the suffix into the buffer.
"# yw": copy # words to the buffer
"yy": copies the line of the cursor to the buffer.
"# yy": for example, "6yy" means to copy "count down" six lines of text from the line where the cursor is located.
"p": paste the characters in the buffer to the position of the cursor. Note: all copy commands related to "y" must work with "p" to complete the copy and paste function.
6) replace
"r": replace the character where the cursor is located.
"R": replaces the character where the cursor goes 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 go back to the previous operation. Press "u" multiple times to perform multiple replies.
8) Chan
"cw": change the word where the cursor is located to the suffix
"c3w": for example, "c3w" means to change 3 words
9) Jump to the specified line
"ctrl" + "g" lists the line number of the cursor.
"# G": for example, "15G" means to move the cursor to the beginning of line 15 of the article.
21.which executable file name | View the location of the executable file and 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 the executable file.
-m locate the help file.
-s locate the source code file.
-u search for files under the default path other than executable files, source code files, and help files.
-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 | search files quickly by searching the database
-r conditions for finding by using normal expressions
24.find find [PATH] [option] [action] | look for files in the file tree and process them accordingly
Options and parameters:
1. Time-related options: total-atime,-ctime and-mtime and-amin,-cmin and-mmin, described by-mtime
-mtime n: n is a number, meaning a file that has been changed "within one day" before n days.
-mtime + n: lists the file names that have been changed before n days (excluding the n days themselves)
-mtime-n: lists the file names that have been changed within n days (including the n days themselves).
-newer file: file is an existing file that lists file names that are newer than file
two。 Parameters related to the user or group name:
-uid n: n is the number, which is the user's account number ID, i.e. UID
-gid n: n is a number, which 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: people looking for file owners who don't exist / 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 with the file name filename (wildcards can be used)
-size [+ -] SIZE: search for files larger (+) or smaller (-) than SIZE. The specifications of this SIZE are:
C: stands for byte
K: stands for 1024bytes. So, to find a file larger than 50KB, it is "- size + 50k".
-type TYPE: the type of search file is TYPE, and the main types are:
General formal files (f)
Device file (b, c)
Directory (d)
Link file (l)
Socket (s)
FIFO (p)
-perm mode: search for files with file permissions "exactly equal" to mode. This mode is a property value similar to chmod. For example, the property of-rwsr-xr-x is 4755!
-perm-mode: search for files whose permissions "must include all mode permissions", for example
We want to search for-rwxr--r--, that is, 0744 files, using-perm-0744. When the permission of a file is-rwsr-xr-x, that is, 4755, it will also be listed, because the attribute of-rwsr-xr-x already includes the attribute of-rwxr--r--.
-perm + mode: search for files with file permissions that "contain the permissions of any mode", for example
Said, when we search for-rwxr-xr-x, that is,-perm + 755, but a file attribute of-rw- will also be listed because it has-rw.... The property of exists!
4. Additional actions that can be taken:
-exec command: command is other instructions,-exec can be followed by additional instructions to process the search results.
-print: print the result to the screen, this action is a default action!
Eg:
Find /-perm + 7000-exec ls-l {};, the extra instruction begins with-exec and ends with; instead of what was found earlier
| | xargs |
-I the default front output is replaced by {}
Eg:
Find. -name "* .log" | xargs-I mv {} test4
25.grep 'regular expression' filename | search for text with regular expression and print out matching lines
-c outputs only the count of matching rows.
-I is not case-sensitive (for single characters only).
-l displays only the file name
-v displays all lines that do not contain matching text.
-n displays matching row data and its line number
25.file | determines the file type
26.gzip [- cdtv#] File name | Compression, decompression, and source files no longer exist
-d to decompress
-c output the compressed data to the screen
-v: displays information such as the compression ratio of the original file / compressed file
-#: compression level,-1 is the fastest, but the compression ratio is the worst, = 9 is the slowest, but the compression ratio is the best
27.gunzip | decompress
28.bzip2 | Compression and decompression
-d: decompress
-z: compression
-k: keep the source file
-c: output the data generated by the compression process to the screen!
-v: information such as the compression ratio of the original file / compressed file can be displayed
-#: same as gzip, the parameters of compression ratio are calculated.-9 is the best, and-1 is the fastest!
29.bzcat reads data without decompression
30.tar [primary option + secondary option] file or directory | multiple directories or files are packaged and compressed into one large file
Main options:
-c create a packaged file, which can be paired with-v to view the name of the packaged file (filename)
-t to see what file names are contained in the contents of the packaged files, with emphasis on "file names"
-x unpacking or decompression function, can be unpacked with-C (uppercase) in a specific directory
Secondary options:
-j compress / decompress through bzip2 support: at this point, the file name is preferably * .tar.bz2
-z compress / decompress through gzip support: the file name is preferably * .tar.gz at this time
-v displays the name of the file being processed during the compression / decompression process!
-f filename-f is followed by the file name to be processed immediately!
-C directory this option is used to extract, if you want to extract in a specific directory, you can use this option.
-- exclude FILE: ignore a file eg: tar-- exclude / home/zenghao-zcvf myfile.tar.gz / home/* / etc during compression and packaging
-p retains the original permissions and attributes of backup data and is often used to back up (- c) important configuration files
-P (uppercase) retains the absolute path, which allows the backup data to contain the meaning of the root directory
Eg:
Compression: tar-jcvf filename.tar.bz2 the name of the file or directory to be compressed
Inquiry: tar-jtvf filename.tar.bz2
Unzip: tar-jxvf filename.tar.bz2-C directory to be unzipped
31.exit exits the current shell
32.logout exit login shell
33.shutdown-h now
34.users displays users who are currently logged in to the system
Users and sources logged in by 35.who on this machine
-H or-- heading displays the header information column of each field.
36.w users logged in on this machine and their running programs
-s uses a concise format list and does not show the login time of the user, the CPU time spent by the terminal phase jobs and programs.
-h does not display the title information column of each field.
37.write sends messages to users currently online
38.wall sends messages to all users who log in to the machine.
39.last views the user's login log
40.lastlog checks the last login time of each user.
41.finger [options] [user] [user @ Host] | View user information
-s displays the user's registration name, actual name, terminal name, write status, stagnation time, login time and other information
In addition to the information displayed with the-s option, it also displays information such as the user's home directory, login shell, mail status, and the contents of .plan, .project, and .forward files under 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 an alias
44.unalias ii | Clears aliases
45.useradd [- u UID] [- g initial group] [- G secondary group] [- c description column] [- d absolute path of home directory] [- s shell] user account name | add users
-M does not create a user's home directory! (default value of system account)
-m to create a user's home directory! (default value of general account)
-r set up a system account whose UID will be limited.
-e account expiration date in the format "YYYY-MM-DD"
-D View the default values of useradd
46.passwd | change password
-l invalidate the password
-u is opposite to-l, user unlocks
-S lists the relevant parameters in the login user's passwd file
-n days followed, field 4 of shadow, how long can the password not be changed?
-x is followed by the number of days, field 5 of shadow, how long must the password be changed
-w followed by days, field 6 of shadow, warning days before password expiration
-I is followed by "date", field 7 of shadow, and password expiration date
Use Pipeline Liu to set password: echo "zeng" | passwd-- stdin zenghao
47.userdel Delete user
-r user files are deleted as well
48.chage [- ldEImMW] account name | modify the attributes related to the user's password
-l list the detailed password parameters of the account
-d followed by date, modify the third field of shadow (date of the last password change), format YYYY-MM-DD
-E is followed by date, modify the eighth field of shadow (account expiration date), format YYYY-MM-DD
-I the following days, modify the seventh field of shadow (password expiration date)
-m followed by the number of days, modify the fourth field of shadow (minimum number of days of password retention)
-M is followed by the number of days to modify the fifth field of shadow (how long does the password need to be changed)
-W following the number of days, modify the sixth field of shadow (warning date before password expiration)
49.usermod [- cdegGlsuLU] username | modify relevant attributes of a user
-C is followed by the account description, that is, the description column in the fifth column of / etc/passwd, you can add some account description.
-d is followed by the home directory of the account, that is, modify the sixth column of / etc/passwd
-e is followed by a date, and 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 shadow.
-g followed by the initial group, modify the fourth field of / etc/passwd, which is the field of GID!
-G is followed by a secondary group to modify the group that the user can support
-l is followed by the account name. That is, modify the account name, the first column of / etc/passwd!
-s is followed by the actual file of Shell, such as / bin/bash or / bin/csh, and so on.
-u followed by the UID number! That is, the information in column 3 of / etc/passwd
-L freeze password
-U unfreeze password
50.id [username] | View the id information related to the user. It can also be used to determine whether the user exists.
51.groups looks at the groups supported by login users. The first output group is a valid group.
52.newgrp handoff valid group
53.groupadd [- g gid] group name | add group
-g set the specific group id of the add group
54.groupmod [- g gid] [- n group_name] group name | modify group information
-g modify existing GID numbers
-n modify the existing group name
55.groupdel [groupname] | Delete a group
56.gpasswd | Group administrator feature
Root Manager actions:
-gpasswd groupname sets the password
-gpasswd [- A user1,...] [- M user3,...] Groupname
-A hand over the control of groupname to the subsequent users (the administrator of the group)
-M add some accounts to this group
-gpasswd [- r] groupname
-r remove the password for groupname
Group Administrator actions:
-gpasswd [- ad] user groupname
-an add a user to the groupname group
-d remove a user from the groupname group
57.chfn modifies personal information
58.mount [- t vfstype] [- o options] device dir
-ro uses read-only mode to attach devices
-rw uses read-write mode to connect the device
Eg:mount / home/mydisk.iso / tmp/mnt accesses content in mydisk through mnt
59umount unmount
60.cut
-b: split in bytes. These byte positions ignore multibyte character boundaries unless the-n flag is also specified.
-c: split on a character basis.
-d: custom delimiter, default to tab.
-f: used with-d to specify which area to display.
61.sort
-n is sorted by the size of the number.
-o saves the sorted results to the specified file.
-r is sorted in reverse order.
-t specifies the field delimiter used for sorting.
-k chooses which interval to sort.
62.wc counts the number of bytes, words and lines in the specified file, and displays the statistical results.
-l filename report number of rows
-c filename report byte
-m filename report number of characters
-w filename reports word count
63.uniq removes adjacent duplicate lines from the file
-c or-- count: displays the number of repetitions of the row next to each column
-d or-- repeated: show only recurring rows and columns
-f or-- skip-fields=: ignores the comparison of specified fields
-s or-- skip-chars=: ignores comparing specified characters
-u or-- unique: rows that are shown only once
-w or-- check-chars=: specifies the characters to compare.
64.set displays environment variables and normal variables
65.env displays environment variables
66.export turns ordinary variables into environmental variables
67.unset deletes an environment variable
Aaa () {} defines a function
68.read
-p prompt character
-number of seconds to wait for the pick-up
69.declare 、 typeset
-I is declared as an integer
-an is declared as an array
-f is declared as a function
-r declared as read-only
70.ulimit restricts certain system resources of users
-f the maximum file capacity that can be created by this shell (which may generally be set to 2GB) is Kbytes eg: ulimit-f 1024 restricts users to create files with less than 1MBytes size.
71.df [options] [File] | displays the free space of the specified disk file. If no file name is specified, the free space of all currently mounted file systems will be displayed.
-a shows all file systems
-h file size friendly display
-l displays only the local file system
-I display inode information
-T displays the file system type
72.du [options] [File] | displays the disk usage space for each file and directory
-h easy way to read
-s displays only the size of the sum
73.ln [parameter] [source file or directory] [target file or directory] | A file establishes a synchronous link in another location
-s to establish a soft connection
-v shows the detailed process
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 do not check case
-Q displays only differences and no details
Eg: diff a b > parch.log compares the differences between the two files and produces patches
75.date [parameters]... [+ format] | displays or sets the date and time of the system
% H hours (expressed as 00-23).
% M minutes (expressed as 00-59).
% P AM or PM.
% D date (including year, month and day)
% U number of weeks in the year.
Date-s "2015-10-17 01:01:01" / / time setting
Date +% Y%m%d / / shows the day before yesterday, month and day of the year
Date +% Y%m%d-- date= "+ 1 day/month/year" / / shows the date of the previous day / month / year
Date +% Y%m%d-- date= "- 1 day/month/year" / / shows the date of the following day / month / year
Date after 2 weeks of date-d'2 weeks'
76.cal [Parameter] month] [year] | View calendar
-1 displays the calendar of the current month
-3 displays the calendar of the previous, current, and next month
-m shows Monday as the first day of the week
-s (default) Sunday is the first day
-j Calendar showing the day of the year
-y displays the calendar for the current year
77.ps | lists the snapshots of the current process
A shows all processes
-a displays all programs under the same terminal
E display environment variables
F shows the relationship between processes
-H shows the tree structure
R displays the program of the current terminal
T displays all the programs of the current terminal
-au displays more detailed information
-aux displays all itineraries that include other users
-u specify all processes of the user
78.top [Parameter] | displays information about the processes being executed by the current system, including process ID, memory usage, CPU occupancy, etc.
79.kill [Parameter] [process number] | Kills the process
80.free [Parameter] | displays the free and used physical memory and swap memory in the linux system, and the buffer used by the kernel
81.vmstat | monitors the virtual memory, processes and CPU activities of the operating system
82.iostat [parameters] [time t] [times n] (refresh every t time, up to n times) | monitor the disk operation activity of the system and report disk activity statistics, as well as CPU usage.
-p [disk] shows the disk and partition
83.watch [parameters] [Command] | repeat a command to observe the changes
How many seconds does it take to refresh?
-d highlight dynamic Chan
84.at [Parameter] [time] | A specified task can be executed only once at a specified time.
HH: mm [am | pm] + number [minutes | hours | days | weeks] force the task to be performed at a certain time in a certain month and day of a certain year
Atq view tasks that are not performed by the system
Atrm n Delete the task numbered n
At-c n displays the contents of the task numbered n
85.crontab | scheduled task scheduling
File loads crontab
-e Editing the contents of a user's crontab file
-l displays the contents of a user's crontab file
-r Delete a user's crontab file
86.ifconfig [Network Devices] [parameters] | View and configure network devices
87.route | display and manipulate the IP routing table
88.ping [Parameter] [Hostname or IP address] | Test connectivity to the target host
-Q shows only the final result
89.netstat | displays statistics related to IP, TCP, UDP and ICMP protocols
90.telnet [parameters] [Host] | used for remote login. Messages are sent in clear text, and the security is not good.
91.rcp [Parameter] [Source File] [destination File] | remote file copy
-r recursive replication
-p preserves the properties of the source file
Usage: rcp-r remote_hostname:remote_dir local_dir
92.wget [parameters] [URL address] | download files directly from the network
-o FILE writes records to FILE file eg: wget-O a.txt URL
Wget-- limit-rate=300k URL speed limit download
93.awk
The-F separator separates the content with a delimiter
{} the content of the script to be executed eg:cat / etc/passwd | awk-F':'{print $1 "" $7} "
94.sed replaces, deletes, adds and selects data rows.
An added, appears in the new next line
C replaces the line eg between N1 Hi' ab N2: sed '1dint 2c Hi' ab
D Delete
I insert, appear on the new previous line
When 95.paste merges files, you need to ensure that the number of lines of two files merged is the same.
-d specifies a field delimiter that is different from the space or tab key
-s merge by line, with a single file on one line
96.su [parameters] user | switch login
-l change along with environment variables and working directory when switching
-c command executes command to change back to the original user
97sudo | execute specific commands with the privileges of a specific user
-l lists the commands that the current user can execute
-u username#uid to specify users to execute commands thank you for your reading, the above is the "summary of common commands of Linux" content, after the study of this article, I believe you have a deeper understanding of the common command summary of Linux, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.