Linux is currently the most widely used server operating system. It is based on Unix, open source and free. Due to the stability and security of the system, it has a high market share and has almost become the best system environment for running program codes. Linux can not only run the program code we write for a long time, but also can be installed in various computer hardware devices, such as mobile phones, routers, etc. The bottom layer of the Android program runs on the Linux system.
1. Directory structure of Linux
bin (binaries) stores binary executable files
sbin (super user binaries) stores binary executable files and can only be accessed by root
etc (etcetera) stores system configuration files
usr (unix shared resources) is used to store shared system resources
home is the root directory for storing user files
root superuser directory
dev (devices) is used to store device files
lib (library) stores shared libraries and kernel modules required for running programs in the file system
mnt (mount) The mount point where the system administrator installs a temporary file system
Boot stores various files used when the system boots
tmp (temporary) is used to store various temporary files
var (variable) is used to store files that need to change data at runtime
2. Commonly used commands in Linux
Command format:
command -options arguments (options and arguments can be empty)
For example: ls -la /usr
2.1 Operating files and directories
Order
parameter
Example
illustrate
cd
cd /home
Change directory
pwd
pwd
Display the current working directory
touch
touch 1.txt
Create an empty file
mkdir
mkdir testdir
Create a New Directory
-p
mkidr -p dir1/dir2/dir3/
Create a multi-level directory. If the parent directory does not exist, create the parent directory first.
cp
cp 1.txt
Copying a file or directory
-r
cp -r dir1/
Recursive processing, copying files and subdirectories under the specified directory
mv
mv dir1 dir2
Move files or directories, rename files or directories
rm
rm 1.txt
Deleting Files
-r
-f
rm -rf dir1
r deletes all files in the directory at the same time,
f Force deletion of files or directories
rmdir
rmdir dir1
Deleting Empty Directories
cat
cat 1.txt
Display the contents of a text file
more
more 1.txt
Display the contents of a text file in pages, you can turn pages forward and backward, space is backward, b is forward
less
less 1.txt
Display text file contents in pages, you can turn pages forward and backward, space backward, b forward, support bottom line mode (described later)
head
head 1.txt
View the beginning of the text, the default is ten lines
-[num]
head -20 1.txt
View the specified number of lines at the beginning of the text
tail
tail 1.txt
View the end of the text, default is ten lines
-[num]
tail -20 1.txt
View the specified number of lines at the end of the text
-f
tail -f 1.txt
Circularly scroll and read files and dynamically display them on the screen, tracking them according to file attributes
-F
tail -F 1.txt
Circular scrolling reads files and dynamically displays them on the screen, file name tracking
wc
wc1.txt
Count the number of lines, words, and characters in the text
-m
wc -m 1.txt
Number of characters
-w
wc -w 1.txt
Text word count
-l
wc -l 1.txt
Number of text lines
find
-name
find / -name 1.txt
Searches for a specified file in a specified directory in the file system
grep
grep aaa 1.txt
Search for lines containing specified content in the specified file. For example, search for all lines containing aaa in 1.txt
ln
ln 1.txt 1_bak.txt
Create a link file,
-s
ln -s 1.txt 1_bak.txt
Create symbolic links to source files instead of hard links
2.2 Common system commands Command parameter Example Description top top
Order
parameter
Example
illustrate
top
top
Displays the processes that consume the most resources in the current system.
date
date
Display the current system time
ps
Rarely used alone, with parameters as needed, ps -ef or ps -aux
-e /-A
ps -e
Display all processes, environment variables
-f
ps -ef
Full format display
-a
ps -a
Display all processes of all users (including other users)
-u
ps-au
Display processes in order of username and start time
-x
ps -aux
Display processes without a controlling terminal
kill
-9
kill -9 pid
Force kill a process
df
df
Displays the disk space usage of the file system
-h
df -h
Display in human readable form, Kb, Mb, GB, etc.
du
Displays the total disk space used by the specified directory and its subdirectories
-s
du -s *
Display the total of the specified directory. * indicates all the
-h
du -sh *
Display in human readable form, Kb, Mb, GB, etc.
free
free
Displays current memory and swap space usage
ifconfig
ifconfig
Network card network configuration, often used to view the current IP address
ifconfig eth0 192.168.12.22
Temporarily modify the system IP (invalid after restart)
ping
ping baidu.com
Test network connectivity
hostname
hostname
Check the host name
shutdown
-r
shutdown -r
Shut down first, then restart
-h
shutdown -h
No restart after shutdown
halt
halt
Turn off the power after shutdown, equivalent to shutdown -h
reboot
reboot
Restart is equivalent to shutdown -r
2.3 Compression and Decompression
Order
parameter
Example
illustrate
gzip
gzip 1.txt
Compress the following files or folders
-d
gzip -d 1.txt.gz
Unzip the compressed file
-[num]
gzip -9 1.txt
Use the specified number num to adjust the compression speed. -1 or --fast indicates the fastest compression method (low compression ratio), and -9 or --best indicates the slowest compression method (high compression ratio). The system default value is 6
tar
-c
tar -cvf 1.tar 1.txt
Create a parameter command for a compressed file. For example, compress 1.txt to 1.tar. You can also specify multiple files or folders.
-x
tar -xvf 1.tar 1.txt
Parameters for decompressing a compressed file
-z
tar -zcvf 1.tar.gz 1.txt
tar -zxvf 1.tar.gz 1.txt
Whether to use gzip, use gzip compression or decompression
-v
Display files during compression
-f
Use the file name, and follow the file name immediately after f.
Command Parameter Example Description gzip gzip 1.txt compresses the following file or folder -dgzip -d 1.txt.gz decompresses the following compressed file -[num]gzip -9 1.txt
Use the specified number num to adjust the compression speed. -1 or --fast indicates the fastest compression method (low compression ratio), and -9 or --best indicates the slowest compression method (high compression ratio). The system default value is 6
tar-ctar -cvf 1.tar 1.txt creates a compressed file parameter command, for example, compresses 1.txt into 1.tar, and can also specify multiple files or folders -xtar -xvf 1.tar 1.txt decompresses a compressed file parameter command -z
tar -zcvf 1.tar.gz 1.txt
tar -zxvf 1.tar.gz 1.txt
Do you need to use gzip? Use gzip to compress or decompress. -v Display files during compression. -f Use the file name. The file name should be immediately followed by f.
2.4 File Permission Operations
Interpretation of the description format of Linux file permissions
r read permission, w write permission, x execute permission (can also be expressed in binary 111 110 100 --> 764) 1st bit: file type (d for directory, - for regular file, l for link file) Bits 2-4: User permissions, represented by u (user) Bits 5-7: Group permissions, represented by g (group) Bits 8-10: Other user permissions, represented by o (other) Bits 2-10: All permissions, represented by a (all)
Order
parameter
Examples
illustrate
chmod
chmod u+r 1.txt
Modify file or directory permissions
u represents the current user, g represents the users in the same group, o represents other users, and a represents all users
r means readable, w means writable, and x means executable
Example: Modify the 1.txt file to add executable permissions to the current user
-R
chmod -R u+r dir1
Modify the permissions of all files in the specified directory and its subdirectories
Three digits
chmod 764 1.sh
Directly specify file permissions
7: Readable, writable, and executable, 4+2+1
6: indicates readable and writable, 4+2
...
chown
chown user1:group1 1.txt
Modify the user and group of a file
Example: Specify the user to which the 1.txt file belongs as user1 and the group as group1
-R
chown -R user1:group1 1.txt
Modify the users and groups of all files and subdirectories in the directory
Use numbers to represent permissions (r=4, w=2, x=1, -=0)
3. Common shortcut keys and symbol commands in Linux system
Order
parameter
Examples
illustrate
ctrl + c
Stop a process
ctrl + l
Clear screen
ctrl + r
Search history command
ctrl + q
quit
tab
Autocomplete
>
echo "haha" > 1.txt
Write the output of the previous command to the following text
Clear the text and then write
>>
echo "lala" >> 1.txt
Write the output of the previous command to the following text
Do not clear the text, append to the end of the text
|
cat 1.txt | grep 'hello'
Pipeline command, which takes the output of the previous command as input and then performs operations
Example: Print the line with the string hello in 1.txt
*
Wildcard, meaning all
4. vim editor
vi / vim is the most commonly used text editor on Linux and is very powerful. There are only commands, no menus. The figure below shows the switching between various modes of vi commands.
4.1 Modify the text
i
Insert before the cursor
I
Start inserting at the current line of the cursor
a
Insert after cursor
A
Insert at the end of the current line.
o
Insert a new line below the current line of the cursor
O
Insert a new line above the current line of the cursor
:wq
Save and exit
4.2 Positioning Commands
:set nu
Show line numbers
:set nonu
Cancel line number
gg
Jump to first line
G
Jump to the last line
:n
Jump to line n
4.3 Replace and cancel commands
u
undo, cancel the previous operation
Ctrl + r
redo, return to before undo
r
Replace the character where the cursor is
R
Start replacing from the cursor position and press Esc to end
4.3 Deletion Command
x
Delete the character where the cursor is
nx
Delete n characters after the cursor position
dd
Delete the line where the cursor is located. ndd delete n rows
dG
Delete all the contents from the cursor line to the end of the line
D
Delete the content from the cursor to the end of the line
:5,7d
Delete the specified range of rows
4.4 Common shortcut keys
Shift+zz
Save and exit, same as ":wq"
v
Enter character visual mode
V
Enter line visual mode
Ctrl + v
Enter block visual mode
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.
You may also be interested in:
A complete list of commonly used Linux commands (super comprehensive)
Detailed explanation of the usage of grep command in Linux
A complete list of commonly used Linux commands (recommended for collection)
Solve the problem that the commonly used Linux command "ll" is invalid or the command is not found
Linux common commands chmod to modify file permissions 777 and 754