Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seach for all subdirectories

Status
Not open for further replies.

jaabaar

Programmer
Jun 1, 2011
65
0
0
GB
Hi All
I would like to be able to search for all subdirectory that start with to letters and 3numbers and display results and display folder properties "Owenership" and date modified. below it does all directory I want it to leave out/only display results for subdirectories.

# finds all directories that start with 2 characters and 3 numbers and rest does not matter what they are.

find /data/folders -type d -name "[a-zA-Z][a-zA-Z][0-9][0-9][0-9]*" > /home/max/resultFindDIR.txt

Thanks for your help.
 
How about:

Code:
$  find /data/folders[red]/*[/red] -type d -name "[a-zA-Z][a-zA-Z][0-9][0-9][0-9]*" > /home/max/resultFindDIR.txt

Add the -prune option as well if you don't want to find any sub-sub-directories...

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Thank you.

How about for each retirned result display file properties on next line.

 
Hi

jaabaar said:
How about for each retirned result display file properties on next line.
See the [tt]-printf[/tt] action in [tt]man find[/tt] :
Code:
find /data/folders/* -type d -name "[a-zA-Z][a-zA-Z][0-9][0-9][0-9]*" [highlight]-printf '%p\n%u\t%t\n'[/highlight] > /home/max/resultFindDIR.txt


Feherke.
 
Thanks you How do I do the following


for every returened directory found move everything to another location and preserve folder/file properties.
for example

find /data/folders/* -type d -name "[a-zA-Z][a-zA-Z][0-9][0-9][0-9]*"

found dir1/
then move it to another location

hope that makes sense.

 
This is beginning to look like incremental homework!

The internet - allowing those who don't know what they're talking about to have their say.
 
Wow! I saw this exact same question on another forum. My response to the "display the properties on the next line" was this...
Code:
find /data/folders/* -type d -name "[a-zA-Z][a-zA-Z][0-9][0-9][0-9]*" -print -ls > /home/max/resultFindDIR.txt
The "[tt]-print[/tt]" displays the file name and the "[tt]-ls[/tt]" displays the file details.

 

I have looked at adive provided above and I am refining what was learned.

I am trying to finds all sub directories named graphics, check if empty if not empty then move all subdirectory contents to another place.


find /data/folders/* -type d -name "graphics" -print -ls

DIR="/-name"

if [ "$(ls -A $DIR)" ]; then

mv -name /data/temp/

else
#do nothing
fi


 

I managed to change to update to the following however the following still does not work properly as I need to only move files in original location if exist if empty do not move. advice will be apriciated.


find /data/folder/* -type d -name "graphics" | xargs -I '{}' mv {} /tmp/graphics

 
I managed to change to update to the following however the following still does not work properly as I need to only move files in original location if exist if empty do not move. advice will be apriciated.


find /data/folder/* -type d -name "graphics" | xargs -I '{}' mv {} /tmp/data/folder/*/graphics

what I mean is found files then move to next location and create same folder structure if already exist then just copy
for example

found
/data/folder/dir1/graphics

New Location
/tmp/data/folder/dir1/graphics

then go to the next folder and copy the same
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top