Basic Linux Commands

Source: Internet
Author: User
Tags create directory echo command parent directory

1 ls view file or directory
"Feature description": View files or directories
"Syntax format": ls parameter specifies a file or directory
"Option Parameters":
Parameter parameter description
-L View details of a file or directory Ls-l/root
-h Displays the file size in 1024 for the binary ls-lh/root
-T sorts by modified time, by default from near to far ls-t/root
-a displays all files/directories, including
'. ' begins with a hidden file. Ls-a/root

LS Example
[Email protected] ~]# ls/root/
Oldboy

-L argument instance
[[email protected] ~]# ls-l/root/
Total 4
Drwxr-xr-x. 3 root root 4096 June 09:44 Oldboy
-H parameter instance
[[[email protected] ~]# ls-lh/root/
Total 4.0K
Drwxr-xr-x. 3 root root 4.0K June, 09:44 Oldboy
-T parameter Instance
[[email protected] ~]# ls-t/root/oldboy/
He.txt He
[[email protected] ~]# ls/root/oldboy/
He he.txt
-a parameter
[[email protected] ~]# ls-a/root
. 1 3. bash_logout. BASHRC
.. 2. Bash_history. bas H_profile. Viminfo
2 mkdir Create directory
"feature description": Create directory
"syntax format": mkdir parameter to create directory under path
"option parameter":
Parameter Description list
-P recursive creation Mkdir-p/ROOT/1/2/3/4

mkdir
[[email protected] ~]# ls
Oldboy
[Email protected] ~]# mkdir/root/he
[[email protected] ~]# ls
He Oldboy
[Email protected] ~]# Ls/root
1
[Email protected] ~]# MKDIR/ROOT/2/ROOT/3
[[email protected] ~]# ls
[Email protected] ~]# Ls/root
1 2 3
-P Parameter Instance
[Email protected] ~]# mkdir-p/ROOT/1/2/3/4
[Email protected] ~]# Tree/root
/root
-- 1<br/>--2
-- 3<br/>--4

4 directories, 0 files
[Email protected] ~]#
Create a multi-level catalog
[Email protected] ~]# mkdir oldboy/{10086,10000}/data-p
[Email protected] ~]# tree
.
└──oldboy
├──10000
│└──data
└──10086
└──data

5 directories, 0 files
[Email protected] ~]#
3 Touch Create File
"Feature description": Create a file
"Syntax format": Create a file under the touch parameter path
"Option Parameters":
Parameter parameter description

[Email protected] ~]# Touch/root/1/he.txt
[[email protected] ~]# LS 1
2 He.txt

Touch Create multiple documents
[[email protected] ~]# ls
[Email protected] ~]# Touch/root/file{1..10}.txt
[[email protected] ~]# ls
File10.txt file2.txt file4.txt file6.txt file8.txt
File1.txt file3.txt file5.txt file7.txt file9.txt

4 awk** *
"Feature description": Awk is a powerful text analysis tool, and as with Grep's lookup, the SED editor, awk is especially powerful when it comes to analyzing data and generating reports. To put it simply, awk reads the file line-by-row, using spaces as the default delimiter to slice each row, and then perform various analytical processing of the cut.
AWK has 3 different versions: AWK, Nawk, and gawk, which are not specifically described, generally referred to as the GNU version of Awk Gawk,gawk
Awk has its name from the first letter of its founder Alfred Aho, Peter Weinberger and Brian Kernighan's surname. In fact, Awk does have its own language: The awk programming language, a three-bit creator has formally defined it as "style scanning and processing language." It allows you to create short programs that read input files, sort data, manipulate data, perform calculations on input, and generate reports, as well as countless other features.
"Syntax format":

"Option Parameters":
Parameter parameter description

Basic usage of 4.1 awk
[[email protected] ~]# Cat Install
Directoy
Install
Echo
Sysconfig
[[email protected] ~]# awk ' nr==2 '/root/install show the first few lines
Install
[[email protected] ~]# awk ' nr==2,nr==4 '/root/install] show the first few lines to the line
Install
Echo
Sysconfig

5 sed** *
"Function description": Stream editor implementation of the file to add, delete, change, replace, view
"Syntax format": Sed-n ' 2,3p '/root/skip.txt
Command parameter lines to the first line in XXX
"Option Parameters":
Parameter parameter description
-N Cancels the default output sed-n ' 3p '/root/skip.txt
-I modify the contents of a file
Sed-i ' s#find#grep#g ' before inserting text into a specified line

Function description
-N Cancels the default output sed-n ' 3p '/root/skip.txt
-I modify the contents of a file
Sed-i ' s#find#grep#g ' before inserting text into a specified line

Internal parameter description
A indicates that one or more lines of text are inserted after the selected row.
I indicates that one or more lines of text are inserted in front of the selected row.
D indicates the text "delete" of the matching line
s## #g s represents substitution, g global-----Global substitution

5.1-n parameters
[Email protected] ~]# sed-n ' 3p '/root/skip.txt
Grep
[Email protected] ~]# sed-n ' 2,3p '/root/skip.txt
Sed
Grep
5.2 Sed replacement format sed ' s## #g ' path
[Email protected] ~]# Cat/root/skip.txt
Awk
Sed
Grep
Head
Tail
[[Email protected] ~]# sed ' s#grep#find#g '/root/skip.txt-i
[Email protected] ~]# Cat/root/skip.txt
Awk
Sed
Find
Head
Tail

[[email protected] ~]# sed-n ' s#skip#oldboy#gp ' Install p indicates which line of the replacement content is displayed on the desktop
Install Oldboy Directoy
[[email protected] ~]# Cat Install
Install Skip Directoy
[Email protected] ~]#

5.3 sed does not display the selection row
[[Email protected] ~]# sed '/find/d '/root/skip.txt
Awk
Sed
Head
Tail
5.4 Adding content before/after the specified line
[email protected] ~]# seq >install.txt
[email protected] ~]# cat Install.txt
20
21st
22
23
[[email protected] ~]# sed-i ' 2a install ' Install.txt 2a means appending content after the second line
[email protected] ~]# cat Install.txt
20
21st
Install
22
23
[Email protected] ~]#

[[email protected] ~]# sed-i ' 2i install ' install.txt 2i means append to the front of the second row
[email protected] ~]# cat Install.txt
20
Install
21st
22
23
24
25
[Email protected] ~]#
5.5 The use of the SED removal feature
[[email protected] ~]# sed-i '/103/d ' install delete line containing 103 characters
[[email protected] ~]# Cat Install
100
101
102
104
105

[email protected] ~]# cat Test.txt
Test Liyao
Oldboy
Oldgir
[[Email protected] ~]# sed ' 2d ' test.txt delete second row
Test Liyao
Oldgir
[Email protected] ~]#

[[Email protected] ~]# sed ' 1,+2d ' install delete the first line of the file and the following 2 lines (1,+2d)
103
104
105
[[email protected] ~]# Cat Install
100
101
102
103
104
105
[[Email protected] ~]# sed ' 1~2d ' Install show arithmetic progression 1,3,5 line, difference to 2, their own designated
101
103
105

[[email protected] ~]# Cat Install
100
101
102
103
104
105
[[email protected] ~]# sed-i ' 2, $d ' Install delete the second line after all the contents include the second row
[[email protected] ~]# Cat Install
100
[Email protected] ~]#

[[email protected] ~]# sed-i ' i "Install does not add a specified line is treated as each line
[[email protected] ~]# cat install

100

101
102
1.1 No easy use at any time;
[[email protected]/]# cat/directory/program.txt
1
3
5
7
9
[[email protected]/]# sed-i '/5/d ' >/directory/program.txt
sed:no input files
[[email protected]/]# cat/directory/program.txt
[[email protected]/]#
6 grep * *

Function Description: Filter, find something in a file
"syntax format": Grep-v "ten"/root
Command parameters What to look for in XXX
"option parameters":
parameter description of the list
-V excludes which row is selected Grep-v "3"/R Oot/skip.txt
-A number shows which row is selected next n rows grep-a1 "3"/root/skip.txt
-B number shows which row is selected before the row of n rows grep-b1 "3"/root/skip.txt
- C number shows which row is selected before and after each n rows grep-c1 "3"/root/skip.txt
-o outputs only the contents of the matching rows grep-o "Oldboy" Test.txt
-W matches only filtered words grep-w "Oldgir" tes T.txt
-E |-e can replace the preceding slash
Color=auto the filtered string with the color
-n display matching row and line number
-I case-insensitive match
-C statistics match the number of rows grep-c "Oldboy" test. TXT
6.1-v parameter
[[email protected] ~]# grep-v "3"/root/skip.txt
1
2
4
5
6.2-a-b-c parameter
[[em Ail protected] ~]# grep-a1 "3"/root/skip.txt
3
4
[[email protected] ~]# grep-b1 "3"/root/skip.txt
2
3
[[email protected] ~]# grep-c1 "3"/root/skip.txt
2
3
4
6.3-o-w-c-i-n
[[EMAIL&NB Sp;protected] ~]# cat test.txt
Test Liyao
Oldboy
Oldgir

[[email protected] ~]# grep-o "Oldboy" test.txt only output filtered characters
Oldboy

[Email protected] ~]# grep-w "Oldgir" test.txt
Oldgir

[[email protected] ~]# grep-w "Olgir" test.txt this must be a complete word within the file

[Email protected] ~]# grep-c "Oldboy" test.txt
1
[Email protected] ~]#

[email protected] ~]# cat Test.txt
Test Liyao
Oldboy
Oldgir
[Email protected] ~]# grep-n "old" test.txt
2:oldboy
3:oldgir
[Email protected] ~]#
7 find** *
"Feature description": Find the file or directory under the directory, any string in front of the parameter, will be considered as the name of the directory you want to find. When the parameter is not set, he will look up subdirectories and files in the current directory and display all information.
"Syntax format": find/root/-type f-name "*.txt"
command XXX Find what file to find what name
"Option Parameters":
Parameter parameter description
-type type F file d directory to find
-name to find the name of the general "" in the inside enter what to look for.
-O or-name ""-o-name ""

7.1 Use Find to delete multiple files/directories,

[email protected] ~]# Touch install{1..20}.txt
[[email protected] ~]# ls
Install10.txt install15.txt install1.txt Install5.txt
Install11.txt install16.txt install20.txt Install6.txt
Install12.txt install17.txt install2.txt Install7.txt
Install13.txt install18.txt install3.txt Install8.txt
Install14.txt install19.txt install4.txt Install9.txt
[[email protected] ~]# find/root/-type f-name "*.txt" |xargs rm-f after suffix find by pipeline delete
[[email protected] ~]# ls
[Email protected] ~]#

[[email protected] ~]# Touch install{1..20}/root
[[email protected] ~]# ls
Install1 install13 install17 install20 install6
Install10 install14 install18 Install3 install7
Install11 install15 install19 Install4 Install8
install12 install16 install2 install5 install9
[[email protected] ~]# Find/-name "Inst" |xargs rm-f Delete the document/directory containing the previous content
[[email protected] ~]# ls
[Email protected] ~]#

[Email protected] ~]# find-name "Find7.txt"-o-name "Find9.txt"
./oldboy/10086/data/find9.txt
./oldboy/10086/data/find7.txt
./oldboy/10000/data/find9.txt
./oldboy/10000/data/find7.txt
[Email protected] ~]#

8 seq
"Feature description": Print numbers, loop print
"Syntax format": Seq-s "0" 3
Command parameters specify the number of separators
"Option Parameters":
Parameter parameter description
-S "" Specify delimiter seq-s "0" 3
-W outputs the same number of digits as the longest one for the template. Seq-w 10
-F "find%2g"% followed by the maximum number of digits is displayed as a space. Seq-f "FIND%2G" 10

8.1-s parameters
[[email protected] ~]# seq-s "0" 5
102030405

8.2-W parameter-w-s combined use
[[email protected] ~]# seq-w 10 with the largest template not enough to supplement with 0
01
02
03
04
05
06
07
08
09
10

[[email protected] ~]# seq-ws "" 10 Specify the split symbol
01 02 03 04 05 06 07 08 09 10

Several usages of 8.3 seq
[[email protected] ~]# seq 3 "Starting from 1 default growth is 1"
1
2
3
[[email protected] ~]# SEQ 3 5 "Starting from 3 default growth of 1"
3
4
5
[[email protected] ~]# seq 1 3 10 "growth from 1 to 3"
1
4
7
10

9 Head
"Feature description": The header displays the first few lines of the file, and the first 10 lines of the file are displayed by default.
"Syntax format": Head-n2 Oldboy
Command parameter file name
"Option Parameters":
Parameter parameter description
-N Displays the first few lines of the file by default display the first 10 lines of the file "n can omit the direct plus-number" head-n2 Oldboy

-N Parameter
[Email protected] ~]# head-2 Oldboy
Awk
Find

Head Connect pipe cat Display
[Email protected] ~]# head-3 Oldboy | Cat-n
1 awk
2 Find
3 grep
[Email protected] ~]# Cat-n Oldboy | Head-3
1 awk
2 Find
3 grep

Ten tail Tails
Feature Description: Displays the next few lines of the file, displaying 10 rows by default.
"Syntax format":
"Option Parameters":
Parameter parameter description
-N followed by a number to display the file's next n rows, n can omit direct-to-digital tail-n3 Oldboy
-c The number of n bytes that begin at the end of a digital output file. Tail-c Oldboy

Tail usage
[Email protected] ~]# Tail-2 Oldboy
Sed
Echo
[Email protected] ~]# Tail-2 Oldboy | Cat-n
1 sed
2 Echo
[Email protected] ~]# Cat-n Oldboy | Tail-2
6 sed
7 Echo
-C parameter
[Email protected] ~]# tail-c Oldboy

Sed
Echo
Cat
"Feature description": Displays the contents of a file
"Syntax format":
"Option Parameters":
Parameter parameter description
-N with line number display Cat-n Oldboy
-B is displayed with line numbers, and blank lines do not label line numbers. Cat-b Oldboy
-S when a blank line that encounters 2 rows or more is merged into 1 rows. Cat-s Oldboy

Cat-n-b-s parameter
[Email protected] ~]# cat-n Oldboy
1 head-n
2 Tail-n-C
3
4
5 dirctory
[Email protected] ~]# Cat-b Oldboy
1 head-n
2 Tail-n-C

 3  

[Email protected] ~]# CAT-SB Oldboy
1 head-n
2 Tail-n-C

 3  dirctory

Echo
"Feature description": outputs the specified string or variable
"Syntax format": echo "File" >>oldboy
Command output Write Address
"Option Parameters":
Parameter parameter description
-N No newline input echo-n "Oldger"; echo "Oldboy"
-E Use tab Echo-ne "Oldger\t"; echo "Oldboy"
Echo Echo {A.. Z} generate a-to-Z sequence to screen

echo Command App
[[email protected] ~]# echo "Oldgre" >> Oldboy to append the content to the end of the file
[email protected] ~]# cat Oldboy
Head-n
Tail-n-C
Dirctory
Oldgre
[[email protected] ~]# echo "man" > Oldboy overwrite the contents of the source file
[email protected] ~]# cat Oldboy
Mans
[[email protected] ~]# echo "Oldger" Display to desktop
Oldger
[Email protected] ~]#
-N-E parameters
[Email protected] ~]# echo-n "Oldger"; echo "Oldboy"
Oldgeroldboy
[Email protected] ~]# echo-ne "oldger\t"; echo "Oldboy" "\ t is tab"
Oldger Oldboy

Write multiple lines of text with Echo
[[email protected] ~]# Touch Install
[[email protected] ~]# ls
Install
[Email protected] ~]# echo "Directoy

Install
Echo
Sysconfig ">>install
[[email protected] ~]# Cat Install
Directoy
Install
Echo
Sysconfig
[Email protected] ~]#
Echo Generation sequence
[[email protected] ~]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
[Email protected] ~]# echo {A.. J
A b c d e F g h i J
[Email protected] ~]#

cd
"Function description": Enter the Directory
"Syntax format": Cd/root
Where to enter the order
"Option Parameters":
Parameter parameter description
Cd. Switch to current directory, equivalent to not moving
Cd.. Switch to the parent directory of the current directory
Cd.. /.. Return to the top level two directory, and so on
CD ~ Go to User home directory
CD-Return to the directory you just located

RM Delete files/directories
"Feature description": Delete a file or directory
"Syntax format": Rm-f/root/oldboy
What the command parameters want to delete
"Option Parameters":
Parameter parameter description
-F Force deletion of documents (without prompting)
-R Delete Directory
-FR forcibly deleting a directory

RM usage
[[email protected] ~]# ls
Cat Find SED
[[email protected] ~]# rm/root/ -rf All files/directories under the root directory, but not including
[[email protected] ~]# ls-a hidden files/directories
. . bash_history. Bash_profile. Viminfo
.. . bash_logout. BASHRC

MV Cut
"Feature description": Used to cut directories or rename files/directories
"Syntax format":
"Option Parameters":
Parameter parameter description

[Email protected]/]# Mv/data/root
[Email protected]/]# Ls/root
Data test.txt
[Email protected]/]# ls/root/data/
He oldboy1.txt Oldboy.txt
[Email protected]/]#
PWD Displays the current location
"Function description":
"Syntax format":
"Option Parameters":
Parameter parameter description

[Email protected]/]# cd/root/data/he/
[Email protected] he]# pwd
/root/data/he "= = = Current Working path
[Email protected] he]#

Xargs
"Feature description": Grouping
"Syntax format":
"Option Parameters":
Parameter parameter description

Group
[email protected] ~]# cat M.txt
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
[Email protected] ~]# Xargs-n5 < M.txt
01 02 03) 04 05
06 07 08) 09 10
11 12 13) 14 15
16 17 18) 19 20
[Email protected] ~]#

VI Vim Edit Text
"Feature description": Tools for editing text in Linux
"Syntax format":
"Option Parameters":
Parameter parameter description
I enter edit mode
: Wq Save and exit
ESC Key to exit
: Q Exit does not save
: q! Force quit does not save
-O Edit Multiple text

CP Copy
"Feature description": Copies files or directories, copying files by default.
"Syntax format":
"Option Parameters":
Parameter parameter description

[Email protected] he]# ls/root/data/
He oldboy1.txt Oldboy.txt
[Email protected] he]# cp/root/data/oldboy.txt.
Cp:overwrite './oldboy.txt '? Y
[[email protected] he]# \cp/root/data/oldboy.txt./Do not prompt for coverage method use with caution
[Email protected] he]#/bin/cp/root/data/oldboy.txt.
[Email protected] he]#

    1. History view commands that have been used

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.