[Reprint] Linux Tutorials (14) - Find and Replace in Linux

Linux Tutorials (14) - Find and Replace in Linux

Disclaimer: This article is a blogger original article, follow the  CC 4.0 BY-SA  copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_42350428/article/details/81937303

Find and replace 
grep can only be used to find the file contents in the 
content sed can find and replace, or insert the desired

a: new, can take back a string, and those strings come (now the next line) on a new line; 
d: deleted, because it is deleted ah, so the back d usually do not take anything; 
i : insert, i can take back the string, and those strings come (on the current line) in a new line; 
the p-: print, that will print a selection of information. P parameters will usually sed 
S: replace, the work can be substituted directly!

Example 
Delete / tmp / abc contents of the first file line 2-5 
Write pictures described here 
in the back row the second add this line 123456 
Write pictures described here 
was added 123 456 before the last line of the file 
Write pictures described here 
in the file of all replaced dog cat 
Write pictures described here

If you want to make changes to the original file, use the -i option (caution) 
Write pictures described here

The find Linux 
needs: 
to find to find files larger than 5M under / var directory, and copy them to / tmp / lewisfile directory

Usage: find [path] [command parameter] [expression] 
parameters: 
-name "filename": to find the specified file name; 
-user username: Find files owned by the user specified; 
-group Group name: to find the specified group has file; 
-mtime n-: Find the modified file in N days; 
-atime n-: lookup file is accessed in N days; 
demand: 
find find in / var files larger than 5M, and copy them to / tmp / lewisfile directory

Usage: find [path] [command parameter] [Expression] 
Parameters: 
-type D / F / B / L / P: to find the specified file type; 
-empty: Find empty files; 
-size: Find size by volume ; 
-perm the MODE: to find the specified file attributes; 
-exec the command {} \ ;: find the specified file and executes the specified command; 
-newer file name: Finding newer than the specified file

Find all three days were modified files in the directory / var 
Write pictures described here

Find all been changed three days before the files in the directory / var 
Write pictures described here

Find files larger than 5M in the / var directory 
Write pictures described here

More info larger than 2M files in / var directory 
Write pictures described here 
Write pictures described here

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11857955.html