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!

Re: How Linux Differentiates Between A File or Folder 80 80

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.

Re: How Linux Differentiates Between A File or Folder 80 80

We can just move it :)

Re: How Linux Differentiates Between A File or Folder 80 80

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.

Re: How Linux Differentiates Between A File or Folder 80 80

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.

Re: How Linux Differentiates Between A File or Folder 80 80

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

Unix Filesystem Organization

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.