@gull04
Your script contains a couple of common problems:
1) Uses "for" with an open-ended list.
This breaks when the command line gets too long.
Also, the "for" breaks if any filename contains a space character.
2) The "find" is not specific to files
We can turn the script round to make it a bit more robust:
For the diagnostic version we could display what we are searching for,
because I too am having trouble understanding the content of "tobedelete.txt" (or is it "tobedeleted.txt"?). There is nothing in your code which would overwrite the file.
@yogeshkumkar
Please post what Operating System and version you have and what Shell you are using.
You're absolutely right in your approach to making the script more robust and I must admit there were several basic assumptions made by me that were possibly optimistic.
I did assume;
And again I'd say that I took yogeshkumkar at face value when I gave the advice, not that that is any excuse for sloppiness. I should have tested for file types incase there was a link or the likes, should have enclosed the variable to ensure that it worked around spaces etc.
I work in a fairly pressured production/dr/test/development environment. So have four of every machine from M9000's to T5120's where I always have the facility to test - possibly it has made me a little cavalier.
I'll try to remember that not everyone can restore Pb sized file systems in minutes if things go pear shaped
Thanks for the vote of confidence, Pb Petabyte 1024Tb - dead easy with ZFS. BTW thanks for being patient with me on the forum, I'm prepared to try - "never been wrong, never done anything".
@yogeshkumkar
DANGEROUS SCRIPT
The first "find" command posted would be a syntax error on some O/S because there is no "-name" parameter. On my O/S it produces a list of EVERY file and directory in the directory named in the first parameter. Thus your script is in danger of deleting EVERY file regardless of whether they appear in "filenames.txt".
I've commented about using "for" with open-ended lists in an earlier post.
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)