Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am a bit confused on what a directory really is. In various places I read that in Linux directories are just strings that keep the names of the nested files. In that case is there a way to show excactly the contents of a directory just as we would by using cat file?

I would like a way to do cat . and then I would expect to get something like this:

\STARTfile1\0file2\0\END
share|improve this question

migrated from stackoverflow.com Oct 7 '11 at 0:07

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 2 down vote accepted

In Linux filesystems, basically "everything is an 'inode".

A "file" is a named set of inodes that contain data.

A "directory" contains lists of files.

The SAME inodes may be shared by DIFFERENT files. In other words, the SAME file (perhaps in a different directory) can have MULTIPLE names.

These links might help clarify:

PS: Perhaps you're interested in the "readdir()" API:

http://linux.die.net/man/3/readdir

share|improve this answer
    
+^ this is probably way more useful of an answer then my vi idea ). –  chown Oct 5 '11 at 18:30
    
Thanks! I also read those links and they were helpful :) –  Pithikos Oct 8 '11 at 10:53

Something to consider is that vi will show a directory listing if you vi [DIR]:

vi /home/jon/

Gives:

" ============================================================================
" Netrw Directory Listing                                        (netrw v102)
"   /home/jon
"   Sorted by      name
"   Sort sequence: [\/]$,*,\.bak$,\.o$,\.h$,\.info$,\.swp$,\.obj$
"   Quick Help: <F1>:help  -:go up dir  D:delete  R:rename  s:sort-by  x:exec
" ============================================================================
../
./
.fontconfig/
.ipython/
.matplotlib/
.pip/
.pylint.d/
.python-eggs/
.ssh/
.subversion/
.vim/
Python-2.7.1/
acl/
backup/
cron/
mqueue/
public_html/
python26/
reporter/
repos/
scripts/
test/
.Xauthority
.Xresources
.bash_history
.bash_logout
.bash_profile
.bashrc
.csshrc
.lesshst
.mysql_history
.pylintrc
.screenrc
.smblogin
.sqlite_history
.toprc
.viminfo
.vimrc
csshrc.back
mbox
test.cpp
test.py
test.tar.gz
testIt.py
testite
test.o
share|improve this answer
1  
Yes, but that's a far cry from saying "Linux directories are just strings that keep the names of the nested files." They aren't. Which is why "cat ." doesn't work ;) –  paulsm4 Oct 5 '11 at 18:26
    
@paulsm4 You are absolutely correct. I didn't intend for my answer to sound like it was confirming his inaccurate assumption on that =). –  chown Oct 5 '11 at 18:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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