404

I know that using ls -l "directory/directory/filename" tells me the permissions of a file. How do I do the same on a directory?

I could obviously use ls -l on the directory higher in the hierarchy and then just scroll till I find it but it's such a pain. If I use ls -l on the actual directory, it gives the permissions/information of the files inside of it, and not of the actual directory.

I tried this in the terminal of both Mac OS X 10.5 and Linux (Ubuntu Gutsy Gibbon), and it's the same result. Is there some sort of flag I should be using?

codeforester
  • 39,467
  • 16
  • 112
  • 140
user42228
  • 4,085
  • 2
  • 17
  • 5

10 Answers10

520

Here is the short answer:

$ ls -ld directory

Here's what it does:

-d, --directory
    list directory entries instead of contents, and do not dereference symbolic links

You might be interested in manpages. That's where all people in here get their nice answers from.

refer to online man pages

TheoKanning
  • 1,631
  • 11
  • 20
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
  • 27
    I think the man page is poorly worded. I scoured it five times before I started googling. I don't want directory 'entries' (thing 'entered' into directories? Like their files and sub-directories?) nor their 'contents' (they sound like the same concept to me), I want the directories *themselves*. – user151841 Jul 27 '12 at 13:23
  • 2
    it's completely standard terminology, the directories _themselves_ are the directory entries, i.e. entries in the filesystem – alldayremix Apr 13 '13 at 17:12
  • 45
    It may be standard terminology, but to someone who would likely be asking such a question, it is probably confusing jargon. – CatShoes Jun 20 '13 at 11:57
73

You can also use the stat command if you want detailed information on a file/directory. (I precise this as you say you are learning ^^)

Piotr Lesnicki
  • 9,442
  • 2
  • 28
  • 26
49
$ ls -ld directory

ls is the list command.

- indicates the beginning of the command options.

l asks for a long list which includes the permissions.

d indicates that the list should concern the named directory itself; not its contents. If no directory name is given, the list output will pertain to the current directory.

Mehul Jariwala
  • 886
  • 1
  • 9
  • 19
22

In GNU/Linux, try to use ls, namei, getfacl, stat.

For Dir

[flying@lempstacker ~]$ ls -ldh /tmp
drwxrwxrwt. 23 root root 4.0K Nov  8 15:41 /tmp
[flying@lempstacker ~]$ namei -l /tmp
f: /tmp
dr-xr-xr-x root root /
drwxrwxrwt root root tmp
[flying@lempstacker ~]$ getfacl /tmp
getfacl: Removing leading '/' from absolute path names
# file: tmp
# owner: root
# group: root
# flags: --t
user::rwx
group::rwx
other::rwx

[flying@lempstacker ~]$ 

or

[flying@lempstacker ~]$ stat -c "%a" /tmp
1777
[flying@lempstacker ~]$ stat -c "%n %a" /tmp
/tmp 1777
[flying@lempstacker ~]$ stat -c "%A" /tmp
drwxrwxrwt
[flying@lempstacker ~]$ stat -c "%n %A" /tmp
/tmp drwxrwxrwt
[flying@lempstacker ~]$

For file

[flying@lempstacker ~]$ ls -lh /tmp/anaconda.log
-rw-r--r-- 1 root root 0 Nov  8 08:31 /tmp/anaconda.log
[flying@lempstacker ~]$ namei -l /tmp/anaconda.log
f: /tmp/anaconda.log
dr-xr-xr-x root root /
drwxrwxrwt root root tmp
-rw-r--r-- root root anaconda.log
[flying@lempstacker ~]$ getfacl /tmp/anaconda.log
getfacl: Removing leading '/' from absolute path names
# file: tmp/anaconda.log
# owner: root
# group: root
user::rw-
group::r--
other::r--

[flying@lempstacker ~]$

or

[flying@lempstacker ~]$ stat -c "%a" /tmp/anaconda.log
644
[flying@lempstacker ~]$ stat -c "%n %a" /tmp/anaconda.log
/tmp/anaconda.log 644
[flying@lempstacker ~]$ stat -c "%A" /tmp/anaconda.log
-rw-r--r--
[flying@lempstacker ~]$ stat -c "%n %A" /tmp/anaconda.log
/tmp/anaconda.log -rw-r--r--
[flying@lempstacker ~]$
15

There is also

getfacl /directory/directory/

which includes ACL

A good introduction on Linux ACL here

Taylan
  • 3,045
  • 3
  • 28
  • 38
10

This displays files with its permisions

stat -c '%a - %n' directory/*
Brandon Aguilar
  • 389
  • 6
  • 14
  • `stat` is a gnu coreutil that [isn't available on all unix-like systems](https://unix.stackexchange.com/questions/287008/stat-command-not-found) \(such as Solaris < 11\). – Mavaddat Javid Aug 02 '23 at 23:54
5

On OS X you can use:

ls -lead

The e option shows ACLs. And ACLs are very important to knowing what the exact permissions on your system are.

Tony Topper
  • 402
  • 6
  • 14
5

In addition to the above posts, i'd like to point out that "man ls" will give you a nice manual about the "ls" ( List " command.

Also, using ls -la myFile will list & show all the facts about that file.

Filip Ekberg
  • 36,033
  • 20
  • 126
  • 183
2

ls -lstr

This shows the normal ls view with permissions and user:group as well

0

To check the permission configuration of a file, use the command:

ls –l [file_name]

To check the permission configuration of a directory, use the command:

ls –l [Directory-name]
Aslam Khan
  • 382
  • 2
  • 2
  • this is not the right answer, it should be -ld, as indicated in below anwser – fanny Nov 02 '20 at 00:20
  • It's work fine for me . i have set (assets) folders permission using these command, – Aslam Khan Nov 02 '20 at 07:12
  • hmmm... but as the OP has stated: "If I use ls -l on the actual directory, it gives the permissions/information of the files inside of it, and not of the actual directory". I think OP wanted to know the permissions of a FOLDER not the FILES in it. – fanny Nov 02 '20 at 10:55