954,234 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How Linux Differentiates Between A File or Folder

Hey Guys,


I am trying to figure out how Linux determines whether an object in directory is a file or folder. There's got to be a property (I am guessing in Stat) that Linux references from which lets it know quickly. It's hard to find information on google because when you enter a query like "how linux differentiates between file folder" you get a lot of tutorials on what physically makes them different which is annoying :P.


Thanks!

BLUEC0RE
Light Poster
40 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

Hmm, I am starting to think this should have been posted in the Kernel forums. My apologizes. I would delete it and repost it but can find the deletion button.

BLUEC0RE
Light Poster
40 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

We can just move it :)

Ezzaral
Posting Genius
Moderator
15,985 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

I don't know too many of the internals of Linux (not as many as I'd like). But if you run the ls -a -l command in a directory, you see complete information on the listed files. In the file permissions part of the listing for each item, the first property indicates whether a listed item is a file or a directory. For files there is a dash - (flag not set). For directories it's d (flag set). The other flags rwxrwxrwx relate to the items read/write/execute privileges for the owner, members of the owners group and all other users. So there's at least a flag that gets set.
I don't know much more than that.

JasonHippy
Master Poster
769 posts since Jan 2009
Reputation Points: 590
Solved Threads: 125
 

I natively run slackware so my command prompt is in color. So blue is folder, red is compressed file, green is executable, white is just a general file (script, or text file.) etc.... If I find myself on another linux platform that doesn't natively differentiate I do "ls --color=always" or "dir --color=always." Don't have much experience with ubuntu or debian, I know it works on redhat and redhat clones. I assume ubuntu or debian isn't much different. You could always ls --help or dir --help it to see how its set up for your flavor.

reversefiction
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

Have a look at this, which covers the basic pretty well

Unix Filesystem Organization

shibblez
Junior Poster in Training
72 posts since Oct 2010
Reputation Points: 15
Solved Threads: 6
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: