How can I tell which ones are directories in ls output? It seems ls doesn't differentiate directories and files. I know I can use cd to test but is there a way to make it more obvious when I ls a pth? PS: I have one Debian 5.0.9 server which uses different colors to show directories and files. But another Debian 6.0.4 server doesn't do it.

  • 2
    Adding this to bash profile solved the problem alias ls='ls --color=auto' – sdaffa23fdsf Apr 9 '12 at 0:14
  • You can type: file filename. This is not ls but just wanted to put it out there. – user122530 Apr 9 '12 at 3:10
  • ls -G, and then subsequently alias ls='ls -G' did it for me. I'm using a bash shell and OSX. I'd suggest running man ls and look for a color option if neither of these work for you. – Peter Berg Jul 15 '14 at 20:42

ls -l or ls -F; the former gives full information, the latter tacks on a suffix which indicates the type of filesystem object.

  • Thank you. ls -F does the job. What's the second column in ls -l output? I notice files generally have 1 in this field while folders have 2. But I see other numbers 4,5,8... I don't know what this field means. – sdaffa23fdsf Apr 8 '12 at 23:50
  • Number of hard links. People don't often use them these days, so it's usually 1 for on-directories; for directories on local Unixlike filesystems, it's 2 + the number of subdirectories (the additional 2 being for the . and .. entries); what it means for network and non-Unix-native filesystems depends on the filesystem. – geekosaur Apr 8 '12 at 23:54

If you use bash, it will color code directories differently than files.

  • I am using bash on both servers – sdaffa23fdsf Apr 8 '12 at 23:44
  • Oh. Then try ls --color=auto If you like that, alias ls to that command. – Scott C Wilson Apr 9 '12 at 0:17
  • My favorite: alias ls='ls -F --color=auto' – Code Novice Jul 7 '19 at 19:24

If you prefer to use colors you can force it to by setting the force_colors variable to true in the /etc/profile (or /etc/bash_profile). It depends on whether or not they think your terminal supports colors. Since most do these days it won't hurt to force it.

You could also do it yourself by putting this in your ~/.bashrc:

alias ls='ls --color=auto'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.