1. Find usage
" Text.txt "/tmp/text.txt/root/text.txt
#找到文件后, give it to the pipe to delete
[Email protected] tmp]# Find/-type f-name "Text.txt" | Xargs rm-f
Interview title: Delete all files in a directory, but keep a specified file (keep File10)
[email protected] tmp]# Touch file{1.. 10}[[email protected] tmp]# ll total dosage0-rw-r--r--1Root root0May - Ten: thefile1-rw-r--r--1Root root0May - Ten: OneFile10-rw-r--r--1Root root0May - Ten: thefile2-rw-r--r--1Root root0May - Ten: theFile3-rw-r--r--1Root root0May - Ten: thefile4-rw-r--r--1Root root0May - Ten: theFile5-rw-r--r--1Root root0May - Ten: theFile6-rw-r--r--1Root root0May - Ten: theFile7-rw-r--r--1Root root0May - Ten: theFile8-rw-r--r--1Root root0May - Ten: thefile9# Method One: [[email protected] tmp]# Find/tmp-type f! -name"File10"|xargs RM-F Method Two: [[email protected] tmp]# Find/tmp-type f! -name"File10"-exec rm-f {} \;
#find找到的内容,-exec is a parameter, {}: The target to look for, you can generally do not write \: Backslash escape character
! The effect is: take the reverse
2, RM remove delete files or directories
-F Mandatory
-R Delete Directory
Note: The production scenario should not use RM, if not to use, must first CP backup
0 1 0 May : 0
3. Echo Usage
Print out content, with "> or >>" to overwrite and append content to the file
">" means redirect, which clears all previous data in the file.
">>" For additional content
4. Cat View File contents
Special usage: Add multiple lines of content
[email protected] tmp]# cat >>/tmp/nulige.txt <<EOF> I am studying Linux. >41 root root 0 May : File10 1 May : nulige.txt[[email protected ] tmp]# Cat Nulige.txt I am studying Linux.
5. CP command
Grammar:
CP source file directory file (cp parameter Apr)
Parameters:
-A: equivalent to-PDR
-D: If the source file is a linked file, the link file property is copied instead of the file itself
-F: Mandatory, the right directory file already exists and cannot be opened, then try again after removing
-I: If the target file already exists, the overwrite will be asked first
-P: Copy the past together with the attributes of the archive, not the default properties
-R: Recursive for copying directories
-U: If the destination file exists, the destination file is copied before the source file
Tip: If the source file is multiple, then the destination file is at the end, and the directory
6.
Linux Common commands