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:-
I expected the results to be displayed in alphabetical order and accordingly the first few entries came like this :
Then suddenly in another directory, a very strange thing happened. It started displaying the result in a radom order (or so it appears)
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 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.
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).
I ran ls -lf on the directory which was giving some random order reading as processed by find
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 ?
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:
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.
[...]
Also note that the find command you provided in your 1st posting on this thread:
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):
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)
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)
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)
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)
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)
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)
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)
----------------------------------------------------------------------
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)
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)