I am trying to create a graphical program for my script.
Inside the script I use tar to create a tar archive.
From the graphical program I get the full name of file that I want to create a tar archive.
tar -cvf temp.tar /home/username/dir1/dir2/selecteddir
My tar archive includes home, username, dir1, dir2 and selecteddir while i want tar to create archive only including selecteddir.
dirnameto extract everything until "selecteddir" andbasenameto extract "selecteddir". Try the two commands with the $path as argument. – Ketan Nov 17 '14 at 03:42tar -C /home/username/dir1/dir2 -cvf temp.tar '*.csv'won't work. – Christian Long Aug 29 '16 at 14:59tar -C /home/username/dir1/dir2/selecteddir -cvf temp.tar .to only reflect the tree of selecteddir witout 'selcteddir/' preceding every filename. – grenix Dec 22 '21 at 11:53./prefixing all files! See @mpen's answer – Hashbrown Jan 21 '22 at 10:28*: https://unix.stackexchange.com/a/71464/408419 – User Rebo Jun 08 '23 at 06:29