LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-27-2008, 08:27 AM   #1
thomas.beaver
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?


Thanks,

Thomas
 
Old 01-27-2008, 08:44 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,887

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
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:

#!/bin/bash

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

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

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


Reply


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


All times are GMT -5. The time now is 07:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration