0

So, my archive manager seems not to have preserved the directory hierarchy when extracting a tar.xz file. Now my Downloads folder is messy and full of files not in their proper places.

I want to delete those and only those files that were in the archive to start with. To do this I am trying to match the ends of each file path from the output of tar tf file.tar.xz and delete the associated files.

For example if the input is:

tor-browser_en-US/Browser/firefox
tor-browser_en-US/Browser/firefox.real
tor-browser_en-US/Browser/fonts/
tor-browser_en-US/Browser/fonts/Arimo-Bold.ttf

I want the output to be:

firefox
firefox.real
Arimo-Bold.ttf

so I can delete them.

I have been trying to accomplish this with sed 's/.*\/([^\/]+)$/\1/' but that gives the error sed: -e expression #1, char 19: invalid reference \1 on 's' command's RHS and I'm not sure what else to try.

1 Answer 1

1
sed '/\/$/d; s|.*/||'

/\/$/d removes any line with trailing /. s|.*/|| removes everything before the last / (if any) and the / itself.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .