compress file using /bin/gzip with particular patterns

KrunalParmar

I want to compress files individually with the particular pattern. For example, I have directory as below :

/log/log1
    -/1/log2/file.1
    -/1/log2/file123
    -/1/log2/file2.1
/log/log2
    -/2/log2/file4.1
    -/2/log2/file345
    -/2/log2/file3.1

I want to compress all the files having extension .1 inside /log recursively.

The result will look like

/log/log1
    -/1/log2/file.gz
    -/1/log2/file123
    -/1/log2/file2.gz
/log/log2
    -/2/log2/file4.gz
    -/2/log2/file345
    -/2/log2/file3.gz
RomanPerekhrest

find + bash solution:

find /log -type f -name "*.1" -exec bash -c 'gzip -nc "$1" > "${1:0:-2}.gz"; rm "$1"' _ {} \;

gzip options:

  • -n - when compressing, do not save the original file name and time stamp by default
  • -c - write output on standard output; keep original files unchanged

${1:0:-2} - bash's slicing; get filepath with the last 2 characters truncated

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to compress a YAML file using references in a script?

分類Dev

how to overwrite a particular data in file using c++

分類Dev

Compress a bitstring using Ruby

分類Dev

Using java regex read a text file to match multiple patterns

分類Dev

Process non common csv file with awk using field patterns

分類Dev

File input to a particular field

分類Dev

Replacing patterns using sed

分類Dev

Reading a particular word in .txt file

分類Dev

How to compress a string using GZip or similar in Dart?

分類Dev

Using Gzip to compress/decompress an array of bytes

分類Dev

Python How to replace a particular word in a particular line in a text file?

分類Dev

using prinf function for repeated patterns

分類Dev

dynamically Accessing of particular label in text file and get elements under it and again start with next word and get elements under it using python

分類Dev

Perl: Exit if a particular line is not present in a file

分類Dev

Exclude directories in .gitignore which contain a particular file

分類Dev

Reading a file and output in a particular format in Perl

分類Dev

Extracting a particular value from a JSON file

分類Dev

How to use exclude-patterns from a file

分類Dev

movie ticket booking in a particular row using array

分類Dev

Mysql: Set particular value of column using update

分類Dev

Dividing columns by particular values using dplyr

分類Dev

Unable to get particular db value using $project

分類Dev

How to call a particular screen in Tkinter using OOP

分類Dev

How to compress the image size using C# Dot Net Core

分類Dev

How to compress / decompress string with using SevenZip - 7Zip

分類Dev

How to compress images and convert them into progressive images using cloud code?

分類Dev

How do I compress multiple files into one archive using lzma?

分類Dev

grep patterns from file1 into column of file2

分類Dev

Removes values in a file that match patterns from another file

Related 関連記事

  1. 1

    How to compress a YAML file using references in a script?

  2. 2

    how to overwrite a particular data in file using c++

  3. 3

    Compress a bitstring using Ruby

  4. 4

    Using java regex read a text file to match multiple patterns

  5. 5

    Process non common csv file with awk using field patterns

  6. 6

    File input to a particular field

  7. 7

    Replacing patterns using sed

  8. 8

    Reading a particular word in .txt file

  9. 9

    How to compress a string using GZip or similar in Dart?

  10. 10

    Using Gzip to compress/decompress an array of bytes

  11. 11

    Python How to replace a particular word in a particular line in a text file?

  12. 12

    using prinf function for repeated patterns

  13. 13

    dynamically Accessing of particular label in text file and get elements under it and again start with next word and get elements under it using python

  14. 14

    Perl: Exit if a particular line is not present in a file

  15. 15

    Exclude directories in .gitignore which contain a particular file

  16. 16

    Reading a file and output in a particular format in Perl

  17. 17

    Extracting a particular value from a JSON file

  18. 18

    How to use exclude-patterns from a file

  19. 19

    movie ticket booking in a particular row using array

  20. 20

    Mysql: Set particular value of column using update

  21. 21

    Dividing columns by particular values using dplyr

  22. 22

    Unable to get particular db value using $project

  23. 23

    How to call a particular screen in Tkinter using OOP

  24. 24

    How to compress the image size using C# Dot Net Core

  25. 25

    How to compress / decompress string with using SevenZip - 7Zip

  26. 26

    How to compress images and convert them into progressive images using cloud code?

  27. 27

    How do I compress multiple files into one archive using lzma?

  28. 28

    grep patterns from file1 into column of file2

  29. 29

    Removes values in a file that match patterns from another file

ホットタグ

アーカイブ