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 have a problem with listing of some directory with ls -l:

$ ls -l ./directory
-????????? ? ? ? ?            ? file001.txt
-????????? ? ? ? ?            ? file002.txt

and just ls works good:

$ ls ./directory
file001.txt file002.txt

What is wrong?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Check the permissions of ./directory : if you have read permissions but not execute permissions on this directory, then you have enough rights to read the list of files in that directory, but you can't actually use these files or get information about them.

example session:

$ cd /tmp/
$ mkdir /tmp/test
$ touch /tmp/test/file
$ ls -la test/
total 44
drwxr-xr-x  2 myself myself  4096 janv.  5 11:01 .
drwxrwxrwt 42 root   root   54242 janv.  5 11:01 ..
-rw-r--r--  1 myself myself     0 janv.  5 11:01 file
$ chmod a-x /tmp/test # remove execute permission for all
$ ls -la test/
total 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..
-????????? ? ? ? ?            ? file
$ ls -ld test/
drw-r--r-- 2 myself myself 4096 Jan  5 11:01 test/
$ cat test/file 
cat: test/file: Permission denied
$ chmod a+x /tmp/test # readd execute permission for all
$ ls -la test/
total 44
drwxr-xr-x  2 myself myself  4096 janv.  5 11:01 .
drwxrwxrwt 42 root   root   54242 janv.  5 11:01 ..
-rw-r--r--  1 myself myself     0 janv.  5 11:01 file
$ ls -ld test/
drwxr-xr-x 2 myself myself 4096 Jan  5 11:01 test/
$ cat test/file
$

Some ls versions show error messages when they can't display information about files.

share|improve this answer
    
But how ls can know, is the file inside test directory or not (check d char for '.' and '..')? –  osgx Jan 5 '13 at 10:18
    
@osgx: This is part of the file list, with the file name and the inode number. man readdir for more low-level detail. Note that this behaviour is not specified by POSIX. –  BatchyX Jan 5 '13 at 13:23

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.