How to tar certain file types in all subdirectories?
find ./someDir -name "*.php" -o -name "*.html" | tar -cf my_archive -T -
How to tar specific file extension files?
find -name "*.h" -o -name "*.cpp" | xargs tar -czvf build.tar.gz
How do I tar a directory of files and folders without including the directory itself?
cd my_directory/ && tar -zcvf ../my_dir.tgz . && cd -
should do the job in one line. It works well for hidden files as well. "*" doesn't expand hidden files by path name expansion at least in bash. Below is my experiment:
$ mkdir my_directory
$ touch my_directory/file1
$ touch my_directory/file2
$ touch my_directory/.hiddenfile1
$ touch my_directory/.hiddenfile2
$ cd my_directory/ && tar -zcvf ../my_dir.tgz . && cd ..
./
./file1
./file2
./.hiddenfile1
./.hiddenfile2
$ tar ztf my_dir.tgz
./
./file1
./file2
./.hiddenfile1
./.hiddenfile2
tar folder and exclude all subfolders, then tar to specific path
first, use find
to find the files meeting your criteria:
find ~/Desktop -type f -maxdepth 1
then pipe it to tar, using -T
( or --files-from
) to tell tar
to get the list of files from stdin
:
find ~/Desktop -type f -maxdepth 1 | \
tar -T - cvf r.tar
Shell command to tar directory excluding certain files/folders
You can have multiple exclude options for tar so
$ tar --exclude='./folder' --exclude='./upload/folder2' -zcvf /backup/filename.tgz .
etc will work. Make sure to put --exclude
before the source and destination items.
How to create tar file with only certain extensions but omitting server generated files with similar extension?
tar -tf file.tar --wildcards '*.jpg' --exclude '*.*.jpg'
Output:
filetwo.jpg
imagethree.jpg
original.jpg
Just change -t
to -x
to extract instead.
To create the archive:
tar -cf file.tar *.jpg --wildcards --exclude '*.*.jpg'
Related Topics
How to Split Mailbox into Single File Per Message
How to Cut an Existing Variable and Assign to a New Variable in Bash
Join on First Column of Two Files
Remove File Coding Mark But Preserve Its Coding
Execute Script as Another User Whilst Not Being Root
Bash Echo with an $ Character Outside the String
Eclipse Cdt Indexer Lost After System Update
How to Grep a String in a Directory and All Its Subdirectories
Amazon Linux: "Apt-Get: Command Not Found"
What's the Difference Between Event-Driven and Asynchronous? Between Epoll and Aio
Split Output of Command by Columns Using Bash
Redirecting Output of Bash for Loop
Shell-Init: Error Retrieving Current Directory: Getcwd -- the Usual Fixes Do Not Wor
Opening a .Tar.Gz File with a Single Command
Ssh Error When Executing a Remote Command: "Stdin: Is Not a Tty"