ls command in UNIX
ls [OPTION]... [FILE]...Introduction
Section titled “Introduction”List information about elements (in the current directory, by default).
Options
Section titled “Options”Here are some of the options that you will use the most:
-a,--all: do not ignore entries starting with.(single dot)-b,--escape: print C-style escapes for non-graphic character (like spaces)-d,--directory: list directories themselves, not their contents-F, ---classify: append indicator (one of*/=>@|) to entries-h,--human-readable: with-land-s, print sizes like1K,234Metc.--si: likewise, but use powers of1000not1024-i,--inode: print the index number of each file-l: use a long listing format-n,--numeric-uid-gid: like-l, but list numeric user and group IDs-r,--reverse: reverse order while sorting-R,--recursive: list subdirectories recursively-s,--size: print the allocated size of each file, in blocks-t: sort by modification time, the newest first-X: sort alphabetically by entry extension
Examples
Section titled “Examples”If you specify a directory name as parameter, you’ll get the ls of that directory without having to change directory (cd) into it:
cd Desktop/
lsarduino-arduinoide.desktop fritzing.AppImage Matlab.desktopblog homeworks dog
pwd/home/pit/DesktopWithout changing directory:
ls Desktop/arduino-arduinoide.desktop fritzing.AppImage Matlab.desktopblog homeworks dog
pwd/home/pitThe long listing format is usually set as an alias (we’ll talk about aliases in a dedicated blog post).
cat .bashrc# ...alias ll='ls -alF'# ...
# $ls -alF Desktop/ll Desktop/drwxr-xr-x 6 pit pit 4096 mar 13 15:12 ./drwxr-xr-x 47 pit pit 4096 mar 14 00:11 ../-rwxr-xr-x 1 pit pit 364 ott 26 11:57 arduino-arduinoide.desktop*drwxrwxr-x 2 pit pit 4096 mar 11 18:12 blog/drwxrwxr-x 3 pit pit 4096 mar 8 15:56 dog/# ...Other options, like reverse or recursive, are very easy to use:
cd Desktop/dog && lshello-world hello-world.c subfolder
ls -r # ls --reversesubfolder hello-world.c hello-world
ls -tsubfolder hello-world hello-world.c
ls -R # ls --recursive.:hello-world hello-world.c subfolder
./subfolder:file.py file.txt hard-link.txt
ls -Rt # ls -tR.:subfolder hello-world hello-world.c
./subfolder:file.txt hard-link.txt file.pyPlease Note: && between two commands means that the second command wait for the first to finish before start its execution.
Quotes
Section titled “Quotes”Manual reference: