Shell script: Delete filenames containing a substring?
Hello, I've got a great idea for a shell script but I don't know how to implement it. I'd like to make a shell script that walks through a directory and though its subdirectories and deletes all files with a specified substring in their file name.
I've read a bit about shell scripts, I'm sure bash could do this easily. |
find /path/to/your/directory -name *substring*|xargs rm
|
Sounds like someone got their homework done for them. :)
|
And
find - "*substr*" -exec rm "{}" \; would be quicker ;} ... no pipe, no xargs. Cheers, Tink P.s.: Don't use -name arguments with wildcards without quoting! You'll most likely get unexpected (unwanted?) results. An invocation like find -name "*substr*" won't get globbed by the shell. |
Thanks, works great.
Here I was thinking I would need to do a script to recursively walk through subdirs, find | grep, then rm, but it turned out to be a one liner. |
All times are GMT -5. The time now is 04:50 AM. |