find command listing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find command listing
# 1  
Old 10-23-2012
Network find command listing

Hello,

I have been trying to understand how the 'find' command lists the search results. I have a list of songs in different file formats (mp3, wav, aac etc) in a huge directory hierarchy organized by genre and am trying to get the list of all songs of a particular format.

I found ls -R command to be of no use, here (very surprisingly) and so tried the above set of commands

Cd to the top level 'Music' Directory first and then find command as follows:-

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

I expected the results to be displayed in alphabetical order and accordingly the first few entries came like this :

Code:
./English music/Savage Garden/Animal Song.WAV
./English music/Savage Garden/To the moon and back.WAV
./English music/Savage Garden/Truly Madly Deeply.WAV
./English music/U2/Original Of the species.WAV
...

Then suddenly in another directory, a very strange thing happened. It started displaying the result in a radom order (or so it appears)

Code:
./Hindi Music/Mere pass Tu Hai.WAV
./Hindi Music/Nach Le-Daler Mehndi.WAV
./Hindi Music/Nusrat Fateh Ali Khan-Afreen.WAV
./Hindi Music/Pal-KK.WAV
./Hindi Music/Kaawa Kaawa-Monsoon Wedding.WAV
./Hindi Music/Piya Haji Ali-Nusrat Fateh Ali Khan.WAV
./Hindi Music/Baazigar Title Track.WAV
./Hindi Music/Carol-Unknown.WAV
./Hindi Music/Dekh Le-Munnabhai MBBS.WAV

How can a filename starting with the letter D come "after" the filename starting with letter N. So if its not alphabetical order, then what is it ? I am at a loss to understand this .

Could someone please clarify ?
# 2  
Old 10-23-2012
find reads the directory file(s). The order you see is the order they are physically stored in the directory.
# 3  
Old 10-25-2012
Physically stored

Hello,

Could you please confirm waht you mean by "order in which they are physically stored in the directory ? Because if you read the directory listing, you will still read it in an alphanumeric order.
# 4  
Old 10-26-2012
Quote:
Originally Posted by ajayram
Hello,

Could you please confirm what you mean by "order in which they are physically stored in the directory ? Because if you read the directory listing, you will still read it in an alphanumeric order.
Reading "the directory listing" is not the same thing as reading "the directory".

The ls utility (which produces a directory listing) sorts its output by filename by default. It will also produce listings that are sorted by file size, by one of the three time stamps on the file, or unsorted depending on the options you give to ls. If you use the commandls -lfyou will get a list of files in the current directory in long format listed in the order in which those files appear in the directory (i.e., unsorted).
# 5  
Old 10-26-2012
Still alphabetical order

Hello,

I ran ls -lf on the directory which was giving some random order reading as processed by find

Code:
ajayram@pc13:/media/HITACHI/Music/Hindi Music$ ls -1f *.WAV
Aaja re-Bend It Like Beckham.WAV
Baazigar Title Track.WAV
Carol-Unknown.WAV
Dekh Le-Munnabhai MBBS.WAV
Dil Nahin Lagta-Nusrat Fateh Ali Khan.WAV
Do Dil Mil Rahein Hain-Pardes.WAV
Gurus Of Peace.WAV
Jaan Leva.WAV
Jal Jal Ke-Sonu Nigam.WAV
Janabeali-Unknown.WAV
Jheelon Ka Sheher-Mission Kashmir.WAV
Kaawa Kaawa-Monsoon Wedding.WAV
Kaho Na Kaho-Murder.WAV
Mere pass Tu Hai.WAV
Nach Le-Daler Mehndi.WAV
Nusrat Fateh Ali Khan-Afreen.WAV
Pal-KK.WAV
Piya Haji Ali-Nusrat Fateh Ali Khan.WAV
Shaan-Take me to the heart.WAV
Tishnagi-Shaan.WAV
Tum mere Bahon me Aan na sake.WAV

Again I find that ls -1f gives the alphabetical order of filenames, whereas if you see my earlier post, find command gives some random order.. Could someone clarify this ?
# 6  
Old 10-26-2012
I said to run ls with the l (letter 'l', not digit '1') and f options with no operands. However, using either -1f or -lf will be fine. But, by specifying a globbing pattern as an operand to ls, the shell that invoked ls expanded *.WAV into a sorted list of filenames before calling ls. It will also work as I intended if you specify one or more operands that are the pathnames of files of type directory.

I repeat: run the command ls -lf(with no file operands) in a directory in which find reported .WAV files that were not in sorted order. It won't produce a listing of just .WAV files and it won't search subdirectories, but it will give you a listing of all files in that directory in unsorted directory order.

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.

Since you didn't quote *.WAVI also have to assume that there were either no .WAV files or only one .WAV files in that directory. Otherwise, the shell would have expanded *.WAV and would have generated another syntax error in find.
# 7  
Old 10-26-2012
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).

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