ls command Lists the files in the current directory, in alphanumeric order, except files starting with the “.” character.
ls command syntax
1 |
$ ls [<i>options</i>] |
ls command options
ls command main options:
option | description |
---|---|
ls -a (all) | Lists all the files (including .* files) |
ls -l (long) | Long listing (type, date, size, owner, permissions) |
ls -t (time) | Lists the most recent files first |
ls -S (size) | Lists the biggest files first |
ls -r (reverse) | Reverses the sort order |
ls -ltr (options can be combined) | Long listing, most recent files at the end |
ls -d | -d tells ls not to display the contents of directories |
ls -i | list file’s inode index number |
ls -la (long + all) | Long listing + Lists all the files |
ls -ls (long + size) | Long listing with size |
ls -R | list recursively directory tree |
ls command examples
ls (List):
1 2 3 4 5 6 7 8 9 10 11 |
$ ls Android idea-IC-141.177.4 mytxt.sh test AndroidStudioProjects IdeaProjects Pictures test.txt a.txt javadoc Public Untitled Document Desktop javadoc~ pycharm-community-4.0.5 Untitled Document~ Documents libchromiumcontent.so PycharmProjects Videos Downloads libffmpegsumo.so resources examples.desktop locales sample gittest Music Templates $ |
Lists filse present in directory
ls -a (all) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ ls -a . .dmrc javadoc~ PycharmProjects .. Documents libchromiumcontent.so resources .adobe Downloads libffmpegsumo.so sample .android examples.desktop .local Templates Android .gconf locales test .AndroidStudio1.5 .gitconfig .macromedia test.txt AndroidStudioProjects gittest .mozilla Untitled Document a.txt .gnome Music Untitled Document~ .bash_history .gradle mytxt.sh .vboxclient-clipboard.pid .bash_logout .gvfs .oracle_jre_usage .vboxclient-display.pid .bashrc .ICEauthority Pictures .vboxclient-draganddrop.pid .cache .IdeaIC14 .pki .vboxclient-seamless.pid .compiz idea-IC-141.177.4 .profile Videos .config IdeaProjects Public .Xauthority .dbus .java .PyCharm40 .xsession-errors Desktop javadoc pycharm-community-4.0.5 .xsession-errors.old $ |
Lists all the files (including .* files)
ls -l (long) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
$ ls -l total 77720 drwxrwxr-x 3 root root 4096 Jan 14 22:36 Android drwxrwxr-x 3 root root 4096 Jan 14 23:04 AndroidStudioProjects -rw-rw-r-- 1 root root 0 Mär 2 23:41 a.txt drwxr-xr-x 2 root root 4096 Mär 28 2015 Desktop drwxr-xr-x 2 root root 4096 Mai 2 2015 Documents drwxr-xr-x 2 root root 4096 Feb 28 20:10 Downloads -rw-r--r-- 1 root root 8980 Mär 28 2015 examples.desktop drwxrwxr-x 3 root root 4096 Mär 29 2015 gittest drwxrwxr-x 6 root root 4096 Mär 28 2015 idea-IC-141.177.4 drwxrwxr-x 4 root root 4096 Mär 28 2015 IdeaProjects -rw-rw-r-- 1 root root 109 Jan 14 21:23 javadoc -rw-rw-r-- 1 root root 0 Jan 14 21:22 javadoc~ -rw-rw-r-- 1 root root 76984472 Mär 29 2015 libchromiumcontent.so -rw-rw-r-- 1 root root 2496440 Mär 29 2015 libffmpegsumo.so drwxrwxr-x 2 root root 4096 Mai 2 2015 locales drwxr-xr-x 2 root root 4096 Mär 28 2015 Music -rw-rw-r-- 1 root root 0 Mär 2 23:40 mytxt.sh drwxr-xr-x 2 root root 4096 Mär 28 2015 Pictures drwxr-xr-x 2 root root 4096 Mär 28 2015 Public drwxrwxr-x 8 root root 4096 Mär 28 2015 pycharm-community-4.0.5 drwxrwxr-x 4 root root 4096 Mär 28 2015 PycharmProjects drwxrwxr-x 3 root root 4096 Mai 2 2015 resources drwxrwxr-x 3 root root 4096 Mär 29 2015 sample drwxr-xr-x 2 root root 4096 Mär 28 2015 Templates drwxrwxr-x 3 root root 4096 Mär 29 2015 test -rw-rw-r-- 1 root root 0 Mär 2 23:40 test.txt -rw-rw-r-- 1 root root 48 Jan 31 12:04 Untitled Document -rw-rw-r-- 1 root root 0 Jan 31 12:04 Untitled Document~ drwxr-xr-x 2 root root 4096 Mär 28 2015 Videos $ |
Long listing (type, date, size, owner, permissions)
1 2 3 4 |
$ ls *txt a.txt test.txt $ |
The shell first replaces *txt by all the file and directory names ending by txt (including .txt), except those starting with ., and then executes the ls command line.
1 2 3 4 5 6 7 8 9 10 |
$ ls -d .* . .bashrc .gitconfig .local .vboxclient-clipboard.pid .. .cache .gnome .macromedia .vboxclient-display.pid .adobe .compiz .gradle .mozilla .vboxclient-draganddrop.pid .android .config .gvfs .oracle_jre_usage .vboxclient-seamless.pid .AndroidStudio1.5 .dbus .ICEauthority .pki .Xauthority .bash_history .dmrc .IdeaIC14 .profile .xsession-errors .bash_logout .gconf .java .PyCharm40 .xsession-errors.old $ |
Lists all the files and directories starting with . -d tells ls not to display the contents of directories.