looping through linux directories
I need to loop through a long list of directories checking the files in each of these directories for file names that include grp and delete the matching files.
|
what have you tried so far ?
Code:
find . -name "*grp*" -exec mv '{}' /whatever/floats/your/boat \; |
I haven't tried anything yet. I used rsync to try to bring all the files over that I wanted to the new dir and that worked but it left behind that I copied and I needed them to me deleted. I guess, at this point, I really just need to iterate through the source directory structure and delete the files with grp in the name. Sorry if I started this off in the wrong direction.
I was thinking that I could write a short script like this: my @dirs = ?????? foreach my $sub_dir(@dirs) { system("cd $sub_dir"); system("rm -f */*grp*"); system("cd .."); } I just don't know how to populate the array with the list of dirs. I only need to go 1 level deep on the hierarchy. |
no prob... people usually post the code tidbits that are causing them problems then responders can correct the issues.
i would use find to generate a list of the relative paths of the files i want to move and go from there. |
trying to use your find example.
find . -name "*grp*" -exec rm -i-r wanted to find and remove anything with grp in the name starting in the current dir and recursing through all dirs asking before deleting. I get error::: find: missing argument to `-exec' |
Code:
find . -name "*grp*" -exec rm -i -r also this '{}' tells find to use that as the filename argument. not sure why you need to recurse with find what does this yeild for you ?: Code:
find . -name "*grp*" |
same error message.
find: missing argument to `-exec' |
Quote:
Code:
find . -name "*grp*" -exec rm -i -r {} \; |
still the same.
just to be sure, this should work right from the command line, right? |
Quote:
|
Quote:
Code:
[eggroll@picard test]$ ls |
Code:
find . -name "*grp*" -exec rm |
Quote:
|
Quote:
Please run the following command and post the output Code:
find . -name "*grp*" -exec rm -i -r {} \; |
ok, I'm a complete ass.
I thought the semi colon was a type so I left it off. just ran it again and it looks like it worked. thank you for your patients. damn, I hate being a noob some times. can you do my one last favor and explain what the {} \; means? |
All times are GMT -5. The time now is 01:44 AM. |