Linux Is currently the most widely used server operating system , be based on Unix, Free open source , Because of the stability and security of the system , The market share is very high , Almost become the best system environment for program code running .linux Not only can we run our program code for a long time , It can also be installed in various computer hardware devices , Such as mobile phone 、 Router, etc ,Android The bottom layer of the program is running in linux On the system .

One 、linux Directory structure of

/ Sub directory structure

  • bin  (binaries) Store binary executables
  • sbin  (super user binaries) Store binary executables , Only root Ability to visit
  • etc (etcetera) Store system configuration files
  • usr  (unix shared resources) For storing shared system resources
  • home Root directory for user files
  • root  Super user directory
  • dev (devices) Used to store equipment files
  • lib  (library) Store shared libraries and kernel modules needed for running programs in the file system
  • mnt  (mount) System administrator install temporary file system installation point
  • boot Store all kinds of files used for system boot
  • tmp  (temporary) Used to store all kinds of temporary documents
  • var  (variable) Files used to store data that needs to be changed at run time

Two 、linux Common commands

  • Command format : command   - Options   Parameters ( Options and parameters can be empty )
  • Such as :ls  -la  /usr

2.1 Operation files and directories

command Parameters Example explain
cd   cd /home Toggle directory
pwd   pwd Displays 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 multi-level directory , If the parent directory does not exist, I will become the parent directory
cp   cp 1.txt Copy files or directories
  -r cp -r dir1/ Recursive processing , Copy the files in the specified directory together with the subdirectories
mv   mv dir1 dir2 Move files or directories 、 Change the name of a file or directory
rm   rm 1.txt Delete file
 

-r

-f

rm -rf dir1

r Delete all files in this directory at the same time ,

f Force deletion of files or directories

rmdir   rmdir dir1 Delete empty directory
cat   cat 1.txt Display the contents of the text file
more   more 1.txt

Page by page display of text file content , It can turn back and forth , Space back ,b forward

less   less 1.txt

Page by page display of text file content , It can turn back and forth , Space back ,b forward , Support bottom line mode ( Later on )

head   head 1.txt Look at the beginning of the text , Default ten rows
  -[num] head -20 1.txt Look at the beginning of the text and specify the number of lines
tail   tail 1.txt Look at the end of the text , Default ten rows
  -[num] tail -20 1.txt Look at the end of the text and specify the number of lines
  -f tail -f 1.txt Scroll through the file and display it dynamically on the screen , Track... According to file properties
  -F tail -F 1.txt Scroll through the file and display it dynamically on the screen , File name tracking
wc   wc 1.txt

Count the number of lines of text 、 Number of words 、 Number of characters

 

-m

wc -m 1.txt Number of characters
  -w wc -w 1.txt The number of words in the text
  -l wc -l 1.txt Number of lines of text
find -name find / -name 1.txt Find the specified file in the specified directory in the file system
grep   grep aaa 1.txt Find the line containing the specified content in the specified file , example : stay 1.txt Search for include aaa All of the line
ln   ln 1.txt 1_bak.txt Create a link file ,
 

-s

ln -s 1.txt 1_bak.txt Make a symbolic connection to the source file , Not hard connection

2.2 Common commands of the system

command Parameters Example explain
top   top

Shows the most resource consuming processes in the current system

date   date Display the current time of the system
ps     Less used alone , Match parameters according to demand ,ps -ef perhaps ps-aux
  -e /-A ps -e

Show all processes , environment variable

  -f ps -ef Full format display
  -a ps -a

Show all processes for all users ( Including other users )

  -u ps -au

Show processes in the order of user name and start time

  -x ps -aux Show processes without control terminals
kill -9 kill -9 pid Force to kill a process
df   df Shows the usage of the file system disk space
  -h df -h To display in a human readable manner ,Kb,Mb,GB etc.
du    

Displays the total amount of disk space used by the specified directory and its subdirectories

  -s du -s * To display the sum of the specified directories ,* The current directory represents all
  -h du -sh * To display in a human readable manner ,Kb,Mb,GB etc.
free   free Displays the 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 Modify the system temporarily IP( Failure after restart )
ping   ping baidu.com Test network connectivity
hostname   hostname View host name
shutdown -r shutdown -r Turn it off first , Restart again
  -h shutdown -h Do not restart after shutdown
halt   halt

Turn off the power after shutting down , amount to shutdown -h

reboot   reboot

Restart amount to shutdown -r

2.3 Compression and decompression

command Parameters Example explain
gzip   gzip 1.txt Compress the following file or folder
  -d gzip -d 1.txt.gz Unzip the compressed file behind
  -[num] gzip -9 1.txt

Use the specified number num Adjust the compression speed ,-1 or --fast Represents the fastest compression method ( Low compression ratio ),-9 or --best Represents the slowest compression method ( High compression ratio ). The default value of the system is 6

tar -c tar -cvf 1.tar 1.txt Create a parameter instruction for the compressed file , example , take 1.txt Compress it into 1.tar, You can also specify multiple files or folders
  -x tar -xvf 1.tar 1.txt Unpack the parameter instruction of a compressed file
  -z

tar -zcvf 1.tar.gz 1.txt

tar -zxvf 1.tar.gz 1.txt

Need to use gzip , Use gzip Compress or decompress
  -v   Display files during compression
  -f   Use file name , stay f After that, the file name should be received immediately

2.4 File permission Operation

  • linux Interpretation of the description format of document authority
    • The first 1 position : file type (d Catalog ,- Ordinary documents ,l Link to the file )
    • The first 2-4 position : User rights , use u(user) Express
    • The first 5-7 position : Group permissions , use g(group) Express
    • The first 8-10 position : Other user privileges , use o(other) Express
    • The first 2-10 position : Indicates all permissions , use a(all) Express
    • r Read permission ,w Write permission ,x Executable rights ( It can also be expressed in binary  111 110 100  -->  764)
command Parameters example explain
chmod   chmod u+r 1.txt

Permission to modify a file or directory

u Represents the current user ,g Represents the same group of users ,o Means other users ,a Represents all users

r Means to read ,w Said to write ,x For executables

example : modify 1.txt File to add executable permissions to the current user

  -R chmod -R u+r dir1 Modify permissions for all files in the specified directory and its subdirectories
  Three digits chmod 764 1.sh

Directly specify the file permissions

7: Represents readable, writable, executable ,4+2+1

6: Represent readable and writable ,4+2

...

chown   chown user1:group1 1.txt

Modify the user and group to which the file belongs

example : take 1.txt The user of the file is designated as user1, Group for group1

  -R chown -R user1:group1 1.txt

Modify the users and groups of all files and subdirectories in the directory

Use numbers to express authority (r=4,w=2,x=1,-=0)

 

3、 ... and 、linux System commonly used shortcut keys and symbol commands

command Parameters example explain
ctrl + c     Stop the process
ctrl + l     Clear the screen
ctrl + r     Search history command
ctrl + q     sign out
tab     Automatic completion
>   echo "haha" > 1.txt

Output the previous command , Write to the following text

Empty the text , And then write

>>   echo "lala" >> 1.txt

Output the previous command , Write to the following In the text

Don't empty the text , Append to the end of the text

|   cat 1.txt | grep 'hello'

Pipeline command , The output of the previous command is used as input , And then you do the math

example : Print 1.txt With medium hello Line of string

*     wildcard , Means all

Four 、vim Editor

vi / vim yes Linux On the most commonly used text editor and very powerful . Only the command , No menu , The figure below shows vi Switch between various modes of command .

4.1 Modify the text

i

Insert... In front of the cursor

I

Insert... At the current line of the cursor

a

Insert... After the cursor

A

Insert... At the end of the current line of the cursor

o

Insert a new line next to the current line of the cursor

O

Insert a new line on the previous line of the cursor's current line

:wq Save and exit

4.2 Locate the command

:set nu According to the line Numbers
:set nonu Cancel the line Numbers
gg Jump to the first line
G Jump to the last line
:n Jump to the first n That's ok

4.3  Replace and cancel commands

u undo, Cancel the previous operation
Ctrl + r

redo, Back to undo Before

r

Replace character at cursor

R

Replace from where the cursor is , Press Esc Key end

4.3 The delete command

x Deletes the character where the cursor is
nx Delete... After the cursor n Characters
dd Deletes the line where the cursor is located .ndd Delete n That's ok
dG Delete all contents from the cursor line to the end line
D Delete the content from the cursor to the end of the line
:5,7d Deletes the row of the specified range

 

4.4 Common shortcut key

Shift+ zz Save and exit , And “:wq” The same effect
v Enter character visual mode
V Enter line view mode
Ctrl + v Enter block view mode

original text :https://blog.csdn.net/xulong_08/article/details/81463054