views:

62

answers:

2

The code should sort the files in the given directory like the "ls" command.

Please find exact details below:- File name in alphabetical order, size, mod time. The sort should continue if there is a sub directory.

Please reply to this post. Its a bit urgent.

Thanks,

A: 

It's not working but it's an idea

 ls -alR | sort -k1 -n | sort -k6 -n | sort -kOTHER -n 
  • ls -laR : ls in subdirectories
  • sort -k1 -n : order the list in function of the first column (in this case, the name of file)
  • sort -k6 -n : order the list in function of the sixthcolumn (in this case, the size) sort -kOTHER -n :order the list in function of the sixth column (in this case, the mod time: sorry I don't remember). I know there's there are more column: you have to aggregate them.

Sorry but I can't test and develop my idea :(

alepuzio
+1  A: 

A simple script combining the find and awk (or related, perl, ruby, etc.) utilities should suffice.

For example, on Mac OS X, the following command-line gets you pretty much there:

find . -ls | awk '{printf("%s\t%s\t%s %s %s\n", $11, $7, $8, $9, $10)}' | sort

See the man page for find on your system and an awk tutorial.

maerics