Searching for folders/parent folders not files.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Searching for folders/parent folders not files.
# 1  
Old 06-23-2011
Question Searching for folders/parent folders not files.

Hello again,

A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x.

I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally would include folder size.

From the folder I want to record data from, I used
Code:
ls -al

and the far right column output confuses me.
Code:
-rwxr-xr-x

and
Code:
drwxr-xr-x

etc.

Now while the ls command does give me the file size of the current folder, is the find command modifiable to search for the lowest level folder instead of the individual files?

As of right now my find command is
Code:
find  .  -daystart -ctime 0 -type f | xargs ls -sSh > data_DDMMYY

And I'm aware that there is nothing in that above line that would make me think it's searching for files individually, unless that is the actual function of find.

Any and all help as always is greatly appreciated,
Thanks,
Michael
# 2  
Old 06-23-2011
First, the column printed by ls that looks like -rwxr-xr-x indicates the file's permissions and the file type. The type is indicated by the first character: d is directory, - is regular file, l is symbolic link, etc. The POSIX man page lists all of the possible types.

The remainder is three sets of permission flags for owner, group and other. For each set contains the read, write and execute permission (e.g. rwx, r-x, rw- etc.). Again the man page explains all.

The find command you listed does indeed target only regular files. That is what the -type f option does. If you use -type d then it will list directories only. However, it seems that you want a further limitation and only want to list a directory that has no subdirectories. I don't believe that find has that ability.

To list only the directories with no subdirectories, and then list the files in each of those directories, piping the output of find to awk (or similar script) to further limit the list, and then using the ls command to list the directoies is required. Something like this will find all directories in the current directory that do not have subdirectories, and lists their contents:

Code:
find . -type d|awk '{
    n = split( $1, a, "/" );
    p = ".";
    for( i = 2; i <= n; i++ )
    {
        p = p "/" a[i];  # count times path appears, more than once indicates it has subdirectories
        cp[p]++
    }
}

END {
    for( x in cp )
        if( cp[x] == 1 )  # print only paths with no subdirs; count of 1
            print x;
}'| xargs ls -l

This User Gave Thanks to agama For This Post:
# 3  
Old 06-23-2011
Thanks for the reply, explanation and help.

I'll give it a go most likely on Monday, the big boss has my hands full at the moment.

Cheers,
Michael
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

2. Shell Programming and Scripting

CAT 3 files with the same name in 3 different folders

I am trying to cat 3 files. They all have the same name MFExtract.txt. But, they are in 3 seperate file names. Any idea how I could cat the 3 together. It's throwing me off figuring out a way because the names are the same. I was thinking just doing a 3 cat commands with the full path names and... (2 Replies)
Discussion started by: risarose87
2 Replies

3. UNIX for Dummies Questions & Answers

Archive folders and sub folders

Hi Can i archive folder and folders in with the tar command My files are located in subfolders Eg: Folder1/Folder1_1/*.pdf Folder1/Folder1_2/*.pdf Folder1/Folder1_3/*.pdf so i would like to tar all the files in Folder1_1 and Folder1_2 only not Folder1_3 that should be done next... (2 Replies)
Discussion started by: cnrj
2 Replies

4. Shell Programming and Scripting

Copy between two different folders containing same sub-folders

I have a folder like this ls input1 dir1 dir2 dir3 file1 file2 file3 dir1, dir2 and dir3 are sub-folders inside the folder input1 ls input2 dir1 dir2 dir3 file1 file2 file3 My dir1 in input1 folder has files f1, f2, f3 and f4. My dir1 in input2 folder has file f4 and f5. ... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Making 99 folders 99 folders deep

I am trying to make a unix shell script that will make 99 folders 99 deep (counting the first level folders). So far i have made it make the first 99 folders and 99 more in all of the folders. The only problem is the only way i have found is copying and pasting part of the script over and over and... (18 Replies)
Discussion started by: YukonAppleGeek
18 Replies

6. UNIX for Dummies Questions & Answers

Move folders containing certain files

Hello, How can I move just the folders that contains files modified n days ago? Source tree: |-- SourceFolder | |-- Subfolder1 | | |-- file1.dat | | `-- file2.dat | |-- Subfolder2 | | |-- filea.dat | | `-- fileb.dat Destination tree: |-- ... (3 Replies)
Discussion started by: xavix
3 Replies

7. Shell Programming and Scripting

Searching for folders which are over 5 hours old.

I want to create a script which will delete all folders which are over 5 hours old in HP-UX 11.11. I tried to use the "find" command but it didn't have an option for searching files/folder by hours. Could some one tell me how to achieve this in HP-UX with only using the standard OS commands and... (4 Replies)
Discussion started by: stevefox
4 Replies

8. UNIX for Dummies Questions & Answers

Find file on server, searching thru many folders

Hi all, Is it possible to find a file on a server without knowing the file path? And when the file is found is it possible to find out the file path? I would like to find a file by typing: find server/ -name "filename" Instead of: find server/folder1/folder2/folder3/ -name "filename" Can... (5 Replies)
Discussion started by: Snakehead
5 Replies

9. UNIX for Dummies Questions & Answers

Copying Folders without some folders... ;-)

I am in a fix....... I have to write a backup script to backup say Folder A. Folder A contains n folders 1,2 ,3 .....n. my script should copy A without folder 2 & 3. Is there anyway I can do it without writing individual copy commands???? Please help.... (5 Replies)
Discussion started by: chimpu
5 Replies

10. Shell Programming and Scripting

Backing up Folders without some folders...;)

I am in a fix....... I have to write a backup script to backup say Folder A. Folder A contains n folders 1,2 ,3 .....n. my script should copy A without folder 2 & 3. Is there anyway I can do it without writing individual copy commands???? Please help.... (1 Reply)
Discussion started by: chimpu
1 Replies
Login or Register to Ask a Question