how to rename files you put into a tar archive using linux 'tar'
You can modify filenames (among other things) with --transform
. For example, to create a tape archive /tmp/foo.tar
, putting files /etc/profile
and /etc/bash.bashrc
into it while also renaming profile
to foo
, you can do the following:
tar --transform='flags=r;s|bar|foo|' -cf file.tar file1 file2 bar fubar /dir/*
Results of the above is that bar
is added to file.tar
as foo
.
The r
flag means transformations are applied to regular files only. For more information see GNU tar documentation.
You can use --transform
multiple times, for example:
tar --transform='flags=r;s|foo|bar|' --transform='flags=r;s|baz|woz|' -cf file.tar /some/dir/where/foo/is /some/dir/where/baz/is /other/stuff/* /dir/too
How to rename .tar.gz file without extracting the contents and creating the new .tar.gz file in UBUNTU?
The easiest is to simply rename ("move") the file:
mv Existing.tar.gz New.tar.gz
Rename Directory Name Before tar Happens
Which tar
?
GNU Tar accepts a --transform
argument, to which you give a sed
expression to manipulate filenames.
For example, to rename during unpacking:
tar -zxf my-dir.tar.gz --transform s/my-dir/your-dir/
BSD tar and S tar similarly have an -s
argument, taking a simple /old/new/
(not a general sed
expression).
Folder Renaming After Tar Extraction
Manually create folder, and strip components from tarball:
archive=my.tar.gz
mkdir ${archive%.tar*}
tar --extract --file=${archive} --strip-components=1 --directory=${archive%.tar*}
How to extract, rename and view some log files from user inputed tar filename?
try this:
#!/bin/bash
fname=$1
if [[ -f "${fname}.tar" ]]; then
tar -xvf "${fname}.tar"
fi
mv tftpboot $fname
then ./extract.sh cubelog_457890
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
Related Topics
How to Get Docker Container Id from Within the Container with Cgroup V2
How to Write Conditional Import Statements in Qml
How to Start Redis-Server on a Different Port Than the Default Port 6379 in Ubuntu
Run Shell Script When Saving a File in Sublime Text 3
Logcat Show Invisible Messages in Eclipse Mars
Case-Insensitive Glob on Zsh/Bash
Tcp: Server Sends [Rst, Ack] Immediately After Receiving [Syn] from Client
Scripts Launched from Udev Do Not Have Display Access Anymore
Why Does Gcc Force Pic for X64 Shared Libs
Pycharm Startup Error: Unable to Detect Graphics Environment
Decrypt Obfuscated Perl Script
Automated Test Tools for Linux/Ncurses
Multiple Option Arguments Using Getopts (Bash)
Does Madvise(_, _, Madv_Dontneed) Instruct the Os to Lazily Write to Disk
How to Get Time Since File Was Last Modified in Seconds with Bash