Shell file lookup and compression commands

Source: Internet
Author: User

Locate command

1.locate filename
Fuzzy match as long as the file name contains the keyword can be
Non-real-time lookup, faster than find.
Rely on index database/var/lib/mlocate/mlocate.db
Automatically run once a day to update the database.
UpdateDB Updating the index database
2. Suitable for searching for files with less frequent changes. The resource consumption of the system is small.

3. Example

1. Locate-r "^/etc/.*\.conf$"

Find command

Real-time Find tool to complete file lookups by traversing a specified path

The name of the file to be found must be filename and not include filename

Find/-name "*filename" Fuzzy match lookup

Instance:

1.find/etc-maxdepth 3-mindepth 1-name passwd

2.find-samefile file to find hard-link files

3.find/etc-regex ". *\.conf$" Regular Expression lookup

4.find/etc "*.sh" wildcard find Find/etc-name "*.sh"-ls

5. Find/etc-iname sos.conf

6.find/data-size 1024c Find File Size range in (1023,1024] 1023 is an open interval that does not contain a 1023,1024 is a closed interval that contains 1024. Overall representation is greater than 1023 is less than or equal to 1024 bytes

7.find/data-size 1k Find File size range in (1-1,1] This range, the Find file size is greater than 0k, less than or equal to 1k of all files.

8.find/data-size-1024 find the file size range for all files in [0,1024-1]

9.find/data-size +1023 means (1023, Infinity] file does not contain 1023

Ten. Find/mnt-size +10m-exec mv {}/data/\;   Locate files larger than 10M in the MNT directory and move to the/data directory. {} Indicates the file name that was searched for itself

Xargs command

By default, the output information of the preceding command is separated by a space, but you can add options to use a specific symbol instead of a space symbol

Sometimes the output information separated by a space can not achieve the corresponding effect

Echo f{1..10} | Xargs-n2 echo-n to split the output information of the preceding command with a space carriage return character

Compression and packaging

1. Compression can only compress a single file, if you need to compress multiple files at the same time, you must first package and then compress

2.tar can package a directory into a file, and then compress the packaged file using the Compress command

3. Create an archive file

TAR-CPVF Data.tar/data

4. View all files under the archive tar package

Tar TVF Data.tar

5. Unzip the tar package file

Tar xvf Data.tar

6. Package and compress at the same time

TAR-ZCPVF Data.tar.gz/data

Tar xvf data.tar.gz

7. Cutting and merging compressed files

Split-b 10m-d data.tar.xz A.tar cut the DATA.TAR.XZ compression packet into 10M a package

Cat a.tar0* > Newdata.tar.xz merge the segmented files into a single compressed package

Shell file lookup and compression commands

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.