Home > front end >  How to tar compress specific and multiple files without changing of name in Bash?
How to tar compress specific and multiple files without changing of name in Bash?

Time:03-22

I need do some simple compresion multiple files to .tar in bash. Conditions: My archive must include only files with extension .exe. Unfortunetly, when I am trying this:

find ./myDir -name "*.exe" | tar -cf archive -T -

The file names are changed like ./file1.exe How can I compress this without change of file names?

CodePudding user response:

Suggesting:

 find "$PWD/myDir" -name "*.exe" | tar -cf archive -T -

This will not do anything interesting.

Better suggesting to feed tar command with results from find command

  tar czf your_compressed_file.tar.gz $(find ./myDir -name "*.exe")

Notice tar cf is not compressed. But tar czf is compressed.

You can also add -v option to see what are the compressed files:

  tar czfv your_compressed_file.tar.gz $(find ./myDir -name "*.exe")
  • Related