Linux is the file with the specified file name in the Tar backup folder

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.