in shell how can I tell the difference between a directory and a file

4

2

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.

sdaffa23fdsf

Posted 2012-04-08T23:29:49.997

Reputation: 280

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 – 2014-07-15T20:42:04.760

2Adding this to bash profile solved the problem alias ls='ls --color=auto' – sdaffa23fdsf – 2012-04-09T00:14:55.597

You can type: file filename. This is not ls but just wanted to put it out there. – None – 2012-04-09T03:10:14.817

Answers

3

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

geekosaur

Posted 2012-04-08T23:29:49.997

Reputation: 10 195

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 – 2012-04-08T23:50:00.580

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 – 2012-04-08T23:54:41.360

0

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

Scott C Wilson

Posted 2012-04-08T23:29:49.997

Reputation: 2 210

My favorite: alias ls='ls -F --color=auto' – Code Novice – 2019-07-07T19:24:43.547

I am using bash on both servers – sdaffa23fdsf – 2012-04-08T23:44:32.427

Oh. Then try ls --color=auto If you like that, alias ls to that command. – Scott C Wilson – 2012-04-09T00:17:42.867

0

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'

Keith

Posted 2012-04-08T23:29:49.997

Reputation: 7 263