Sort Contents by File Extension


ls -X

The name of a file is not the only thing you can use for alphabetical sorting. You can also sort alphabetically by the file extension. In other words, you can tell ls to group all the files ending with .doc together, followed by files ending with .jpg, and finally finishing with files ending with .txt. Use the -X option (or --sort=extension); if you want to reverse the sort, add the -r option (or --reverse).

$ ls -lX ~/src drwxr-xr-x     320 2005-10-06 22:35 backups drwxr-xr-x    1336 2005-09-18 15:01 fonts -rw-r--r-- 2983001 2005-06-20 02:15 install.tar.gz -rw-r--r-- 6683923 2005-09-24 22:41 DuckDoom.zip 


Folders go first in the list (after all, they have no file extension), followed by the files that do possess an extension. Pay particular attention to installdata.tar.gzit has two extensions, but the final one, the .gz, is what is used by ls.



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net