The Three Musketeers and common commands of Linux

Source: Internet
Author: User

Symbols to keep in mind:

>
2>>
2>&1

6.1 Move the/data to the/root directory
#move MV

[Email protected] ~]# mv/data//root/
[Email protected] ~]# ls-l/data
Ls:cannot access/data:no such file or directory
[Email protected] ~]# ls-l/root/
Total 44
-RW-------. 1 root root 1124 Jul 18:25 anaconda-ks.cfg
Drwxr-xr-x. 2 root root 4096 Jul 02:13 data
-rw-r--r--. 1 root root 21736 Jul 18:25 Install.log
-rw-r--r--. 1 root root 5890 Jul 18:24 install.log.syslog

6.2 "Piping Concept" Enter the data directory under the/root directory to delete the Oldboy.txt file

Instance 6-1 #如何备份?
[[email protected] ~]# cd/root/data/
[[email protected] data]# pwd
/root/data
[[email  Protected] data]# ls-l
Total
-rw-r--r--. 1 root root 7 Jul 02:13 alex.txt
-rw-r--r--. 1 root root Jul 1 1 01:16 lidao.txt
-rw-r--r--. 1 root root 254 Jul 01:08 oldboy.txt
[[email protected] data]# CP oldboy.txt O Ldboy.txt.bak
[[email protected] data]# ls-l
Total
-rw-r--r--. 1 root root 7 Jul 02:13 alex.txt
-R W-r--r--. 1 root root 01:16 lidao.txt
-rw-r--r--. 1 root root 254 Jul 01:08 oldboy.txt
-rw-r--r--. 1 root root 25 4 Jul 02:56 Oldboy.txt.bak

. bak = = = Backup
Instance 6-2 #修改文件名 renaming
[Email protected] data]# MV Oldboy.txt oldgirl.txt
[Email protected] data]# ls-l
Total 16
-rw-r--r--. 1 root root 7 Jul 02:13 alex.txt
-rw-r--r--. 1 root root 01:16 lidao.txt
-rw-r--r--. 1 root root 254 Jul 02:56 Oldboy.txt.bak
-rw-r--r--. 1 root root 254 Jul 01:08 oldgirl.txt

6.3 #强制删除
[Email protected] data]# rm-f/root/data/oldgirl.txt
[Email protected] data]# ls-l/root/data/
Total 12
-rw-r--r--. 1 root root 7 Jul 02:13 alex.txt
-rw-r--r--. 1 root root 01:16 lidao.txt
-rw-r--r--. 1 root root 254 Jul 02:56 Oldboy.txt.bak

6.4 #强制删除目录
[Email protected] data]# rm-rf/tmp/data/
[Email protected] data]# ls-l/tmp/data
Ls:cannot access/tmp/data:no such file or directory

rm-rf/tmp/data/
rm-fr/tmp/data/

6.5 #怎么样防止 mistakenly deleted

#创建环境

Touch/root/oldboy.txt/root/alex.txt/root/lidao.txt

6.6 #find命令
[[email protected] data]# #find in xxx-type F-Name "Oldboy.txt"
[Email protected] data]#
[Email protected] data]# find/root/-type f-name "Oldboy.txt"
/root/oldboy.txt

-type what type of f file (file) to find
d Directory (directory)
-name "What's the name?"

#喜欢送/root files ending in. txt
Oldboy.txt Lidao.txt Alex.txt
6.7 Fuzzy Lookup
[Email protected] data]# find/root/-type f-name ".txt"
/root/oldboy.txt
/root/lidao.txt
/root/alex.txt
/root/data/lidao.txt
/root/data/alex.txt
[[Email protected] data]# #
Any character of any character

[Email protected] data]# find/root/-type f-name ".txt"
/root/oldboy.txt
/root/lidao.txt
/root/alex.txt
/root/data/lidao.txt
/root/data/alex.txt
6.8 Piping
[Email protected] data]# find/root/-type f-name "
. txt" |xargs ls-l
-rw-r--r--. 1 root root 0 Jul 03:21/root/alex.txt
-rw-r--r--. 1 root root 7 Jul 02:13/root/data/alex.txt
-rw-r--r--. 1 root root 01:16/root/data/lidao.txt
-rw-r--r--. 1 root root 0 Jul 03:21/root/lidao.txt
-rw-r--r--. 1 root root 0 Jul 03:21/root/oldboy.txt

Find +|xargs Mates
| different from |xargs
Old boy Education Daily-May 18, 2017-Talk | The difference between (piping) and |xargs (pipe Xargs)
http://blog.51cto.com/lidao/1927347

#7 Answer question 6th, exit to the previous level directory to delete the data directory. (originally in/root/data)
Cd.. Go to the top level directory of the current directory
Cd. Go to current directory
#移动xxxxx文件 to the current directory
#复制xxxxx文件 to the current directory
[Email protected] tmp]# cp/root/oldboy.txt.
Cp:overwrite './oldboy.txt '? Y
[Email protected] tmp]# ls-l
Total 4
-rw-r--r--. 1 root root 17:01 oldboy.txt
-RW-------. 1 root root 0 Jul 16:19 yum.log

6.9 Entering the current directory

[Email protected]/]# cd/root/data/
[Email protected] data]# pwd
/root/data
[Email protected] data]# cp/root/oldboy.txt.

4.8 Known files test.txt content
Test
Lidao
Oldboy
To create a test file:
Mkdir-p/data
Cat >/data/test.txt<<eof
Test
Liyao
Oldboy
Eof
6.10 Please give the command that does not contain the Oldboy string when outputting the contents of the Test.txt file.

Example 6-3 method 1-grep
[[email protected] data]# #grep filter to show what you want or not
[[email protected] data]# grep "Oldboy"/data/test.txt
Oldboy
[Email protected] data]# grep-v "Oldboy"/data/test.txt
Test
Liyao

Method 2-head
[Email protected] data]# Head-n2/data/test.txt
Test
Liyao
[Email protected] data]# head-2/data/test.txt
Test
Liyao

#head shows the first few lines of the file display the first 10 rows by default
#tail display the last few lines of the file display the last 10 lines by default

6.11 #显示文件最后一行
[Email protected] data]# tail-1/data/test.txt
Oldboy

Instance 6-4 #方法3 awk
[Email protected] data]# #awk
[Email protected] data]# #gawk
[Email protected] data]# awk '/oldboy/'/data/test.txt
Oldboy
[Email protected] data]# awk '!/oldboy/'/data/test.txt
Test
Liyao

Example 6-5 #方法4 sed
[[Email protected] data]# sed '/oldboy/d '/data/test.txt
Test
Liyao
[Email protected] data]# #delete

Summary:
1.grep Filtration
2.head Tail
3.sed awk (Learn)

6.12 #9 Use a command to complete the creation of the directory/oldboy/test, which is to create/oldboy directory and/oldboy/test

[Email protected] data]# mkdir-p/oldboy/test
[Email protected] data]# ls/oldboy/
Test
#-p creating a multi-level catalog

6.13 #11 View only the contents of rows 20th through 30th in the Ett.txt file (total 100 lines)

[[email protected] data]# SEQ 10
1
2
3
4
5
6
7
8
9
10

SEQ->/data/ett.txt

Example 6-6 #方法1 head + tail
[Email protected] data]# Head-30/data/ett.txt |tail
21st
22
23
24
25
26
27
28
29
30
[Email protected] data]# Head-30/data/ett.txt |tail-11
20
21st
22
23
24
25
26
27
28
29
30

6.14 #显示文件的第30到40行
Key commands:
(1). Head-40/data/ett.txt |tail-11
(2). Tail-11/data/ett.txt

Instance 6-7 #方法2 sed fetch line
[Email protected] data]# sed-n ' 3p '/data/ett.txt
3
#-n Cancel default output (SED command does not display the contents of the file)
[Email protected] data]# sed-n ' 3p '/data/ett.txt
3
#print (meaning shown)
[Email protected] data]# sed-n ' 20p '/data/ett.txt
20

6.15 take 20 lines to 30 rows
[Email protected] data]# sed-n ' 20,30p '/data/ett.txt
20
21st
22
23
24
25
26
27
28
29
30

Instance 6-8 #方法3 awk
[Email protected] data]# awk ' nr==3 '/data/ett.txt
3
[[Email protected] data]# # ' nr line number equals 3 '
[Email protected] data]# awk ' nr==20,nr==30 '/data/ett.txt
20
21st
22
23
24
25
26
27
28
29
30

Mv
[Email protected] ~]# MV Oldboy.txt oldgirl.txt
[Email protected] ~]# ls-l
Total 44
-RW-------. 1 root root 1133 Jul 16:23 anaconda-ks.cfg
-rw-r--r--. 1 root root 21736 Jul 16:23 Install.log
-rw-r--r--. 1 root root 5890 Jul 16:22 install.log.syslog
-rw-r--r--. 1 root root 15:29 oldgirl.txt

6.16 How do I back up?
CD Backup

6.17 RM Delete File
Rm-f forcing files to be deleted
Rm–r Deleting a directory
RM–RF forcibly deleting a directory
RM–FR forcibly deleting a directory

Attention
[Email protected] data]# # "": "".
[[Email protected] data]# # "": <<>>.

6.18 How to prevent accidental deletion
Create an environment
Find Lookup
[Email protected] ~]# find/root/-type f-name "Oldboy.txt"
/root/oldboy.txt
[Email protected] ~]#
Find Fuzzy Lookup
[Email protected] ~]# find/root/-type f-name ".txt"
/root/oldboy.txt
/root/oldgirl.txt
What type of-type to look for
F Fire (file)
d Directory (directory)
-name (first name)
6.19 Pipe (Prevent accidental deletion)
[Email protected] ~]# find/root/-type f-name "
. txt" |xargs ls-l
-rw-r--r--. 1 root root 0 Jul 15:56/root/oldboy.txt
-rw-r--r--. 1 root root 15:29/root/oldgirl.txt

6.20 Summary:
1.head+tail
2.sed
3.awk

6.21 Summary:
1. Simple commands
2.find +|xargs
3. Three Musketeers grep sed (filter fetch line) awk take the line sed replace

6.22 Preview:
1.sed replacement
2. Setting aliases
Linux Basic optimization:
1. Add Users
2. Robbery color (iptables selinux) off
3. How to modify the system's character set

The Three Musketeers and common commands of Linux

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.