find . -name tobedelete.txt -exec rm {};
but doesnt work.
There is a fundamenal understanding problem here, The "find" command posted will look for a file called "tobedelete.txt" and delete that file (not the files listed in that file).
The code posted by "gull04" is scary.
Please post the actual directory structure in machine-readable format:
I've used this type of routine many times, in view of the original post made by yogeshkumkar and given that I pointed out that he should print out the list of the find command I'd just like to understand how my code was "scary".
I'm quite happy to admit that I'm as likely to screw up as the next guy, but in this case I can't really see what is wrong with the advice that I gave. As I'm always keen to learn, I'd appreciate your feedback.
I don't mean to be critical, I'm just interested to know - I wouldn't deliberately give someone poor advice. I really didn't think that my post was too far off the mark, I use "find" this way frequently - I'm quite happy to admit my shortfalls but in this case I thought the advice was OK. Based on the original post I didn't think this was poor advice, I was just trying to solve a problem for someone.
Perhaps I should have said that the code should be "rm -i" and you can check each file prior to deletion.
Regards
Dave
Last edited by gull04; 03-11-2012 at 08:24 PM..
Reason: Typo
Thanks for the comments Methyl and Dave.
The answer by Dave doesnt work. it simply removes the content of the tobedeted.txt.
The actual dir structure is like
in the main_dir
there are subdirs like AAA, BBB, CCC, ....
inside AAA there are subdirs like aa1, aa2, aa3, ...
inside aa1 there are files like AAA_aa1_file1.txt, AAA_aa1_fileextra.txt, AAA_aa1_mod43a4.txt, ....
inside aa2 there are files like AAA_aa2_file1.txt, AAA_aa2_fileextra.txt, AAA_aa2_mod43a4.txt, ....
inside BBB there are subdirs like bb1, bb2, bb3, ...
inside bb1 there are files like BBB_bb1_file1.txt, BBB_bb1_fileextra.txt, BBB_bb1_mod43a4.txt, ....
inside bb2 there are files like BBB_bb2_file1.txt, BBB_bb2_fileextra.txt, BBB_bb2_mod43a4.txt, ....
and so on...up to many hundred of files. I managed to the get the filenames which I must delete.
e.g. the content of tobedeleted.txt is
AAA_aa1_fileextra.txt
BBB_bb1_file1.txt
BBB_bb1_mod43a4.txt
CCC_cc4_mfg54d2.txt
GGG_gg6_hd21s1.txt
and so on....
i hope there is a way!
Last edited by yogeshkumkar; 03-11-2012 at 09:49 PM..
Just for information, the tobedeleted.txt file should be in the directory where you are running the script from or you should enter the pat to the file as well such as "for i in `/path/to/file/tobedeleted.txt`"
Hi, I'm currently trying to print the names of all the .txt files in the subdirectories that contain the string I'm searching.
I tried with this code, but it seems that it searches for the names that matches the string instead of searching for the string in the individual files and printing the... (2 Replies)
Hello,
I wanted to
list all files in subdirectories which are modifiled recently. need to display all files with full details like hpw it display with ls -l ( date, size,..)
Thanks
Bala (3 Replies)
I need to write a script to :
list files with *.i extension in a directory and all its subdirectories + 30days old, save it in a file and then remove (2 Replies)
Hi,
I have a very big directory structure that consists of many sub-directories inside.There are around 50 ".gz" files under this dir structure.
I want to copy all the gz files alone to a seperate location.
Plz help me. (2 Replies)
I'm trying to remove several directories which contains sun-dirs and files inside.
I used the command rm -r <dirname>
But, it always ask "examine file in directory <dirname> yes/no?" line by line.
So, i need to write "y" for every line.
How can i skip this step and remove all directories with... (9 Replies)
If I execute the command "ls -l /export/home/abcde/dev/proj/code/* | awk -F' ' '{print $9}' | cut -d'/' -f6-8" it will list all the files in /export/home/abcde/dev/proj/code/ directory as well as the files in subdirectories also
proj/code/test.sh
proj/code/test1.c
proj/code/unix... (8 Replies)
I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like... (5 Replies)
I posted a week ago regarding this scripting question, but I need to revisit and have a few more questions answered..
User cfajohnson was extremely helpful with the archive script, but clarification on my part is needed to help steer the answer in a direction that works in this particular... (5 Replies)
I need to find the largest files in a directory & it's subdirectories.
I'm not sure what options on ls -l will work to give me this. or is there another way to do this?
Thanks,
igidttam (6 Replies)
Hi,
How to recursively remove Ctrl M characters in files from a directory and its sub directory ?
I know unix2dos command is there but to remove in bunch of files ... ?
Thanks (7 Replies)