ls Command Examples
The ls command in Linux is one of the most used commands. But most people don't utilize its full potential. Check out the basics as well as advanced ls command examples in Linux.
The ls
command is one of the first commands we learn when discovering the shell. And after that, whatever is your skill level, it will remain one of the most often used.
Despite that popularity, we rarely go beyond the -l
, -d
and -a
options. It is unfortunate since a typical ls
implementation has tens of options available! I, therefore, propose you to follow me in my search for the ls
command hidden gems.
Sample file hierarchy we use in this ls command guide
Before getting to the heart of the matter, we need a little bit of preparation: it would be hard to study the ls
command without some directory to work on. So that you will be able to try on your computer the commands given in this article, here is how to create the sample file hierarchy I will use in all my examples. Just copy-paste that list of commands to your terminal, and you will be ready:
mkdir ls
cd ls
# Create a hidden file:
echo You can not see me > .hidden
# Create a couple of 2MiB files:
dd if=/dev/zero of=a bs=1M count=2
dd if=/dev/zero of=b bs=1M seek=1 count=1
# Create few sub-directories
mkdir -p dir/subdir dir/subdir2
# Create a bunch of empty files
touch c dir/{d,e,f} dir/subdir/{g,h,i} dir/subdir2/{j,k,l}
# Create few links (hard and symbolic)
ln dir/e hardlink-to-file
ln -s dir/f symlink-to-file
ln -s dir/subdir symlink-to-subdir
If you have any trouble with these commands, don’t hesitate to use the comment section to ask for some help. Assuming now everything is in order, it is time to dive into our main topic.
The well-known use cases of ls command
As every journey starts with a first step, let’s review first the very basic use cases for the ls
command. Of course, if you consider yourself as an expert, feel free to jump immediately to the more advanced sections. But if you prefer staying with me for now, great: you might learn a thing or two!
<no option>
: the default behavior
The ls
command gives information about each file-like objects pointed by the paths given on the command line. When used without any option:
- the only information displayed is the name of the file-like object pointed by the path;
- if that path points to a directory (or symbolic link to a directory), the
ls
command also lists the content of that directory; - if several entries are displayed, they are sorted in the alphabetical order of their filename.
Finally, when no path is given on the command line, the ls
commands assumes ./
–that is the current directory.
Let see now all those rules in action:
# display the content of the current directory
sh:~/ls$ ls ./
a c e hardlink-to-file symlink-to-file
b dir f link-to-subdir symlink-to-subdir
# without any option, `ls` is equivalent
# to `ls ./`
sh:~/ls$ ls
a c e hardlink-to-file symlink-to-file
b dir f link-to-subdir symlink-to-subdir
# entries are sorted alphabetically
# ("dir/f" starts with a "d" so it is before "e")
sh:~/ls$ ls c b e dir/f a
a b c dir/f e
# when a command line argument is a directory
# (or a symbolic link to a directory)
# displays its content
sh:~/ls$ ls a b c link-to-subdir dir
a b c
dir:
d e f subdir subdir2
link-to-subdir:
g h i
-d
: do not list directory content
With the -d
option, ls
no longer displays the content of the directory given on the command line but instead will treat directory entries just like file entries. Let’s compare:
# Default behavior: display the content of the `dir` directory
sh:~/ls$ ls a dir b
a b
dir:
d e f subdir subdir2
# `-d` option: directories are handled like files
sh:~/ls$ ls -d a dir b
a b dir
When using the -d
option alone, there isn’t much difference between ls
and a plain echo
command:
# In both case, the `*` glob pattern is expanded by
# the shell, which also takes care of
# sorting entries in the alphabetical order
sh:~/ls$ ls -d *
a b c dir hardlink-to-file symlink-to-file symlink-to-subdir
sh:~/ls$ echo *
a b c dir hardlink-to-file symlink-to-file symlink-to-subdir
But the -d
option becomes more useful when associated with another option to display extra information, like when using the -l
flag we will see now.
-l
: the long format option
In the ls
options popularity contest, the -l
(lowercase ell letter) option would probably be the winner. It’s so useful that many systems offer an ll
alias for ls -l
(or ls -l<something>
)
The -l
stands for the long format. With that option, the ls
command will display each entry on its own line containing the following information: * file mode * number of links * owner name * group name * number of bytes in the file * date and time * pathname
Also, with the -l
option, ls
will no longer follow symbolic links. So, it will display the information (file mode, number of links and so on) about the link itself, and not about its destination. For the same reason, the ls
command will not display the content of directories pointed by symbolic links:
# Default behavior: displays only the filename and
# follows symbolic links:
sh:~/ls$ ls *
a b c e f hardlink-to-file symlink-to-file
dir:
d e f subdir subdir2
link-to-subdir:
g h i
symlink-to-subdir:
g h i
# `-l` option: displays extended informations and
# no longer follows symbolic links
sh:~/ls$ ls -l *
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 22:18 a
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 22:18 b
-rw-r--r-- 1 sylvain sylvain 0 Sep 19 22:18 c
-rw-r--r-- 3 sylvain sylvain 0 Sep 19 22:18 e
lrwxrwxrwx 1 sylvain sylvain 5 Sep 19 12:09 f -> dir/f
-rw-r--r-- 3 sylvain sylvain 0 Sep 19 22:18 hardlink-to-file
lrwxrwxrwx 1 sylvain sylvain 10 Sep 19 12:09 link-to-subdir -> dir/subdir
lrwxrwxrwx 1 sylvain sylvain 5 Sep 19 22:18 symlink-to-file -> dir/f
lrwxrwxrwx 1 sylvain sylvain 10 Sep 19 22:18 symlink-to-subdir -> dir/subdir
dir:
total 8
-rw-r--r-- 1 sylvain sylvain 0 Sep 19 22:18 d
-rw-r--r-- 3 sylvain sylvain 0 Sep 19 22:18 e
-rw-r--r-- 1 sylvain sylvain 0 Sep 19 22:18 f
drwxr-xr-x 2 sylvain sylvain 4096 Sep 19 12:09 subdir
drwxr-xr-x 2 sylvain sylvain 4096 Sep 19 12:09 subdir2
To conclude this section, I let you examine the output we obtain by combining both the -l
and -d
options:
sh:~/ls$ ls -ld *
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 22:18 a
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 22:18 b
-rw-r--r-- 1 sylvain sylvain 0 Sep 19 22:18 c
drwxr-xr-x 4 sylvain sylvain 4096 Sep 19 12:09 dir
-rw-r--r-- 3 sylvain sylvain 0 Sep 19 22:18 e
lrwxrwxrwx 1 sylvain sylvain 5 Sep 19 12:09 f -> dir/f
-rw-r--r-- 3 sylvain sylvain 0 Sep 19 22:18 hardlink-to-file
lrwxrwxrwx 1 sylvain sylvain 10 Sep 19 12:09 link-to-subdir -> dir/subdir
lrwxrwxrwx 1 sylvain sylvain 5 Sep 19 22:18 symlink-to-file -> dir/f
lrwxrwxrwx 1 sylvain sylvain 10 Sep 19 22:18 symlink-to-subdir -> dir/subdir
-a
: display all files
With the -a
option, ls
includes hidden files when displaying the content of a directory. But what is a hidden file?
By convention, on Unix-like systems, a file whose name is starting by a dot is considered as hidden. In addition, each directory also contains two special, normally hidden, entries: .
and ..
In each directory:
- the
.
entry points to the directory itself. That kind of self-reference may seem curious. But it is sometimes useful, a bit like having your own phone number into your smartphone repertory. - the
..
entry points to the parent directory. Since the file hierarchy on Unix-like systems is strictly organized as a tree, each directory has one and only one parent. Except the root directory/
maybe? Well, not really: the parent of the root directory is … the root directory itself.
# Default behavior: do not display hidden entries
# (including . and ..)
sh:~/ls$ ls
a c e hardlink-to-file symlink-to-file
b dir f link-to-subdir symlink-to-subdir
# `-a` option: show hidden files and directories
sh:~/ls$ ls -a
. a c e hardlink-to-file link-to-subdir symlink-to-subdir
.. b dir f .hidden symlink-to-file
The useful options of ls command
After having reviewed the well known -l
, -d
and -a
options, let’s turn our attention on a couple of lesser-known options I find particularly useful.
-s
: display allocated size
You may remember the -l
option displayed the number of bytes in the file. The -s
option displays the allocated size in blocks. What’s a block? Well, a group of bytes whose size is implementation dependent. It is usually 512 bytes on BSD and 1024 bytes on Linux.
Why would I bother with size in blocks when I already have access to the size in bytes? Well, the -s
options display the allocated size. Not the logical size of the file. Those may be two completely different things for sparse files. Sparse files are files that contain “holes”. When read, those holes behave like normal file blocks containing only zeros. But they take virtually no space on the disk. We can use the dd command with the seek
option to create sparse files as I did it for the b
file in my sample hierarchy:
sh:~/ls$ ls -ls a b
2052 -rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 22:18 a
1028 -rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 22:18 b
As you can see, both my a
and b
files appear to be two mebibytes long. But the b
file being sparse, it takes only 1028 blocks on the disk (roughly one mebibyte).
-h
display human-readable sizes
With the -h
option, ls
will display file sizes using unit suffixes to make them more user-friendly. This option is only meaningful when used in combination with the -l
option (Linux, BSD) or -s
(Linux):
sh:~/ls$ ls -lsh a b
2.1M -rw-r--r-- 1 sylvain sylvain 2.0M Sep 19 22:18 a
1.1M -rw-r--r-- 1 sylvain sylvain 2.0M Sep 19 22:18 b
openbsd-6.3$ ls -lsh a b
4128 -rw-r--r-- 1 sylvain sylvain 2.0M Sep 19 23:49 a
2112 -rw-r--r-- 1 sylvain sylvain 2.0M Sep 19 23:49 b
You may have noticed sizes are displayed using powers of 1024 units, where K stands for 2^10=1024 bytes, M for 1024^2=1048576 bytes and so on. Worth mentioning here the ls
implementation provided as part of the GNU Coreutils has an extra --si
options to use power 1000 instead of powers of 1024:
sh:~/ls$ ls -lsh --si a b
2.2M -rw-r--r-- 1 sylvain sylvain 2.1M Sep 19 22:18 a
1.1M -rw-r--r-- 1 sylvain sylvain 2.1M Sep 19 22:18 b
-i
display inode number
On a Unix-style filesystem, an inode number (or file serial number in the POSIX terminology) is a number that uniquely identifies a filesystem object (a file, a directory, a named pipe, … ). With the -i
option, the ls
command will display its inode number alongside each path.
Even if it seems somewhat exotic, I find myself using the -i
option from time to time, especially to identify directory entries that are referencing the same filesystem object. You will use that option mostly when investigating hard links or bind mounts. Take a look at that video for a practical example: https://youtu.be/Jp58Osb1uFo?t=140
sh:~/ls$ ls -i *
8222 a 8243 b 8262 c 8264 hardlink-to-file 8272 symlink-to-file
dir:
8263 d 8264 e 8265 f 8245 subdir 8261 subdir2
symlink-to-subdir:
8266 g 8267 h 8268 i
In the example above, you can see each filename prefixed by the inode number associated with that path. On your system, the numbers will surely differ. Anyway, take a closer look at the hardlink-to-file
and dir/e
entries. Both have the same inode number (8264 in my case). That means they are two entries referencing the same underlying filesystem object— which is, in fact, the exact definition of what is a hard link.
You may remember I said earlier the parent of the root directory was the root directory itself. By using the -i
option, it is quite easy to verify that assertion:
openbsd-6$ ls -id /
2 /
openbsd-6$ ls -ia /
2 . 25985 bin 5 dev 77954 sbin
2 .. 1235 boot 51969 etc 10 sys
8 .cshrc 1240 bsd 2 home 7 tmp
9 .profile 1241 bsd.booted 77953 mnt 2 usr
51968 altroot 4 bsd.rd 26016 root 78016 var
As you can see, on my system, the root directory is associated with the inode number 2, which is also the inode of its parent. So that proves the root directory is its own parent.
The rarely used options of ls command
I regularly use the options described in the previous section, but those I will talk about now… well… I know they exists. However I must admit when I need them, I often have to look at the man
to refresh my memory.
-L
: display informations about the target of the symbolic links
This option modify the behavior of the ls
command when applied to symbolic links. With the -L
option, ls
will display the information about to the target of the symbolic link instead of displaying those related to the symbolic link itself. By examining the following example, the difference will be obvious:
# Pay special attention to the permission
# and file size for symbolic links with and without
# the `-L` option:
sh:~/ls$ ls -ld *
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 20 00:09 a
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 20 00:09 b
-rw-r--r-- 1 sylvain sylvain 0 Sep 20 00:09 c
drwxr-xr-x 4 sylvain sylvain 4096 Sep 20 00:09 dir
-rw-r--r-- 2 sylvain sylvain 0 Sep 20 00:09 hardlink-to-file
lrwxrwxrwx 1 sylvain sylvain 5 Sep 20 00:09 symlink-to-file -> dir/f
lrwxrwxrwx 1 sylvain sylvain 10 Sep 20 00:09 symlink-to-subdir -> dir/subdir
sylvain@bulbizarre:/tmp/ls/ls/ls$ ls -lLd *
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 20 00:09 a
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 20 00:09 b
-rw-r--r-- 1 sylvain sylvain 0 Sep 20 00:09 c
drwxr-xr-x 4 sylvain sylvain 4096 Sep 20 00:09 dir
-rw-r--r-- 2 sylvain sylvain 0 Sep 20 00:09 hardlink-to-file
-rw-r--r-- 1 sylvain sylvain 0 Sep 20 00:09 symlink-to-file
drwxr-xr-x 2 sylvain sylvain 4096 Sep 20 00:09 symlink-to-subdir
-F
: append a classification character to the filename
The -F
option adds an extra character after the pathname of some categories of file system objects to identify them. It will add:
- a
\
after each pathname that is a directory, - a
@
after each pathname that is a symbolic link, - a
*
after each executable file, - and a
|
after each FIFO (seemkfifo
for more information about that)
In my early Unix days, I used that option a lot. But since ls
can colorize its output (and since we have color monitors!), I rarely need that. But I remember it. And from time to time, on a remote terminal, I find an occasion to use it:
sh:~/ls$ ls -F
a b c dir/ hardlink-to-file symlink-to-file@ symlink-to-subdir@
t
: sort entries by modification time
With the -t
option, the ls
command with display directory entries sorted by modification time (most recent first) instead of sorting them by their name:
# Default sort order (by filename)
sh:~/ls$ ls
a b c dir hardlink-to-file symlink-to-file symlink-to-subdir
# Sort by modification date
sh:~/ls$ ls -t
symlink-to-subdir symlink-to-file c dir hardlink-to-file b a
If I change a file, it will now appear as the first (ie: most recently modified) entry in the list:
sh:~/ls$ echo >> a
sh:~/ls$ ls -t
a symlink-to-subdir symlink-to-file c dir hardlink-to-file b
-S
: sort entries by size
With the -S
option, ls
will display entries sorted by size, largest file first. In case of a tie, the entries are sorted according to their pathname:
sh:~/ls$ ls -lS
total 6244
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 23:49 a
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 23:49 b
drwxr-xr-x 4 sylvain sylvain 512 Sep 19 23:49 dir
lrwxr-xr-x 1 sylvain sylvain 10 Sep 19 23:49 symlink-to-subdir -> dir/subdir
lrwxr-xr-x 1 sylvain sylvain 5 Sep 19 23:49 symlink-to-file -> dir/f
-rw-r--r-- 1 sylvain sylvain 0 Sep 19 23:49 c
-rw-r--r-- 2 sylvain sylvain 0 Sep 19 23:49 hardlink-to-file
-r
: reverse sort order
This option reverses the sort order. I find it most useful when associated with the -t
option to have the least recently modified file displayed first or with the -S
option to display the smallest file first. But it also works with the default, by pathname, sort order:
# Display the least recently modified file first
sh:~/ls$ ls -rt
b hardlink-to-file dir c symlink-to-file symlink-to-subdir a
# Display the smallest file first
sh:~/ls$ ls -rS
hardlink-to-file c symlink-to-file symlink-to-subdir dir b a
# Display path names in reversed alphabetical order
sh:~/ls$ ls -r
symlink-to-subdir symlink-to-file hardlink-to-file dir c b a
-n
: Display numeric UID/GID
This option is exactly the same as the -l
option— except with -n
the owner’s group id (GID) and user id (UID) are displayed as numbers rather than using their associated name:
sh:~/ls$ ls -ld a b c /
drwxr-xr-x 28 root root 4096 May 6 00:28 /
-rw-r--r-- 1 sylvain sylvain 2097153 Sep 20 00:45 a
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 20 00:09 b
-rw-r--r-- 1 sylvain sylvain 0 Sep 20 00:09 c
sh:~/ls$ ls -nd a b c /
drwxr-xr-x 28 0 0 4096 May 6 00:28 /
-rw-r--r-- 1 1000 1000 2097153 Sep 20 00:45 a
-rw-r--r-- 1 1000 1000 2097152 Sep 20 00:09 b
-rw-r--r-- 1 1000 1000 0 Sep 20 00:09 c
The really exotic usage of ls command
No one can claim to know everything. And while writing this article, I (re-)discovered a couple of ls
options. I can’t remember having used them myself, but maybe did you? If it is the case, I would be curious to read in the comment section in which circumstances you find them useful. Anyway, here is a selection that you might find interesting.
-R
: recursively list subdirectories
By default, the ls
command only display the content of the directories explicitly given on the command line. With the -R
option, it will also recursively display the content of the directories encountered:
sh:~/ls$ ls -R
.:
a b c dir hardlink-to-file symlink-to-file symlink-to-subdir
./dir:
d e f subdir subdir2
./dir/subdir:
g h i
./dir/subdir2:
j k l
While intersting in theory, I find (pun intended) the output produced by the find .
command more readable for that purpose. But your mileage may vary, of course:
sh:~/ls$ find .
.
./c
./.hidden
./hardlink-to-file
./b
./symlink-to-subdir
./dir
./dir/d
./dir/e
./dir/subdir2
./dir/subdir2/l
./dir/subdir2/j
./dir/subdir2/k
./dir/subdir
./dir/subdir/g
./dir/subdir/i
./dir/subdir/h
./dir/f
./symlink-to-file
./a
-A
: display almost all files
While not defined in the POSIX standard, the -A
options appear both in the GNU and BSD world. In both cases, it works like -a
, but excluding the .
and ..
entries. Worth mentioning on BSD systems, -A
is implied for the superuser:
sh:~/ls$ ls -a
. a c hardlink-to-file symlink-to-file
.. b dir .hidden symlink-to-subdir
sh:~/ls$ ls -A
a b c dir hardlink-to-file .hidden symlink-to-file symlink-to-subdir
openbsd-6.3$ su root
openbsd-6.3# ls
.hidden a b c dir hardlink-to-file symlink-to-file symlink-to-subdir
-f
: do not sort
With the -f
option, ls
will display entries in the order in which they appear in the directory. That order is dependent on the underlying filesystem, and the order files were created, so it is hardly predictable. The -f
option also implies the -a
option:
sh:~/ls$ ls -f
.. .hidden b dir a
c hardlink-to-file symlink-to-subdir symlink-to-file .
openbsd-6$ ls -f
. a c symlink-to-subdir
.. b hardlink-to-file
.hidden dir symlink-to-file
Amusingly enough, with the GNU Coreutils 8.26 ls
implementation, you can use both the -l
and -f
options if you spell it -fl
–but not if you write -lf
. On OpenBSD both are working as expected:
sh:~/ls$ ls -lf
.. .hidden b dir a
c hardlink-to-file symlink-to-subdir symlink-to-file .
sh:~/ls$ ls -fl
total 3100
drwxr-xr-x 3 sylvain sylvain 4096 Sep 19 12:09 ..
-rw-r--r-- 1 sylvain sylvain 0 Sep 20 00:09 c
-rw-r--r-- 1 sylvain sylvain 19 Sep 20 00:09 .hidden
-rw-r--r-- 2 sylvain sylvain 0 Sep 20 00:09 hardlink-to-file
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 20 00:09 b
lrwxrwxrwx 1 sylvain sylvain 10 Sep 20 00:09 symlink-to-subdir -> dir/subdir
drwxr-xr-x 4 sylvain sylvain 4096 Sep 20 00:09 dir
lrwxrwxrwx 1 sylvain sylvain 5 Sep 20 00:09 symlink-to-file -> dir/f
-rw-r--r-- 1 sylvain sylvain 2097153 Sep 20 00:45 a
drwxr-xr-x 3 sylvain sylvain 4096 Sep 20 00:09 .
openbsd-6$ ls -lf
total 6256
drwxr-xr-x 3 sylvain sylvain 512 Sep 19 23:49 .
drwxr-xr-x 5 sylvain sylvain 512 Sep 19 23:49 ..
-rw-r--r-- 1 sylvain sylvain 19 Sep 19 23:49 .hidden
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 23:49 a
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 23:49 b
drwxr-xr-x 4 sylvain sylvain 512 Sep 19 23:49 dir
-rw-r--r-- 1 sylvain sylvain 0 Sep 19 23:49 c
-rw-r--r-- 2 sylvain sylvain 0 Sep 19 23:49 hardlink-to-file
lrwxr-xr-x 1 sylvain sylvain 5 Sep 19 23:49 symlink-to-file -> dir/f
lrwxr-xr-x 1 sylvain sylvain 10 Sep 19 23:49 symlink-to-subdir -> dir/subdir
openbsd-6$ ls -fl
total 6256
drwxr-xr-x 3 sylvain sylvain 512 Sep 19 23:49 .
drwxr-xr-x 5 sylvain sylvain 512 Sep 19 23:49 ..
-rw-r--r-- 1 sylvain sylvain 19 Sep 19 23:49 .hidden
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 23:49 a
-rw-r--r-- 1 sylvain sylvain 2097152 Sep 19 23:49 b
drwxr-xr-x 4 sylvain sylvain 512 Sep 19 23:49 dir
-rw-r--r-- 1 sylvain sylvain 0 Sep 19 23:49 c
-rw-r--r-- 2 sylvain sylvain 0 Sep 19 23:49 hardlink-to-file
lrwxr-xr-x 1 sylvain sylvain 5 Sep 19 23:49 symlink-to-file -> dir/f
lrwxr-xr-x 1 sylvain sylvain 10 Sep 19 23:49 symlink-to-subdir -> dir/subdir
-q
: Display non-printable filename characters as ?
On Unix-style filesystems, a filename may contain any character except the \
and the NUL characters. This means a filename may contain unprintable characters or even control sequences that may interfere with your terminal. Let’s try something amusing:
touch "$(echo -e '\x1B[7mBOO\x1B[0m')"
Obviously, that filename contains non-printable characters. On modern implementations of ls
, the -q
option is implied when the output is a terminal, to avoid potential nefarious effects. So the non-printable characters will be replaced by a question mark:
sh:~/ls$ ls *BOO*
?[7mBOO?[0m
However, things will be different if you write that instead:
# I let you try that by yourself
# to not spoil the fun;)
sh:~/ls$ ls *BOO* | cat
The | cat
is useless, but as a side effect, the ls
command now sees a pipe on its standard output instead of a tty (a “terminal”). Since the output is no longer a terminal, the -q
option is no longer implied, and ls
will display the filename verbatim. In that case, if all works as expected, to present the file name with a funky video effect.
Explicitly using the -q
option would fix that. I will let you try that by yourself (and eventually playing with other ANSI escape sequences). But I take that occasion to warn you against using the ls
command in shell scripts. In practice, ls
is designed for “human consumption”. There are many side cases regarding specially crafted filenames that are very difficult to handle properly. If you need to walk through a list of files, I strongly encourage you to use the find command instead. In the simplest cases, a simple for
loop is even sufficient— but that would be another story.
for f in *; do echo "$f"; done
The end?
So that concludes our tour of the ls
command options. No need to mention it was far from being exhaustive and I tried to focus here on the most useful and most portable options. But each ls
implementation has its share of cool features, so if you know some nice option I missed in this article, don’t hesitate to share that with us using the comment section. If we have enough feedback, we may even compile and publish them in a follow-up article!
Speaking of ls command, do know the lsof command? It’s not related to ls but it tells you which user is accessing a certain file.
Engineer by Passion, Teacher by Vocation. My goal is to share my enthusiasm for what I teach and prepare my students to develop their skills by themselves.