find command listing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find command listing
# 8  
Old 10-26-2012
Quote:
Originally Posted by radoulov
Quote:
Originally Posted by Don Cragun
[...]
Also note that the find command you provided in your 1st posting on this thread:
Code:
find -name *.WAV

is using a non-standard extension I've never seen before. On standard versions of the find utility, the first argument to the find utility would have to be the name of a directory.
[...]
Just to add that GNU find defaults to the current directory if no path(s) is/are given (man 1 find):

Code:
$ find --version
GNU find version 4.2.27

Code:
OPTIONS
       The  '-H', '-L' and '-P' options control the treatment of symbolic links.  Command-line arguments following these
       are taken to be names of files or directories to be examined, up to the first argument that begins with '-', '(',
       ')', ',', or '!'.  That argument and any following arguments are taken to be the expression describing what is to
       be searched for.  If no paths are given, the current directory is used.  If no expression is given,  the  expres-
       sion '-print' is used (but you should probably consider using '-print0' instead, anyway).

Thanks for the information.

I perform the vast majority of my programming on OS X, so running the commandman 1 findwill not provide the text that you quoted from the find man page you'll find on a Linux system.

For the record, on OS X (and I imagine on BSD and most UNIX-branded systems) that command line writes diagnostic messages similar to:
Code:
find: illegal option -- n
find: illegal option -- a
find: illegal option -- m
find: illegal option -- e
find: *.WAV: No such file or directory

to standard error and exits with exit code 1.
# 9  
Old 10-29-2012
Question ls -lf is correct

Hello,

I tried ls -lf on a subdirectory of the main directory Music,. and got a huge list of files in 3 columns

Code:
ajayram@pc13:/media/HITACHI/Music/Hindi Music$ ls -lf
...
Abhijeet Sawant/                                                 Piya Haji Ali-Nusrat Fateh Ali Khan.WAV                    Rang De Basanti/
Agnee/                                                           AlbumArt_{95109B16-8980-425B-9D75-7C1BD9569130}_Small.jpg  Rangeela/
Aisha/                                                           AlbumArt_{ADAE49DB-6396-4F0A-86E3-79DF94F56DAF}_Large.jpg  Refugee/
I hate love stories/                                             AlbumArt_{ADAE49DB-6396-4F0A-86E3-79DF94F56DAF}_Small.jpg  Rock on/
Instant Karma/                                                   AlbumArt_{D4826E15-A4F0-4E8C-8448-2C5DB13E3C86}_Large.jpg  Saajan/
Jaan Leva.WAV                                                    AlbumArt_{D4826E15-A4F0-4E8C-8448-2C5DB13E3C86}_Small.jpg  Saawariya/
...

The output is in unsorted order.

I then scanned the output for .WAV files ie reading Column 1 from top to bottom, then Column 2 and then Column 3 and it gives the same output as this find command run on the top level directory ..

Code:
ajayram@pc13:/media/HITACHI/Music$ find -name *.WAV

So does the find command work like this ? It takes the input directory and goes through all sub directories and executes
Code:
 ls -lf

and filters from that the files of the required type ( here in this case *.WAV)

However, I have another doubt, when I ran the find command on the top level Music Directory, the Music Directory had no *.WAV files in it , but only in the directories beneath it, thus it gave the desired output,. I expected a similar output when I go to the Hindi Music Directory, I thought that find would give me all the *.WAV files in that directory and directories beneath it.

But it just returns one line of the output and throws up and error !

Code:
ajayram@pc13:/media/HITACHI/Music/Hindi Music$ find -name *.WAV 
find: paths must precede expression: Baazigar Title Track.WAV
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

could someone please clarify this ?
# 10  
Old 10-29-2012
Quote:
Originally Posted by ajayram
Hello,

I tried ls -lf on a subdirectory of the main directory Music,. and got a huge list of files in 3 columns

Code:
ajayram@pc13:/media/HITACHI/Music/Hindi Music$ ls -lf
...
Abhijeet Sawant/                                                 Piya Haji Ali-Nusrat Fateh Ali Khan.WAV                    Rang De Basanti/
Agnee/                                                           AlbumArt_{95109B16-8980-425B-9D75-7C1BD9569130}_Small.jpg  Rangeela/
Aisha/                                                           AlbumArt_{ADAE49DB-6396-4F0A-86E3-79DF94F56DAF}_Large.jpg  Refugee/
I hate love stories/                                             AlbumArt_{ADAE49DB-6396-4F0A-86E3-79DF94F56DAF}_Small.jpg  Rock on/
Instant Karma/                                                   AlbumArt_{D4826E15-A4F0-4E8C-8448-2C5DB13E3C86}_Large.jpg  Saajan/
Jaan Leva.WAV                                                    AlbumArt_{D4826E15-A4F0-4E8C-8448-2C5DB13E3C86}_Small.jpg  Saawariya/
...

The output is in unsorted order.

I then scanned the output for .WAV files ie reading Column 1 from top to bottom, then Column 2 and then Column 3 and it gives the same output as this find command run on the top level directory ..
Yes. This is exactly what Jim Mcnamara and I have been describing in our posts on this thread.
Quote:
Code:
ajayram@pc13:/media/HITACHI/Music$ find -name *.WAV

So does the find command work like this ? It takes the input directory and goes through all sub directories and executes
Code:
 ls -lf

and filters from that the files of the required type ( here in this case *.WAV)
NO! The find utility does not call the ls utility to read directories. The find utility and the ls utility both read directories on their own. (If you want to know what is going on under the covers, look at the opendir() and readdir() functions manual pages on your system.)

The find utility does not sort directory entries after reading them; the ls utility sorts directory entries unless the -f option is in effect.
Quote:
However, I have another doubt, when I ran the find command on the top level Music Directory, the Music Directory had no *.WAV files in it , but only in the directories beneath it, thus it gave the desired output,. I expected a similar output when I go to the Hindi Music Directory, I thought that find would give me all the *.WAV files in that directory and directories beneath it.

But it just returns one line of the output and throws up and error !

Code:
ajayram@pc13:/media/HITACHI/Music/Hindi Music$ find -name *.WAV 
find: paths must precede expression: Baazigar Title Track.WAV
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

could someone please clarify this ?
This is a completely different topic based on the need to use appropriate quoting mechanisms when expanding filenames in the shell (especially when those filenames may contain <space> or <tab> characters like the names of your .WAV files do). When you ask the shell to run the command:
Code:
find -name *.WAV

the shell sees an unquoted *.WAV pathname pattern and expands it to a (sorted) list of files in the current directory that match that pattern. Then it calls find with each element of that list as a separate argument.

The find -name primary expects to see a single filename pattern as an argument, but instead you are giving it a list of files. The find utility looked at its arguments, determined that the first filename in the list was to be used as the -name primary's pattern argument, and saw more arguments that didn't match the name of any of find's primaries or operators. Therefore, it gave you a diagnostic message for the second filename expanded from the *.WAV pattern by the shell and quit.

If you use the shell's quoting rules to avoid the shell's pathname pattern matching expansions, you will get what you want. In this case, any of the following:
Code:
find -name '*.WAV'
find -name "*.WAV"
find -name \*.WAV

and well over a hundred other ways of quoting this string will work as you expected.

Note that the behavior of the command you gave without quoting *.WAV will vary depending on how many files match the pattern in the directory where you run the command. If there aren't any files matching that pattern in the directory where you ran the command (such as your top level music directory, you'll get what you wanted because the pattern expands to itself when there are no matches. Had there been exactly one file that matched, find would find the file you wanted in the current directory, but would have found *.WAV files in subdirectories only if they had the same name as the file matched in the current directory.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Getting files through find command and listing file modification time upto seconds

I have to list the files of particular directory using file filter like find -name abc* something and if multiple file exist I also want time of each file up to seconds. Currently we are getting time up to minutes in AIX is there any way I can get file last modification time up to seconds. (4 Replies)
Discussion started by: Nitesh sahu
4 Replies

2. UNIX for Dummies Questions & Answers

Listing only the files under a directory from the result of find command

Hi, I have a main folder 'home'. Lets say there is a folder 'bin' under 'home'. I want to check the list of files under subdirectories present under the /bin directory created in the last 24 hours. I am using the following find command under home/bin directory: find . -mtime -1 -print ... (3 Replies)
Discussion started by: DJose
3 Replies

3. UNIX for Dummies Questions & Answers

How to find directory listing from root to all files in tree format with details of perm/own/grp?

Hi, My apologies if my query is already available on this forum but I am new and could not find. I need a script to list all directories/sub directories and files with permissions/groups/owners. The script would run from home directory and should capture every directory. How do I do this? ... (4 Replies)
Discussion started by: 8709711
4 Replies

4. Solaris

SFTP Command Help - listing files

Ok I am just going to explain what I am running step by step sftp user@hostname sftp > ls < when I run the command "ls" I get a long listing the old version, on the new version I get a short listing how can I change my new version to give me long listing by default (1 Reply)
Discussion started by: slufoot80
1 Replies

5. UNIX for Dummies Questions & Answers

Long listing of files using find command on remote server via SSH

Hi , I am trying to find some files on a remote machine using the find command. >ssh -q atukuri@remotehostname find /home/atukuri/ -name abc.txt /home/atukuri/abc.txt The above command works fine and lists the file, but if I want to do a long listing of files (ls -l) its not working . ... (2 Replies)
Discussion started by: atukuri
2 Replies

6. UNIX for Dummies Questions & Answers

find command -- listing files twice

I noticed the other day that after i used the find command to search for some files, the computer listed them twice -- first with just the names of the files (meaning ./(then the individual file names), then with the directory name, followed by the file names (./directory name/file name). I was... (2 Replies)
Discussion started by: Straitsfan
2 Replies

7. Shell Programming and Scripting

Find problem listing directories even -type f

Hi All, #!/bin/ksh find /home/other -ls -type f -xdev | sort -nrk7 | head -2 >bigfile.txt The above is my script, which writes the large file into a file called bigfile.txt. My script contains only the above two lines. after execution i am getting the output like find: cannot chdir to... (1 Reply)
Discussion started by: Arunprasad
1 Replies

8. Shell Programming and Scripting

find command nonrecurslu listing ls -lrt

---------------------------------------------------------------------- I have tried find . type -f -exec ls -lrt {} \; but it listed files recursively ,I need only that dir files not internal dir file. --------------------------------------------------------------------- (8 Replies)
Discussion started by: RahulJoshi
8 Replies

9. UNIX for Dummies Questions & Answers

listing year in ls command

Hi all .. As per rule i searched the forum i am not able found out ... I want to display the year in when listing the files .. when i use ls -lt it is not displaying files with recent 6 month old .. I know that perderabo has written a script for that if you give that link it will be... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

10. UNIX for Dummies Questions & Answers

Find files older than 5 days and remove tem after listing

need help with this ... Find files older than 5 days and remove tem after listing list "test" file older than 5 days and then remove them (1 Reply)
Discussion started by: ypatel6871
1 Replies
Login or Register to Ask a Question