Exclude directories when searching for files
Hi Guys,
When searching for a specific file in a directory, I use: find /usr/test/files/ -iname "mytest*" -print0 This returns all "mytest" files from the specified directory. Unfortunatly, if a "mytest" file exists in a subdirectry, say "/usr/test/files/archive/", then this file is also returned. How can I exclude specific subdirectories from the search directory list? I basically only want to search in one directory, even if subdirectories exists. Also, when the files are returned, they are shown with the full path and file name. How do I get them shown with the name only? Thanks! J |
you can use the -maxdepth value for find amongst various other approaches. This does largely make the use of find questionable. You probably don't want to use it, and just use ls instead or something? I'm presuming this is in a script, right? Maybe just a normal wildcard glob would suffice.
|
Code:
find /usr/test/files/ -maxdepth 1 -iname "mytest*" Code:
# # ls -ltr |grep -v "^d"|grep "mytest*"|awk '{print $9}' |
Great, thanks guys. Its working. Any suggestion on the removal of the path before the file name? I just need the file name itself with no path included.
Thanks! J |
you can use basename to do that easily enough. alternatively if you were change directory and then run an ls IN that directory, you'd only have the short name to start with.
|
Quote:
|
Yes, thank you Pinga123. Thanks for the help, I learn a lot!
|
All times are GMT -5. The time now is 03:45 PM. |