Essay recording Linux commands, to be improved

  The 20 most commonly used commands in Linux, you can check them anytime you need The 20 most commonly used commands in Linux, you can check them anytime you need them

1. The 20 most commonly used commands in Linux

  This part mainly summarizes some Linux commands that are commonly used by anyone who uses a Linux system. The 20 most commonly used commands in Linux are as follows:

ls
View directories and files
Display detailed information about all files in the current directory: ls-la

mkdir
Create directory
Create the test directory in the current directory: mk dir test
in /opt/ Create the directory img under the test directory. If there is no test directory, create the test directory first: mk dir -p /opt/test/img

cat
View file content
View the content of desc.txt: cat desc.txt

more
View the contents of the file in pages
View the contents of the desc.txt file in pages: more desc.txt

tail
View the tail content of the file
View the last 100 lines of desc.txt: tail -100 desc.txt

cp
Copy command
Copy the desc.txt file to the /mnt directory: cp desc.txt/mnt/
Copy the test directory to the /mnt directory: cp -r test/mnt
Note here that when copying the directory, specify it with -r

mv
Cut or rename
Cut the file desc.txt to the directory /mnt: mv desc.txt/mnt/ 2. When the directory where the source file is located is the same as the target directory, it is a rename operation. 1. When the directory where the source file is located is different from the target directory, it is a cut operation;
Note here that this Linux command has two uses, cutting and renaming

rm
Delete command
Delete the test directory, -r deletes recursively, -f forcefully deletes.
Please be careful before deleting, avoid! :rm -rf test

find
Search file command
Find files ending with .txt in the opt directory: find/opt-name'.txt'

ln
Create link file
Create a symbolic link to the directory /opt/test: ln-s/opt/test./link2test

man
Command Help
Provides help and explanations for commands you are not familiar with: man ls can view ls related usage

cd+pwd

Path operation commands

Change the current directory and enter the netseek directory: cd netseek

View the full path of the current directory: pwd

Crash or restart command: shutdown

Immediate crash: shutdown -h now

Restart after 60s: shutdown -r -t 60

Display network related information: netstat

List all ports: netstat -a

View directory usage: du

Check the usage of c drive in the /opt/test directory: du -h/opt/test

top: Displays the current process information of the system

kill: kill process
Kill the process with process number 27810, force a halt, and make it difficult to recover system resources: kill -s 927810

Change the access permissions of a file or directory: chmod

Permission scope: u (owner) g (group) o (other users), permission code: r (read permission) w (write permission) x (execution permission)

Reduce the execution permissions of test.sh to the file owner: chmodu+xtest.sh

Reduce the execution permissions of the test directory and all files under it to the file owner: chmodu +x -R test

Compression and decompression: tar+vf

Package the test directory as a test.tar.gz file, -z means use gzip compression: tar-zcvftest.tar.gz./test

Unzip the test.tar.gz file: tar-zxvftest.tar.gz

Text editing: vim
Vim has three modes: command mode, insert mode, and edit mode. Use ESC or i or: to switch modes
In command mode,
:qexit:q!Force exit:wqSave and exit
:setnumber displays the line number
/java Find java in the document
yy copy p paste

Edit the desc.txt file: vim desc.txt

2. Other commonly used Linux commands

clear command
clears the screen, equivalent to cls under DOS

date command
displays the current time

mount command
loads a hardware device

mount[parameter] The device mount point to be loaded
mount/dev/cdrom
cd/mnt/cdrom//Enter the CD directory

su command
Switch to another person’s identity without logging out

su -l username (if the username is default, switch to the root state)
su-l netseek (switch to the netseek user, you will be prompted to enter the password) a>

whoami: The terminal will return the username of the current user

whereis: Query the directory where the command is located and the directory where the help document is located
whereis bin displays the directory where bin is located, which will be displayed as: /usr/local/bin

which: Query the directory where the command is located (similar to whereis)

The id:id command can display the real and effective user ID (UID) and group ID (GID). UID is a unique identifier for a user. Group ID (GID) corresponds to multiple UIDs

grep command
This command is often used to analyze a line of information. If there is information we need, the line will be displayed. This command is usually used together with the pipeline command. It is used to filter and process the output of some commands, etc. Its simple sentence pattern is

grep: text content search;
grep success*/*Find files rich in success characters in all files under the current directory

passwd command
can set the password

history command
can display the commands used by the user in the past

finger command
allows users to query information about other users
inger root//View root information

file command
This command is used to determine the basic data of the file following the file command. Since the file types under Linux are not divided into suffixes, this command It is very useful for us. Its usage is very simple. The basic sentence pattern is as follows:
file filename

gcc command
For a person who uses Linux to develop C programs, this command is very important. It is used to compile C language source program files into executable program, because many parameters of g++ are very similar to it, so here we only introduce the parameters of gcc. Its common parameters are as follows:
-o: output, used to specify the generation of an executable file The file name
-c: used to generate the source file into an object file (.o) and prevents the compiler from creating a complete program
-I: reduces the The path to search for header files during compilation
-L: Reduce the path to search for static link libraries during compilation
-S: Generate source files into assembly code files -std=: used to specify the version of C language to be used -lpthread: Connects the thread library implemented by NPTL
-lm: Represents the function library named libm.a in the directory of the standard library

3. Linux pipeline command: |

This command is quite special and is often used in combination.
Use the standard output of one command as the standard input of another command. That is to say, several commands are combined and used, and the result of the latter command is multiplied by the previous command.
Example: grep -r "close" /home/*|more Search all files in the home directory, including close files, and output them in pages.

Guess you like

Origin blog.csdn.net/weixin_44563573/article/details/134016743