18

When I cd to / and enter the command:

ls -ls

for some files/folders it gives output like:

0 lrwxrwxrwx.   1 root   root         7 Jan 30  2018 bin -> usr/bin

So what actually is this lrwxrwxrwx?

idaljeetsingh
  • 185
  • 1
  • 2
  • 8
  • 4
    @Kulfy I think the fact that OP provided ls -l in their question suggests they already know how to view permissions. They're more interested in the meaning of the output in this particular case of symlinks. So I don't think that's an appropriate duplicate – Sergiy Kolodyazhnyy Jan 03 '19 at 23:48
  • @Serg g_p's answer has the info OP is looking for, but I agree it's not a duplicate question. – wjandrea Jan 04 '19 at 01:10
  • @Serg The dup Q&A is generically orientated on meaning of permissions. If a question of lwrxwrxwrx (see /vmlinuz) like this is unique, would a question of dwrxwrxwrx (see /tmp/) be unique as well? If each combination of permissions is a unique question we can have untold number of what could be considered psuedo-dups. For example *"What does permissions of dr-xr-xr-x for /proc directory mean"?*. – WinEunuuchs2Unix Jan 04 '19 at 01:42
  • 2
    @WinEunuuchs2Unix While I agree the dup is general and should cover wide range, including this one, this question happens to talk about specific file type and the set of permissions lrwxrwxrwx is typical to all symlinks, which Zanna's answer covered very well in detail. If you feel like this should be covered in the linked dup, feel free to either post an answer or edit the existing ones there. – Sergiy Kolodyazhnyy Jan 04 '19 at 01:47
  • @SergiyKolodyazhnyy Then it opens the door to another potential dup *"What is a symbolic link?"* or *"What does l mean in permissions*". As for me posting an answer on dup I respectfully decline on the grounds Zanna would do a much better job and would deserve the credit of porting her answer over there with any minor tweaking that might be required... In any respect I think there could be a generic Q&A on what the file control field means including symoblic links, hard links, (root, group, user) permissions, pipes, sockets and what not that can appear in the file control field. – WinEunuuchs2Unix Jan 04 '19 at 02:02
  • 1
    @WinEunuuchs2Unix That's a slippery slope fallacy. The purpose of the duplicates is to provide appropriate information, not cover everything, nor they are meant to prevent people from asking similar questions. I've already expressed my opinion - Zanna's post here does better job than what's covered in the link, and the questions differ somewhat. The rest may the community decide – Sergiy Kolodyazhnyy Jan 04 '19 at 02:10
  • @SergiyKolodyazhnyy I agree on community deciding. Mods can step in and merge if need be. I DO like Zanna's answer :) – WinEunuuchs2Unix Jan 04 '19 at 02:20
  • @SergiyKolodyazhnyy Actually i thought the same what wjandrea mentioned but was still doubtful. So I just casted a vote and let the community decide about the fate of the question. Nonetheless, I've casted my reopen vote :) – Kulfy Jan 04 '19 at 06:05

2 Answers2

23

The leading l indicates that this file is a symlink, in contrast to - which indicates a regular file, d which indicates a directory, and other less common prefixes.

A symlink is type of file which only contains a link to another file. Reading a symlink reads the real file. Writing to a symlink writes to the real file. cding to a symlink that is to a directory results in behaviour almost identical to what would happen if you had cd'd into the real directory.

The permission bits are displayed as rwxrwxrwx. All symlinks show these bits, but they are "dummy permissions". The actual (or effective) permissions of a symlink are the permissions of the real file it links to. You can get the real permissions (and file type) by running stat on the symlink, for example:

$ stat -Lc '%a %A' /initrd.img
644 -rw-r--r--
  • stat read file metadata
  • -L dereference (follow) symlinks
  • -c select output according to specified string
  • %a octal permissions
  • %A "human readable" permissions
Zanna
  • 70,465
  • 1
    No need to use readlink, just use option -L to dereference symlinks. You can do stat -L or ls -L. – wjandrea Jan 03 '19 at 19:36
  • 2
    ls also has a -L option to follow the link. – Barmar Jan 03 '19 at 20:06
  • @Barmar good point :) – Zanna Jan 03 '19 at 20:08
  • The actual permissions of a symlink are the permissions of the real file it links to. Um, not quite. This needs to be reworded. Symlinks are symlinks - you already mentioned they show dummy permissions that all symlinks show, and actual file is different from symlink. Nonetheless, good and detailed answer. +1'ed already – Sergiy Kolodyazhnyy Jan 03 '19 at 23:46
2

The ls -sl command

The Linux command ls = List of files in the directory you are in

The added switch -sl = print short list

The resulting this example part of the output: lrwxrwxrwx

In my shortest explanation would be: The first letter will usually be either: l, d, or -:

l = Link to another file

d = a directory

- = file

r = read permission - Read the file

w = write permission - Write or edit the file

x = execute permission He can execute the file

- = no permission

Number  Permission Type            `Symbol`
0         No Permission             `---`
1         Execute                   `--x`
2         Write                     `-w-`
3         Execute + Write           `-wx`
4         Read                      `r--`
5         Read + Execute            `r-x`
6         Read + Write              `rw-`
7         Read + Write + Execute    `rwx`

In Summary: The file type and access and Permissions the Ownership, and User; privileges such as Read and/or Write for each directory or file that is listed in the output.

a l for a link , d for a directory or - for a file and these are set by the Linux operating system. You can not manually change these letters (unless you change the file type of course). (ie... lrwxrwxrwx 1 root root 1024 Feb 13 09:45 myfile3)

Please refer to: http://earthen.tripod.com/linuxper.htmPermissions (Setting up the modes)

~ Samuel F Campbell