Skip to content
Search

Ls

lastmod 2025-07-20created 2014-01-0827 edits

ls is one of the commands of Unix-like operating systems specified in POSIX and the Single UNIX Specification. Short for 'list segments', it is a command that displays a list of files. It is similar to the dir command in DOS.

Flags

  • ls -a: list all files including hidden file starting with '.'
  • ls --color: colored list [=always/never/auto]
  • ls -d: list directories - with ' */'
  • ls -F: add one char of */=>@| to enteries
  • ls -1: if you want one entry per line

Something like pwd can't read it.

  • Using readlink: readlink -f {symlinkName}
  • Using Python: python -c 'import os.path; print(os.path.realpath("symlinkName"))'
  • Using realpath: realpath {symlinkName}

Format

For example:

drwxr-xr-x@ 19 yourname  staff   646  2 20 08:42 gdrive

Information on each field

  • d - The first character is the file type.
    • - - Regular file
    • d - Directory
    • l - Link
    • p - named pipe (can be created with mkfifo)
  • rwxr-xr-x - File type and permission information.
    • In groups of three characters: owner permissions (Owner), group permissions (Group), anonymous permissions (Anonimouse)
    • r = Read
    • w = Write
    • x = Execute
  • @ - Whether extended information exists; see #What is at('@').
  • 19 - Number of hard links. See inode for details.
  • yourname - Owner name
  • staff - Group name
  • 646 - File size. In bytes unless the -h option is given.
  • 2 20 08:42 - File creation time unless otherwise specified.
    • If the creation time is more than six months ago, the time is omitted and the year of the file is included.
  • gdrive - File name.

What is at('@')

When using ls -l on macOS, entries marked with @ are printed as below.

yournameui-MacBook-Pro:~ yourname$ ls -l
total 8
drwx------@  3 yourname  staff   102  2  6 10:11 Applications
drwx------+  4 yourname  staff   136  2 14 15:36 Desktop
drwx------+  3 yourname  staff   102  2  6 10:00 Documents
drwx------+ 17 yourname  staff   578  2 20 09:52 Downloads
drwx------@ 62 yourname  staff  2108  2 14 08:46 Library
drwx------+  3 yourname  staff   102  2  6 10:00 Movies
drwx------+  3 yourname  staff   102  2  6 10:00 Music
drwx------+  3 yourname  staff   102  2  6 10:00 Pictures
drwxr-xr-x  26 yourname  staff   884  2 17 14:23 Project
drwxr-xr-x+  5 yourname  staff   170  2 10 12:47 Public
drwxr-xr-x   3 yourname  staff   102  2 10 12:44 bin
drwxr-xr-x@ 19 yourname  staff   646  2 20 08:42 gdrive
-rw-r--r--   1 yourname  staff  2268  2 13 12:28 java0.log
drwxr-xr-x  28 yourname  staff   952  2 14 16:31 torch

This can be found in the man page as below.

If the -l option is given, the following information is displayed for each file: 
file mode, number of links, owner name, group name, number of bytes in the file, abbreviated month, day-of-month file was last modified, hour file last modified, minute file last modified, and the pathname.
In addition, for each directory whose contents are displayed,
the total number of 512-byte blocks used by the files in the directory is displayed on a line by itself,
immediately before the information for the files in the directory.

If the file or directory has extended attributes, the permissions field printed by the -l option is followed by a '@' character.
Otherwise, if the file or directory has extended security information (such as an access control list),
the permissions field printed by the -l option is followed by a '+' character.

In short, the character is printed when extended attributes exist. To see the extended attributes, add the -@ option.

yournameui-MacBook-Pro:~ yourname$ ls -l@
total 8
drwx------@  3 yourname  staff   102  2  6 10:11 Applications
    com.apple.quarantine      25
drwx------+  4 yourname  staff   136  2 14 15:36 Desktop
drwx------+  3 yourname  staff   102  2  6 10:00 Documents
drwx------+ 17 yourname  staff   578  2 20 09:52 Downloads
drwx------@ 62 yourname  staff  2108  2 14 08:46 Library
    com.apple.FinderInfo      32
drwx------+  3 yourname  staff   102  2  6 10:00 Movies
drwx------+  3 yourname  staff   102  2  6 10:00 Music
drwx------+  3 yourname  staff   102  2  6 10:00 Pictures
drwxr-xr-x  26 yourname  staff   884  2 17 14:23 Project
drwxr-xr-x+  5 yourname  staff   170  2 10 12:47 Public
drwxr-xr-x   3 yourname  staff   102  2 10 12:44 bin
drwxr-xr-x@ 19 yourname  staff   646  2 20 08:42 gdrive
    com.apple.FinderInfo      32
-rw-r--r--   1 yourname  staff  2268  2 13 12:28 java0.log
drwxr-xr-x  28 yourname  staff   952  2 14 16:31 torch

Add Color to the Terminal

To apply colors to the ls command, proceed as follows.
To apply it automatically in bash, first create a .bash_profile file in your home directory.
Then add the environment variables as below.

export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

See also

Favorite site

References


  1. Ls_command_manual.pdf ↩

author Zer0 sitemap