Basic Linux Commands

Source: Internet
Author: User

Directory Structure of 1.linux

Bin: (binaries) storing binary executable files
Sbin (Super User binaries) store binary executable file
ETC: (etcetera) storage System configuration file
USR (Unix shared resources) is used to store shared system resources
Home Store The root directory of user files
Root Super User Directory
Dev (devices) storage device files
Lib (library) stores the shared libraries and kernel modules needed to run the program in the file system
MNT (Mount) system administrator installs the temporary file system installation point
Boot holds various files used for system boot
TMP (temporary) for storing various temporary files
VAR (variable) is used to store files that need to change data at run time

2. Switch Directory command CD

CD test switch to the test directory
Cd.. Switch to Parent directory
CD/Switch to System and directory
CD ~ Switch to user home directory
CD-Switch to the previous directory

3. Order of operation of the catalogue (add and revise)

Add Directory:

mkdir Directory Name

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

View Catalog:

Ls

LS: all directories and files in the current directory

LS-A: You can see all the files and directories in this directory, including hidden

Ls-l: Can be abbreviated to LL, you can see the details of the file under this directory

Query directory:

Find Directory Parameters

Find/root-name ' *test* ': Find the test-related directory file 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 the MV can be renamed not only to directories but also to various files, compressed packages

Move directory location (cut):

The new location of the MV Directory name directory

MV Newtest/usr: Cut the Newtest file in the current directory into the USR directory

Copy directory:

Cp-r Directory name directory copy target location (R for 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 copy files and compress packages. copy files and compress packages without writing-R recursion

To delete a directory:

RM-RF Directory

RM-RF newtest/: Delete the Newtest file in the current directory and all the files in it, and do not need to ask


4. Operation commands for files

Creation of files

Touch file name (empty piece)

Touch a.txt: Create an empty file named A.txt in the current directory

View of the file

Cat/more/less/tail file

Use cat to display only the last screen of content
Use more to display percentages, the carriage return can be one line down, the space can be a page down, Q can exit view
Use less to page up and down using the PgUp and PgDn on the keyboard, q to end the view
A file can be dynamically monitored using the tail-f file, like a tomcat log file that changes as the program runs.

Modify the contents of a file

Vim file

Vim's start command: Vim filename opens vim and creates a file named filename

File commands
Opening a single file Vim file
Open multiple files at the same time: Vim file1,file2 ...
Opening a new file in the Vim window: Open file
Open files in a new window: Split file
Switch to the next file: Bn
Switch to previous file: BP
View the list of currently open files, and the file currently being edited is 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's mode

Normal mode (press esc+[key to enter) the lower left corner shows the file or empty
Insert mode (press the I key to enter) the lower left corner shows--insert--
Visual mode: The lower left corner shows--visual--

VIM's Insert command 

I: Insert before current position
I: Inserting at the beginning of the current line
A: Insert after current position
A: Insert at the end of the current line
O: Insert after the current line
O: Inserted before the current line

Vim's Find command

/text find text, press N to find the next, press N to find the previous
? text find text, reverse lookup, press N to find Next, press N to find the previous
: Set ignorecase ignores case-finding
: Set noignorecase does not ignore case-finding
: Set Hlsearch Highlight search results, all results are highlighted instead of just one match
: Set Nohlsearch Close Highlight search display
Look for long words, if a word is long, type in trouble, you can move the cursor over the word, press the * or the # key

that word can be searched, equivalent to/search, and # command equivalent? search

Vim's replacement command

  

RA replaces the current character with a, the current character is the character of the cursor
s/old/new/replace new with old, replacing the first match of the current row
s/old/new/g replace new with old, replacing all occurrences of the current row
%s/old/new/replace new with old, replacing the first match of all rows
%s/old/new/g replace new with old, replacing all occurrences of the entire file
DDP swaps the line that the cursor is in and immediately below it

Vim's Move command

H move one character to the left
L Move one character to the right (usually w instead)
K Move up one character
J Move down one character

The above four commands can be used in conjunction with the number, such as 20J is moving down 20 lines

W move forward one word, if it has reached the end of the line, then go to the beginning of the next line, this command block, can replace the l command
b Move backward One word, 3b move backwards three words
^ Move to the first non-whitespace character of the bank
0 (number 0) move to the first character of the bank
$ move to end of line
GG Move to file header
G Move to end of file
The f (find) command can also be used to move, FX will find the character of the first x after the cursor, and 3FD will find a third character of D
F, same as F, reverse lookup
: The jump to 10 lines, 10G jump to 10 lines
Ctrl + E scrolls down one line
Ctrl + y scrolls up one line
Ctrl + D scroll down half screen
Ctrl + u scroll up half screen
Ctrl + F scroll down one screen
Ctrl + B scrolls up one screen

Vim Undo and Redo

U (undo) Undo
U undo an entire line operation
Ctrl + R Redo

Vim's Delete command

X Delete When moving forward
3x Delete current cursor start backward three characters
x Delete the previous character of the current character
DL deletes the current character
DH Deletes the current one character
DD Delete When moving forward
DJ Delete Previous Line
DK Delete Next Line
10d Delete 10 rows from the beginning of the current line
D Delete the current character to the end of the line
d$ Delete all characters after the current character (bank)
KDGG all rows before the current row is deleted (excluding the current row)
JdG (jd+shift+g) deletes all rows after the current line
: 1,10d: Delete 1-10 rows
: One, $d: Delete 11 rows and all subsequent rows
: 1, $d: Delete all rows
J: Merge two lines

Vim's copy and paste

YY copy when moving forward
NYY copy n rows starting at the current line
P Paste after the current cursor, if you have previously used the YY command to copy a row, paste it on the next line of the current row
P Paste before the current line
: 1,10 Co 20 inserts 1-10 rows into line 20th
: 1,$ Co $ copies the entire file and adds it to the end
DDP swaps the current row and its next row
XP swaps the current character and a subsequent character

Vim's Cut command

In normal mode, press V (verbatim) or V (Progressive) to enter the visual mode, then move with the JKLH command to select some lines or characters, then press D to cut
NDD cuts the n rows after the current row, using the P command to paste the clipped content
: 1,10d cuts 1-10 rows and uses the P command to paste the clipped content
: 1,10 m 20 after moving the 第1-10 line to 20 rows

VIM Exit command

: Wq Save and exit
: ZZ Save and exit
: q! force exit and ignore all changes
: e! Discard all changes and open the original file

Vim's window commands

: Split or new opens a new window with the cursor on the top-level window
: Split file or: New to open the files in a fresh window
Split open windows are horizontal, using Vsplit to open the window vertically
Ctrl + WW moves to the next window
Ctrl + WJ Move to the window below
Ctrl + wk Move to the top window
: Close last window cannot use this command to prevent accidental exit of vim
: Q If it is the last window to be closed, then the vim will be exited

Vim Execution Shell command

:!ls lists the files in the current directory
:!perl-c script.pl Check perl script syntax, you can not quit VIM
:!perl scrip.pl executes perl script without exiting vim
: Suspend or CTRL + Z hangs vim, returns to Shell, and press FG to return vim

Vim's annotation commands

In the Perl program, the # starts the behavior comment, so to comment on some lines, just add # at the beginning of the line
3,5 s/^/#/g Comment 第3-5 line
3,5 s/^/#//g dismiss 3-5 lines of comment
1,$ s/^/#/g Comment Entire document
:%s/^/#/g notes the entire document,

Vim's help command

: Help or F1 show the whole aid
: Help xxx display XXX helps
: Help ' number ' vim option is enclosed in single quotes
:help<esc> Special keys help with <> amplification
: Help-tvim for help with startup Parameters-

Vim other non-edit commands

. Repeat the previous command
: Set ruler? To see if ruler is set, in. VIMRC, the options set with the SET command can be viewed with this command
: Scriptnames View the location of Vim script files, such as. vimrc files, grammar files, and plugin.
: Set list displays nonprinting characters, such as tab, space, end of line, if tab cannot be displayed, make sure to use Set
: syntax lists syntax items that have already been defined
: syntax clear clears the defined grammar rules
: syntax case match casing sensitive, int and int will be treated as different syntax elements
: syntax case ignore uppercase and lowercase, int and int will be treated as the same syntax element and use the same color scheme

5. Action commands for suppressing files

Packaged files in Linux generally end in. tar, and compressed commands generally end in. gz, and in general packaging and compression are done together,
The suffix name of the file that is packaged and compressed is generally. tar.gz

TAR-ZCVF Packaging compressed file names to package compressed files, Z for compression with the gzip compression command, C for packaging files, v to display the running process, F for the specified file name
TAR-ZCVF xxx.tar.gz a.txt b.txt: Packaging a.txt and B.txt files in the current directory fame for xxx.tar.gz compressed files

Decompression Package: TAR-XVF,X Representative decompression,
TAR-XVF xxx.tar.gz: Unzip the compressed file named Xxx.tar.gz in the current directory
TAR-XVF Xxx.tar.gz-c/usr,c represents the location of the specified decompression, which is a representation of the file being extracted to the USR file

6. Other commands

PWD: Show Current Location

grep to search for the string, the file to search for

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

| Enter the output of the previous command as the current directory

Ps-ef | grep system: Represents a process that, at first glance, includes the system string in all processes in the current system

PS-EF viewing the processes running in the current system

PID kill process for kill-9 process

7. Network Communication commands

View network card information for the current system: ifconfig
To view a connection to a computer: Ping
To view the port usage of the current system: Netstat-an

Permissions command for 8.linux

Each file/directory and so on have permissions, through the LS-| command we can view the file or directory under a directory permissions
R Read Right
W Write Right
X Executive Right
-No operational rights
First symbol: D stands for directory,-represents a file, | represents a connection (can be considered a shortcut in window)

chmod u=rwx,g=rw,o=r Aaa.txt: Represents the permission to modify the Aaa.txt file in the current directory is the owner of all rights, the group is located in groups with read and write permissions, other users are read-only

Basic Linux Commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.