Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-27-2008, 08:27 AM   #1
LQ Newbie
Registered: Jan 2008
Location: Kentucky
Distribution: Debian, Ubuntu, Gentoo, CentOS, RHEL
Posts: 1

Rep: Reputation: 0
Post Remove Certain Files/Dir from Large Dir

Good day,

Before we continue, we are going to assume we only have CLI access to this machine.

Lets say from the CLI I accidentally untar a huge archive into another large directory such as, / for example. Lets also say that now in / there is a huge list of random directories and files. Aside from manually hunting down and deleting every one, what is the best way to remove these files without touching the rest of the standard directory structure?

I was assuming I could somehow extract the archive to its own directory, perform a ls and pipe it to a document and use that document to rm -r the / directory.

Is this possible? Anyone have a solution to a situation like this?


Old 01-27-2008, 08:44 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,808

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
welcome to LQ...

Why not post the actual situation? The way you describe it makes it sound like homework.

Take a look at the find command--e.g. the options to search by date attributes. Also, find has the "exec" option, allowing you to execute commands using the results. (and the simple -delete option)
Old 01-27-2008, 08:47 AM   #3
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Assuming the tar archive was unpacked relative to / instead of the directory in which it was made, you could try:

1) make a list of the directories/files in the archive: tar -tf <archivename> list.txt

2) write a shell script to cycle through list.txt and delete the files found in that list.
Something like:


cd /
for i in < /path/to/list.txt
rm -rf $i

3) make the script executable, and run it as root.

I'm guessing that would work. Perhaps someone else has a better idea.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to remove all (dot) files without removing toplevel dir? mattengland Linux - Software 8 07-19-2011 02:57 PM
Command to display /dir, /dir/sub, /dir/sub/files knockout_artist Linux - Newbie 9 10-25-2007 02:57 PM
remove some files from a dir wkwireless Linux - Software 5 01-24-2007 07:49 AM
Q. moving /bin dir files to /dev dir?? Texas_student Linux - Software 2 03-26-2006 11:42 PM
Share configuratin dir (.dir) for 3 accounts on local computer LiNuXkOlOnIe Linux - Software 5 01-08-2006 03:36 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:11 AM.

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