Linux Tutorials (14) - Find and Replace in Linux
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
in the back row the second add this line 123456
was added 123 456 before the last line of the file
in the file of all replaced dog cat
If you want to make changes to the original file, use the -i option (caution)
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
Find all been changed three days before the files in the directory / var
Find files larger than 5M in the / var directory
More info larger than 2M files in / var directory