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
?
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
?
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. cd
ing 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" permissionsreadlink
, just use option -L
to dereference symlinks. You can do stat -L
or ls -L
.
– wjandrea
Jan 03 '19 at 19:36
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
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
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:48lwrxwrxwrx
(see/vmlinuz
) like this is unique, would a question ofdwrxwrxwrx
(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 ofdr-xr-xr-x
for/proc
directory mean"?*. – WinEunuuchs2Unix Jan 04 '19 at 01:42lrwxrwxrwx
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:47l
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