Create tar with same name as file but in different folder
Just run this simple shell script from inside your directory:
for file in *; do tar -czf $file.tar.gz $file; done
The result will be a new .tar.gz file for each one of the files inside the directory you're in.
If you wish to create the tar archives in another directory, just change the path that's right after the -cf flags. For example, if you wish to create the archives in another directory that's located in the same directory as your current one, write:
for file in *; do tar -czf ../<Other_Directory>/$file.tar.gz $file; done
is it possible to create a tar of any file which will give different file name after untar
Try the following set/sequence of commands:
assuming your original file is a.b_backup...you can try this..
$ tar -cvf test.tar a.b_backup
$ tar --transform='s/_backup//' -xf test.tar
$ ls
a.b
a.b_backup
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
How to tar compress specific and multiple files without changing of name in Bash?
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")
Staying in another folder, how can i tar specific files from another directory?
You can edit the names in the tar command to remove the path. (Assuming that you have GNU tar.)
tar -cf /home/A/Sample1.tar --transform 's,.*/\([^/]*\),\1,' /home/B/ZSBSDP4/*.csv
Note that if you specify more source directories on the command, you could accidentally put more than one file with the same name in the tar file. Then when unpacking, the last one will overwrite those with the same name that precede it.
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'
untar multiple tar files with identical names to a concatenated/appended file
With GNU tar:
fileno="42"
tar -xvzf "tar${fileno}.tar.gzip" --transform 's/.*/file'"${fileno}"'.csv/' --show-transformed-names
This extracts tar42.tar.gzip
to current directory and names its file to file42.csv
. I assume that the archive contains only one file.
Making archive from files with same names in different directories
What I have used to make a tar ball for the files with same name in different directories is
$find <path> -name <filename> -exec tar -rvf data.tar '{}' \;
i.e. tar [-]r --append
Hope this helps.
Related Topics
How to Create a Bash Variable Like $Random
Compile Git for 32-Bit Linux on Shared Hosting
Cmsg_Nxthdr() Returns Null Even Though There Are More Cmsghdr Objects
/Var/Log/Daemon.Log Taking More Space How to Reduce It
Wget: Unsupported Scheme on Non-Http Url
Linking to Modules Folder Gives Undefined Reference
Gnu Assembler .Data Section Value Corrupted After Syscall
Differencebetween These Two Commands Which Are Used to Run Shell Script
Linux Command Line: How Can Simply Feed Arbitrary Strings to Pipe
Bash Script to Get Specific User(S) Id and Processes Count
How to Disable Hardware Prefetcher in Core I7
Limit Output of All Linux Commands
"Echo" Output Different Answer by Sh and Bash
Extracting Variable in Yaml from a Shell Script
How to Add Text at the Beginning of Specific Lines Using Sed
Wc -M in Unix Adds One Character
How to Make Git-Bash Command Line Start Up with Home Directory