Create a test environment and create a few new files
The code is as follows |
Copy Code |
# cd/tmp # mkdir Test # CD Test # Touch a.php b.js c.css 1.png # ls 1.png a.php b.js C.css
|
Next, find the file to identify the specified suffix, in order to support multiple suffix files, found command to use a regular match
The code is as follows |
Copy Code |
# Find. -type F-regex ". *. (PHP|JS|CSS) " ./b.js ./a.php ./c.css
|
The parameters at the back of the-regex look very complicated, actually very simple, I'll explain, double quotes don't need to explain it
.*. (PHP|JS|CSS) Simplification is. *. (PHP|JS|CSS), in fact, is right. () | To do the next escape, the beginning of the. * Match any character except the line break (this regular expression should be understood)
After finding the file, how to back up the files, tar needs to specify the source file, how to get the find out of these files, and passed to tar, the role of Xargs. See what the following Xargs output is, which is what tar needs.
The code is as follows |
Copy Code |
# Find. -type F-regex ". *. (PHP|JS|CSS) "| Xargs ./b.js./a.php./c.css # Find. -type F-regex ". *. (PHP|JS|CSS) "| Xargs Tar czvf test.tar.gz ./b.js ./a.php ./c.css
|
Let's see if the file is backed up successfully.
The code is as follows |
Copy Code |
# tar TZVF test.tar.gz -rw-r--r--root/root 0 2014-03-14 10:38./b.js -rw-r--r--root/root 0 2014-03-14 10:37./a.php -rw-r--r--root/root 0 2014-03-14 10:38./c.css
|
So far, done!
The purpose of this instruction is to delete files with no suffix in the current directory.
The code is as follows |
Copy Code |
[Codesyntax lang= "bash"] Find. -type f! -name ' *.* '-print0 | xargs-0 RM [/codesyntax] |
There are many ways to achieve this in Linux, but this should be the simplest.