I want to find and tar/archive all my scripts ending .sh so I wrote something like that:
touch ~/archive.tar; find ~ -type f -name '*.sh' -exec rvf ~/archive.tar {} \;
The problem is that after I make an archive called archive.tar the archive won't unpack the files into current directory but to directories where it was archived from. For example, there can be archived script called ~/Desktop/wtf/delete.sh
but it will be extracted into folder wtf
not into current directory where I currently am. So how do I edit my find script to have all scripts in this format ./filename.sh?
cd; find .
rather thanfind ~
. Then the paths in the tarball will be./path/to/script.sh
rather than/home/username/path/to/script.sh
. You can also use the-C
option fortar
to specify the base path to extract tarballs into. – DopeGhoti May 17 '16 at 19:01find
ing from the home directory.cd
with no parameters goes to that location. – DopeGhoti May 17 '16 at 19:24find
, you can use-execdir
instead of-exec
, andfind
will cd to each matching file's directory before running the command. Seeman tar
and search for-execdir
for details. BTW, use+
to terminate the-exec
orexecdir
rather than\;
...that will runtar
with as many filenames as possible, rather than runningtar
once for each filename. – cas May 18 '16 at 3:17