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
link|improve this question
feedback

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

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

2 Answers

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

link|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
feedback

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
link|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
feedback

Your Answer

 
or
required, but never shown

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