How to del all the files expanded by an tarball file?
DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If you could get a list of all the files in the archive you expanded and dump them to a text file, you could just manually add "rm" in front of each of them and run it as a shell script by adding "#!/bin/sh" at the top and making it executable.
It would be the best way to weed out the files you didn't mean to extract while keeping the ones you want.
Originally posted by MikeZila If you could get a list of all the files in the archive you expanded and dump them to a text file, you could just manually add "rm" in front of each of them and run it as a shell script by adding "#!/bin/sh" at the top and making it executable.
It would be the best way to weed out the files you didn't mean to extract while keeping the ones you want.
One quicker way might be to use perl to change the beginning of each line.
If you had the list of files:
filename1
filename2
..etc
then perl -pe 's/^/rm /' filename_with_list_of_filenames
(note the space after the rm) will add 'rm ' to the start of each line.
If you were to make the resulting modified file executable with chmod +x filename_with_list_of_filenames
running ./filename_with_list_of_filenames will get rid of them all.
You want to remove all files extracted by this command. You'd do (in the same directory):
Code:
tar tjf /a/file.tar.bz2 | xargs /bin/rm -f
which will only remove files, and may give errors with directories; you'd then have to remove empty directories. If you know what you do, you can replace '/bin/rm -f' with '/bin/rm -rf'.
Off topic, but NVM, your perl program (on my machine) would wipe over the input file, but if I did:
perl -pe 's/^/rm /' file > new_file
It worked fine, and the modified contents were in the right places. If I did:
perl -pe 's/^/rm /' file > file
It made a clean file called "file" with nothing in it. Is it something I have done?
Originally posted by theYinYeti Let's say that you ran:
Code:
tar xjf /a/file.tar.bz2
You want to remove all files extracted by this command. You'd do (in the same directory):
Code:
tar tjf /a/file.tar.bz2 | xargs /bin/rm -f
which will only remove files, and may give errors with directories; you'd then have to remove empty directories. If you know what you do, you can replace '/bin/rm -f' with '/bin/rm -rf'.
Yves.
good info...
but can you explain why tjf and | xargs /bin/rm -f exactly works...?
(it is hard to remember something that i dont know how it works....)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.