Detailed explanation of some Linux commands

PHP中文网
Release: 2017-06-20 11:03:12
Original
1601 people have browsed it

1.linux directory structure

bin: (binaries) stores binary executable files
sbin (super user binaries) stores binary executable files
etc: (etcetera) stores system configuration File
 usr (unix shared resources) is used to store shared system resources
 Home is the root directory where user files are stored
 root super user directory
 dev(devices) is where device files are stored
lib(library ) stores the shared libraries and kernel modules needed to run programs in the file system
mnt(mount) is the mounting point where the system administrator installs the temporary file system
boot stores various files used during system boot
tmp (temporary) is used to store various temporary files
var (variable) is used to store files that need to change data during operation

2. Switch directory command cd

cd test Switch to the test directory
cd .. Switch to the upper directory
cd / Switch to the system directory
cd ~ Switch to the user home directory
cd - Switch to the previous directory

3. Directory operation commands (add, delete, modify, check)

Add directory:

mkdir directory name

mkdir test is to generate a test directory in the current directory

View directory:

 ls

ls: All directories and files in the current directory

ls -a: You can see all files in the directory and directories, including hidden

ls -l: can be abbreviated to ll, you can see the detailed information of the files in the directory

Query directory:

Find directory parameters

find/root -name '*test*': Find directory files related to test under /root

Modify directory name:

 mv directory name new directory name

mv oldTest newTest: Change the name of the oldTest directory to newTest in the current directory

Note: The syntax of mv can not only rename the directory but also various files and compressed packages Perform rename operation

Move the location of the directory (cut):

 mv The new location of the directory name directory

mv newTest /usr: Move the newTest file in the current directory Cut to the usr directory

Copy directory:

cp -r directory name directory copy target location (r represents recursive copy)

cp -r /usr/newTest /test: Copy the newTest file under usr to the test directory

Note: The cp command can not only copy directories but also files and compressed packages. There is no need to write -r recursion when copying files and compressed packages

Delete directory:

rm -rf directory

rm -rf newTest/: Delete the newTest file in the current directory and all the files in it, and no need to ask


4. File operation commands

File creation

touch file name (empty file)

touch a.txt: Create a file in the current directory An empty file named a.txt

Viewing the file

Cat/more/less/tail file

Using cat can only display the content of the last screen
Use more to display the percentage, press Enter to go down a line, space to go down a page, q to exit viewing
Use less to page up and down using PgUp and PgDn on the keyboard, q to end viewing
Use the tail -f file to dynamically monitor a certain file, just like tomcat's log file. The log will change as the program runs.

Modify the content of the file

Vim file

vim startup command: vim filename Open vim and create a file named filename

File command
Open a single file vim file
Open multiple files at the same time: vim file1, file2...
Open a new file in the vim window: open file
Open the file in a new window: split file
Switch to Next file: bn
Switch to the previous file: bp
View the list of currently open files. The file currently being edited will be enclosed in []: args
Open remote files, such as ftp or share folder

  :e ftp://192.168.10.76/abc.txt
   :e \\qadrive\test\1.txt

vim mode

Normal mode (press the ESC+[ key to enter) the lower left corner displays the file or is empty
Insert mode (press the i key to enter) the lower left corner displays --INSERT--
Visual mode: the lower left corner displays - -VISUAL--

vim’s insertion command 

i: Insert
before the current position I: Insert # at the beginning of the current line ## a: Insert
after the current position A: Insert
at the end of the current line o: Insert
after the current line O: Insert

vim before the current line Search command

 /text To search for text, press n to find the next one, press N to find the previous one

 ?text To search for text, search in reverse direction, press n to find the next one, press N Key search for the previous one
   :set ignorecase Ignore the case of the search Match
:set nohlsearch to turn off highlighted search display
Search for very long words. If a word is very long and it is troublesome to type, you can move the cursor to the word and press the * or # key

That is, you can search for this word, which is equivalent to /search, and the # command is equivalent to?Search

vim’s replacement command

 

ra Replace the current character with a, the current character is the character where the cursor is
s/old/new/ Replace new with old, replace the first match of the current line
s/old/new/g Use old replaces new, replaces all matches in the current line
%s/old/new/ replaces new with old, replaces the first match in all lines
%s/old/new/g replaces new with old, replaces All matches in the entire file
 ddp swaps the line where the cursor is and the line immediately below it

vim’s move command

 h moves one character to the left
 l Move one character to the right (usually w is used instead)
, k move up one character
, j move one character down

The above four commands can be used with numbers, for example, 20j moves down 20 lines

w moves one word forward. If it reaches the end of the line, it goes to the beginning of the next line. This command block can replace the l command
b moves one word backward, 3b moves three words backward Word
 ^Move to the first non-blank character of the line
 0 (number 0) is moved to the first character of the line
 $Move to the end of the line
 GGMove to the beginning of the file
G moves to the end of the file
The f (find) command can also be used to move, fx will find the first x character after the cursor, 3fd will find the third d character
F, the same as f ,Reverse search
  :10+Enter: jump to line 10, 10G jump to line 10
 Ctrl + e scroll down one line
 Ctrl + y scroll up one line
 Ctrl + dScroll down half a screen
Ctrl + uScroll up half a screen
Ctrl + fScroll down one screen
Ctrl + bScroll up one screen

Undo and vim Redo

 u(Undo)Undo
 UUndo the operation of the entire line
 Ctrl + r Redo

vim’s delete command

x Delete the current line
3x Delete three characters from the beginning of the current cursor
# dd deletes the current line
dj deletes the previous line
dk deletes the next line
10d deletes 10 lines starting from the current line
d deletes the current character to the end of the line
d$ deletes the characters after the current All characters (this line)
kdgg deletes all lines before the current line (excluding the current line)
jdG (jd+shift+g) deletes all lines after the current line
:1,10d: delete 1 -10 lines
  :11,$d: Delete 11 lines and all following lines
  :1,$d: Delete all lines
  J: Merge two lines


vim Copy and paste

yy copies the current line nyy copies n lines starting from the current line

p Pastes after the current cursor. If the yy command was used to copy a line before, then Paste in the next line of the current line

 PPaste before the current line
   :1,10 co 20 Insert lines 1-10 into line 20
   :1,$ co $Copy the entire file copy and add to the end
 ddp exchanges the current line and the next line
xp exchanges the current character and the next character


vim's cut command

In normal mode, press v (word by word) or V (line by line) to enter visual mode, then use the jklh command to move to select certain lines or characters, and then press d to cut ndd cuts the current line For the next n lines, you can use the p command to paste the cut content

  :1,10d Cut lines 1-10, and use the p command to paste the cut content

   :1,10 m 20Move lines 1-10 to after line 20


vim exit command

 :wqSave and exit  :ZZSave and exit

:q!Force quit and ignore all changes

  :e! Discard all changes and open the original file


Vim window command

   :split or new to open A new window, with the cursor on the top-level window   :split file or :new file Open the file in a new window

The windows opened by split are all horizontal, use vsplit to open the window vertically

Ctrl + ww move Go to the next window
Ctrl + wj Move to the lower window
Ctrl + wk Move to the upper window
:close This command cannot be used on the last window to prevent accidental exit of vim
:q If is the last window to be closed, then you will exit vim


vim executes the shell command

 :!ls lists the files in the current directory :!perl - c script.pl Check the syntax of the perl script without exiting vim

   :!perl scrip.pl Execute the perl script without exiting vim

   :suspend or Ctrl + Z Suspend vim, return to the shell, press fg Return vim


vim’s comment command

Behavior comments starting with # in the perl program, so to comment some lines, just add # at the beginning of the line 3,5 s/^/#/g Comment lines 3-5

3,5 s/^/#//g Uncomment lines 3-5

1,$ s/^/#/g Comment the entire document
:%s/^/#/g Comment the entire document,


vim’s help command

  :help or F1 Display the entire help
  :help xxx Display the help of xxx
  :help 'number' The help of the vim option is enclosed in single quotes
   :help Use the help of the special key <>Expand
  :help -t vim startup parameters help -

vim other non-editing commands

 .Repeat the previous command
:set ruler? Check whether the ruler is set. In .vimrc, the options set using the set command can be viewed through this command
:scriptnames Check the location of vim script files, such as .vimrc files, grammar files and plugins, etc. .
:set list displays non-printing characters, such as tab, space, and end of line. If tab cannot be displayed, please make sure to use set
:syntax lists the defined syntax items
:syntax clear clears the defined ones Syntax rules
:syntax case match is case-sensitive, int and Int will be treated as different syntax elements
:syntax case ignore is case-independent, int and Int will be treated as the same syntax element, and use the same Color scheme

5. Operation commands for compressing files

Packed files in Linux generally end with .tar, compression commands generally end with .gz, and under normal circumstances packaging It is performed together with compression.
The suffix name of the packaged and compressed file is generally .tar.gz

tar -zcvf The name of the packaged and compressed file is to package the compressed file, z stands for gzip compression Command to compress, c represents the packaged file, v displays the running process, and f represents the specified file name
tar -zcvf xxx.tar.gz a.txt b.txt: Pack the a.txt and b.txt files in the current directory The compressed file is named xxx.tar.gz

Decompress the compressed package: tar -xvf, x represents decompression,
tar -xvf xxx.tar.gz: Name the current directory xxx.tar.gz Decompress the compressed file
tar -xvf xxx.tar.gz -C/usr, C represents the specified decompression location, this paragraph represents decompressing the file to the usr file

6. Other commands

pwd: Display the current location

The string to be searched by grep, the file to be searched for

grep to test.conf: Search for the test.conf file in the current directory Lines containing the string to

| Use the output of the previous command as the input of this directory

ps -ef | grep system: Represents at first glance all processes in the current system, including system String process

 ps -ef View the processes running in the current system

Kill -9 pid of the process Kill the process

7. Network communication command

Check the network card information of the current system: ifconfig
Check the connection status with a certain computer: ping
Check the port of the current system: netstat -an

8.linux permission command

Every file/directory has permissions. Through the ls -| command, we can check the permissions of files or directories in a directory
 rReading rights
 wWriting rights
 x Execution right
-No operation right
The first symbol: d represents directory, - represents file, | represents connection (can be considered as a shortcut in window)

chmod u=rwx,g =rw,o=r aaa.txt: means that the permission to modify the aaa.txt file in the current directory is that the owner has full permissions, the group to which it belongs has read and write permissions, and other users have read-only permissions

The above is the detailed content of Detailed explanation of some Linux commands. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template