LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 06-13-2005, 12:30 AM   #1
hkl8324
Member
 
Registered: Aug 2003
Location: Hong Kong, China
Distribution: Ubuntu 10.04
Posts: 234

Rep: Reputation: 30
How to del all the files expanded by an tarball file?


i wrongly expand the kernel-source 2.6.8.11 to /usr/src/ but not /usr/src/kernel-source

and /usr/src/ become a mess........

how can i del all the files wrongly expanded there? (i mean a intelligent method......but not manually doing it.....)

thanks
 
Old 06-13-2005, 12:44 AM   #2
aikidoist72
Member
 
Registered: Jan 2005
Location: Australia
Distribution: Slackware Archlinux FreeBSD
Posts: 218

Rep: Reputation: 30
hkl8324

Be careful that you did not have anything in /usr/src/ that you may need before deleting like source files from your working kernel. then run

Code:
rm /usr/src/*
This will remove all files in this folder. BE WARNED!!!

Last edited by aikidoist72; 06-13-2005 at 12:45 AM.
 
Old 06-13-2005, 12:50 AM   #3
hkl8324
Member
 
Registered: Aug 2003
Location: Hong Kong, China
Distribution: Ubuntu 10.04
Posts: 234

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by aikidoist72
hkl8324

Be careful that you did not have anything in /usr/src/ that you may need before deleting like source files from your working kernel. then run

Code:
rm /usr/src/*
This will remove all files in this folder. BE WARNED!!!
i do have many files in /usr/src/ ..........
 
Old 06-13-2005, 01:24 AM   #4
MikeZila
Member
 
Registered: Jul 2004
Location: Parts Unknown
Distribution: Arch
Posts: 377

Rep: Reputation: 30
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.
 
Old 06-13-2005, 01:52 AM   #5
hkl8324
Member
 
Registered: Aug 2003
Location: Hong Kong, China
Distribution: Ubuntu 10.04
Posts: 234

Original Poster
Rep: Reputation: 30
Quote:
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.
O...thank you...

you are very smart
 
Old 06-13-2005, 01:58 AM   #6
MikeZila
Member
 
Registered: Jul 2004
Location: Parts Unknown
Distribution: Arch
Posts: 377

Rep: Reputation: 30
Did this work for you?
 
Old 06-13-2005, 03:54 AM   #7
short101
Member
 
Registered: May 2004
Location: Aust.
Distribution: Debian
Posts: 424

Rep: Reputation: 30
Not an answer but a question. What command did you use to do this?
 
Old 06-13-2005, 04:13 AM   #8
hkl8324
Member
 
Registered: Aug 2003
Location: Hong Kong, China
Distribution: Ubuntu 10.04
Posts: 234

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by MikeZila
Did this work for you?
works

i just put rm at the front and [filename1/foldername1] [filename2/foldername2].........

but it is quite time cosuming because the original list is like that:

filename1/foldername1
filename2/foldername2

i have to make that list into a long chain.........
 
Old 06-13-2005, 04:38 AM   #9
nvm
LQ Newbie
 
Registered: Jun 2005
Location: Glasgow, Scotland
Distribution: Debian
Posts: 12

Rep: Reputation: 0
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.
 
Old 06-13-2005, 04:51 AM   #10
nvm
LQ Newbie
 
Registered: Jun 2005
Location: Glasgow, Scotland
Distribution: Debian
Posts: 12

Rep: Reputation: 0
Oops, my apologies that perl line just displays the modified text, to redirect it back to it's original location change it to:

Code:
perl -pe 's/^/rm /' filename_with_list_of_filenames > filename_with_list_of_filenames
 
Old 06-13-2005, 05:05 AM   #11
MikeZila
Member
 
Registered: Jul 2004
Location: Parts Unknown
Distribution: Arch
Posts: 377

Rep: Reputation: 30
That's some nice Perl-ing. I'm going to save that in case I ever need it for this purpose.

Glad the sollution worked for you. Remember; work smarter, not harder.
 
Old 06-13-2005, 06:12 AM   #12
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
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.
 
Old 06-13-2005, 06:29 AM   #13
nvm
LQ Newbie
 
Registered: Jun 2005
Location: Glasgow, Scotland
Distribution: Debian
Posts: 12

Rep: Reputation: 0
That's much better.
 
Old 06-13-2005, 07:29 AM   #14
tomj88
Member
 
Registered: Apr 2005
Location: Wolverhampton, England
Distribution: Ubuntu
Posts: 334

Rep: Reputation: 30
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?
 
Old 06-13-2005, 09:14 AM   #15
hkl8324
Member
 
Registered: Aug 2003
Location: Hong Kong, China
Distribution: Ubuntu 10.04
Posts: 234

Original Poster
Rep: Reputation: 30
Quote:
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....)

thanks again...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
where is the .emacs file in the emacs source code tarball? aizkorri Programming 2 01-13-2007 02:05 PM
accidentally del /etc/group file in RedHat 9 karmakid Linux - Security 3 08-02-2005 08:16 PM
Quota Problem,qbout Upload/del File, i need help,thank singying304 Linux - Software 14 07-06-2005 11:27 AM
Unable to build RPM file from tarball tkt Linux - Newbie 1 04-26-2005 02:29 AM
del file csosa Linux - Software 12 09-28-2003 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 09:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration