Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the 20 commonly used Linux commands

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Today, I would like to talk to you about the 20 commonly used Linux commands, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

I. Files and directories

1. Cd command

(it is used to switch the current directory, and its parameter is the path of the directory to which you want to switch, either absolute or relative.)

Cd / home go to the'/ home' directory

Cd.. Return to the previous directory

Cd.. /.. Return to the upper two-level directory

Cd enters the personal home directory

Cd ~ user1 enters the personal home directory

Cd-returns the directory where it was last located

2. Pwd command

Pwd displays the work path

3. Ls command

(command to view files and directories, meaning list)

Ls view the files in the directory

Ls-l displays the details of files and directories

Ls-a lists all files, including hidden files

Ls-R is listed together with the contents of the subdirectory (recursively listed), which means that all files in that directory will be displayed

Ls [0-9] displays file and directory names that contain numbers

4. Cp command

(used to copy files, meaning copy, it can also copy multiple files to one directory at a time.)

-a: copy the properties of the file together

-p: copied with the attributes of the file instead of using the default method, similar to-an and often used for backup

-I: if the target file already exists, the operation will be asked first when overwriting.

-r: recursive continuous replication for directory replication behavior

-u: it will be copied only when there is a difference between the destination file and the source file

5. Mv command

(used to move files, directories or renames, meaning move)

-f: force force means that if the target file already exists, it will be overwritten without being asked.

-I: if the target file already exists, it will be asked whether to overwrite

-u: if the target file already exists and is newer than the target file, it will be updated

6. Rm command

(used to delete files or directories, meaning remove)

-f: it means force. Ignore files that do not exist and there will be no warning messages.

-I: interactive mode, which asks the user whether to operate before deletion

-r: recursive deletion, most commonly used for directory deletion, is a very dangerous parameter

Second, view the contents of the file

7. Cat command

(used to view the contents of a text file, followed by the name of the file to view, usually piped with more and less)

Cat file1 looks forward at the contents of the file from the first byte

Tac file1 starts from the last line to view the contents of a file in reverse

The number of lines in the cat-n file1 marking file

More file1 looks at the contents of a long file

Head-n 2 file1 view the first two lines of a file

Tail-n 2 file1 view the last two lines of a file

Tail-n + 1000 file1 starts at 1000 lines and shows the values after 1000 lines

Cat filename | head-n 3000 | tail-n + 1000 displays 1000 to 3000 lines

Cat filename | tail-n + 3000 | head-n 1000 starts at line 3000 and displays 1000 (that is, lines 3000mm 3999)

III. File search

8. Find command ()

Find /-name file1 enters the root file system from'/'to search for files and directories

Find /-user user1 searches for files and directories belonging to user 'user1'

Find / usr/bin-type f-atime + 100 searches for execution files that have not been used in the past 100 days

Find / usr/bin-type f-mtime-10 searches for files that have been created or modified within 10 days

Whereis halt shows the location of a binary, source, or man

Which halt displays the full path to a binary or executable file

Delete files greater than 50m:

Find / var/mail/-size + 50m-exec rm {}\

Fourth, file permissions-use "+" to set permissions, use "-" to cancel

9. Chmod command

Ls-lh display permissions

Chmod ugo+rwx directory1 sets permissions for directory owners (u), groups (g), and others (o) to read (rpd4), write (wmem2), and execute (xmem1)

Chmod go-rwx directory1 deletes group (g) and others (o) read and write permissions to the directory

10. Chown command

(change the owner of the file)

Chown user1 file1 changes the owner property of a file

Chown-R user1 directory1 changes the owner properties of a directory and simultaneously changes the properties of all files in the directory

Chown user1:group1 file1 changes the owner and group properties of a file

11. Chgrp command

(change the user group to which the file belongs)

Chgrp group1 file1 changes the group of files

V. text processing

12. Grep command

(analyze the information of a line and display the line if there is any information we need, which is usually used with pipe commands to filter the output of some commands, etc.)

Grep Aug / var/log/messages look for the keyword "Aug" in the file'/ var/log/messages'

Grep ^ Aug / var/log/messages look for words starting with "Aug" in the file'/ var/log/messages'

Grep [0-9] / var/log/messages Select all lines that contain numbers in the'/ var/log/messages' file

Grep Aug-R / var/log/* searches for the string "Aug" in the directory'/ var/log' and subsequent directories

Sed's example.txt example.txt 1 / 2 example.txt replace "string1" with "string2" in the example.txt file.

Sed'/ ^ $/ d'example.txt removes all blank lines from the example.txt file

13. Paste command

Paste file1 file2 merges the contents of two files or columns

Paste-d'+ 'file1 file2 merges the contents of two files or columns, distinguished by "+" in the middle

14. Sort command

Sort file1 file2 sorts the contents of two files

Sort file1 file2 | uniq fetches the union of two files (only one copy of duplicate lines is retained)

Sort file1 file2 | uniq-u delete the intersection and leave other lines

Sort file1 file2 | uniq-d takes out the intersection of two files (leaving only files that exist in both files)

15. Comm command

Comm-1 file1 file2 compares the contents of two files and deletes only the contents contained in 'file1'

Comm-2 file1 file2 compares the contents of the two files and deletes only the contents contained in 'file2'

Comm-3 file1 file2 compares the contents of two files and deletes only the common parts of the two files

VI. Packing and compressing files

16. Tar command

(if the file is packaged, it will not be compressed by default, and if the appropriate parameters are specified, it will also call the appropriate compression program (such as gzip and bzip) to compress and decompress)

-c: create a new package file

-t: check which file names are contained in the contents of the packaged file

-x: unpack or decompress function. You can specify the directory to be unzipped with-C (uppercase). Note that-c _ r _ m _ Q _ x cannot appear in the same command at the same time.

-j: compress / decompress with bzip2 support

-z: compression / decompression with gzip support

-v: displays the name of the file being processed during compression / decompression

-f filename: filename is the file to be processed

-C dir: specify the compressed / unzipped directory dir

Compressed: tar-jcv-f filename.tar.bz2 the name of the file or directory to be processed

Query: tar-jtv-f filename.tar.bz2

Unzip: tar-jxv-f filename.tar.bz2-C directory to be extracted

Bunzip2 file1.bz2 unzips a file called file1.bz2'

Bzip2 file1 compresses a file called 'file1'

Gunzip file1.gz unzips a file called file1.gz'

Gzip file1 compresses a file called 'file1'

Gzip-9 file1 maximum compression

Rar a file1.rar test_file creates a package called 'file1.rar'

Rar a file1.rar file1 file2 dir1 compresses both 'file1',' file2' and directory 'dir1'

Rar x file1.rar decompress the rar package

Zip file1.zip file1 creates a compressed package in zip format

Unzip file1.zip decompresses a compressed package in zip format

Zip-r file1.zip file1 file2 dir1 compresses several files and directories into a package in zip format at the same time

7. System and shutdown (shutdown, restart and logout of the system)

Shutdown-h now shuts down the system (1)

Init 0 shuts down the system (2)

Telinit 0 shuts down the system (3)

Shutdown-h hours:minutes & shuts down the system at the scheduled time

Shutdown-c cancels shutting down the system at the scheduled time

Shutdown-r now restart (1)

Reboot restart (2)

Logout logout

Time measures the execution time of a command (that is, a program)

VIII. Process-related commands

17 ps command

(used to select and output the running status of a process at a certain point in time, meaning process)

-A: all processes are displayed

-a: all processes not related to terminal

-u: processes related to valid users

-x: generally used with parameter a to list more complete information

-l: longer, more detailed listing of PID information

Ps aux # View all process data of the system ps ax # View all processes not related to terminal ps-lA # View all process data of the system ps axjf # View together with part of the process tree status

18 kill command

(used to send a signal to a job (% jobnumber) or a PID (number), which is usually used with the ps and jobs commands)

19killall command

(send a signal to a process started by a command)

20 top command

It is a commonly used performance analysis tool under Linux, which can display the resource consumption of each process in the system in real time, similar to the task manager of Windows.

How to kill a process:

The way of graphical interface

Kill-9 pid (- 9 indicates forced shutdown)

The name of the killall-9 program

The name of the pkill program

View the process port number:

Netstat-tunlp | grep port number after reading the above, do you have any further understanding of the 20 commonly used Linux commands? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report