ls -la we get the list of files in the current directory, with symlinks having also their target files printed.
When displaying a symlink, the shell prints the attributes (and particularly, the date) of the symlink itself.
Is there an option to print the attributes of the target?
-dLl to ls.
ls do show target.
-d tells it to not enter a directory (only makes a difference if the file is a directory).
-l says to do a long list (with detail).
Correct answer by ctrl-alt-delor on January 2, 2021
Most system calls and applications, when given the path of a symlink, do perform their operation on the target of the symlink. Notable exceptions are the ones that operate on directory entries rather than files such as
When it comes to getting file metadata information, there are two separate system calls:
lstat() (operate on symlink itself),
stat() (operate on target of symlink). With the newer
statx() on Linux, that's with a
AT_SYMLINK_NOFOLLOW flag instead. See also
lgetxattr() for extended attributes.
And when it comes to utilities that wrap those, the default depends on the utility, and the option if any to change the mode of operation also depends on the implementation.
ls by default, operates on the target of the file given as argument, unless passed any of the
-n options, in which case it operates on the symlink itself (uses
lstat() instead of
stat() or uses
statx() with the
If you want to use one of those options but still want to follow symlinks, you can pass the
ls -ldH -- "$file"
Will report information about the file after symlink resolution.
ls also has a
-L option which tells it to resolve all symlinks, not only those for the files given as argument. For instance,
ls -Ll /symlink-to-dir would resolve
/symlink-to-dir to the directory it links to, and list its contents, and for each symlink in there, would also list the information at the target of the links. It also affects how recursion is done with
For other tools:
Command | default | change with ----------------------+-----------+-------------- IRIX stat | target | -L zsh stat | target | -L GNU stat | symlink | -L BSD stat | symlink | -L busybox stat | symlink | -L AIX istat | target | none GNU date -r | target | none GNU find -printf | symlink | -follow/-L/-H Linux attr | symlink | -L Linux getfattr | target | -h Linux getfacl | target | -P
Some examples, for the modification time specifically:
$ date -r link +%FT%T.%N%z # GNU date 2020-03-19T17:57:11.277584965+0000 $ zmodload zsh/stat $ stat -F %FT%T.%N%z +mtime link 2020-03-19T17:57:11.277584965+0000 $ gstat -Lc %y link # GNU stat 2020-03-19 17:57:11.277584965 +0000 $ ls -lHd --full-time link # GNU ls drwxr-xr-x 23 root root 29 2020-03-19 17:57:11.277584965 +0000 link/ $ find -H link -prune -printf '%TFT%TT%Tzn' # GNU find 2020-03-19T17:57:11.2775849650+0000
Answered by Stéphane Chazelas on January 2, 2021
1 Asked on February 10, 2021
0 Asked on February 10, 2021 by divb
0 Asked on February 10, 2021 by coffeecatde
1 Asked on February 9, 2021 by luwachamohh
1 Asked on February 9, 2021 by isarandi
2 Asked on February 8, 2021 by nanor
9 Asked on February 8, 2021
2 Asked on February 7, 2021 by prisoner-13
1 Asked on February 7, 2021 by chiseledabs
1 Asked on February 6, 2021 by linuxsecurityfreak
0 Asked on February 6, 2021
1 Asked on February 5, 2021 by robert-einsle
3 Asked on February 5, 2021 by s55michi
0 Asked on February 5, 2021 by modernneo
1 Asked on February 5, 2021 by perimosh
1 Asked on February 5, 2021 by pro-backup
Get help from others!