Search:  
Gentoo Wiki

TIP_dirs_and_files_in_ls

This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

Contents

Distinguishing directories from files in ls

Normally when you type 'ls' in the console you won't be able to distinguish regular files from directories. There is more than one way to make 'ls' show the difference.

Long listing

ls -l

Each file's description will fill a line, the first character of a line shows the type:

Code: ls -l
drwxr-xr-x   10 user      users        4096 jan 1  2005 directory
-rw-r--r--    1 user      users       25721 jan 1  2005 me.jpeg
-rwxr--r--    1 user      users         325 jan 1  2005 script.sh

Classify

ls --classify or ls -F will append characters to files to show their type:

Code: ls -F
directory/         me.jpeg         script.sh*

Color

ls --color=tty

Will color the 'ls' output. Directories are blue, regular files stay black (or white) and executable files are green.

directory         me.jpeg         script.sh

Convenience

Make an Alias of your prefered method.

Example:

alias ls='ls --color=tty --classify'


List only directories

ls -d */

Will list only entries ended by a "/", and with the "-d" option, will not descend into the next level of directory.

Retrieved from "http://www.gentoo-wiki.info/TIP_dirs_and_files_in_ls"

Last modified: Fri, 05 Sep 2008 23:10:00 +0000 Hits: 15,680