3, Method 3, the current folder in combination with grep and xargs to process the file name: ls | Grep-v Keep | Xargs RM #删除keep文件之外的所有文件说明: LS First gets the name of all current files and folders, Grep-v Keep, the grep regular match lookup keep,-v parameter determines the result to match the results, that is, to the keep of all file names , then Xargs is used to get the parameters from the standard input and passed to the following command, where the command used is RM, and then the file selected by RM is deleted. Benefit: Using grep to match the file name with a regular expression, you can keep multiple files at a time for more accurate processing. 4, Method 4, using the Find command instead of LS, improve method 3 to be able to work with the file of the development folder: Find./test/| Grep-v Keep | Xargs rm #删除当前test文件夹中keep文件之外的所有文件说明, use grep instead of Find-name to select the name, because find is troublesome to choose the name, the regular expression support is not enough to exclude the specified file name.
RM excludes files under the specified file or specified folder