LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Remove Certain Files/Dir from Large Dir (https://www.linuxquestions.org/questions/linux-newbie-8/remove-certain-files-dir-from-large-dir-616606/)

thomas.beaver 01-27-2008 08:27 AM

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

pixellany 01-27-2008 08:44 AM

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)

bigrigdriver 01-27-2008 08:47 AM

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.


All times are GMT -5. The time now is 10:04 PM.