Robert Elder Software Inc.
  • Home
  • Store
  • Blog
  • Contact
  • Home
  • Store
  • Blog
  • Contact
  • #linux
  • |
  • #commandline
  • |
  • #softwareengineering
  • |
  • #embeddedsystems
  • |
  • #compilers
  • ...
  • View All >>

Intro To 'ls' Command In Linux

2023-04-22 - By Robert Elder

     I use the 'ls' command to list all of the files in the current working directory:

ls

     and the output might look something like this:

backups  books.txt  music.txt  README.txt  run.sh  src

     I can use the '-a' flag to list hidden files too:

ls -a

     and here's an example of the output showing additional hidden files:

.  ..  backups  books.txt  .git  music.txt  README.txt  run.sh  src

     When I use the '-l' flag like this:

ls -l

     I get to see information about the ownership and permissions of the files:

total 12
drwxrwxr-x 2 robert robert 4096 Apr 22 20:12 backups
-rw-rw-r-- 1 robert robert    0 Apr 22 20:12 books.txt
-rw-rw-r-- 1 robert robert    0 Apr 22 20:12 music.txt
-rw-rw-r-- 1 robert robert    0 Apr 22 20:12 README.txt
-rw-rw-r-- 1 mike   mike     15 Apr 22 20:12 run.sh
drwxrwxr-x 2 robert robert 4096 Apr 22 20:12 src

     You can view a list of files from a different directory that's relative to the current working directory using a path like this:

ls src

     which outputs the following in our example:

algorithm.c  algorithm.h  main.c

     You can also view a list of files using an absolute path like this:

ls /home/robert/important/src

     which produces the same output in this example since it's the same directory:

algorithm.c  algorithm.h  main.c

     One of my favorite ways to use this command is to type 'ls -latr'.  This shows me a listing of all files ordered by their modification date with the most recently modified file printed out last:

ls -latr

     and the output of this command when run in the '/var/log' directory is as follows:

-rw-r--r--   1 root      root               35324 Mar 31 23:59 ubuntu-advantage-timer.log.1
-rw-rw----   1 root      utmp                   0 Apr  1 00:00 btmp
drwxr-x---   2 root      adm                 4096 Apr  1 00:00 unattended-upgrades
drwxrwxr-t   2 root      postgres            4096 Apr  8 00:00 postgresql
-rw-r-----   1 syslog    adm               450322 Apr 15 23:55 kern.log.2.gz
-rw-r-----   1 syslog    adm                15872 Apr 15 23:59 auth.log.2.gz
-rw-r-----   1 syslog    adm               525587 Apr 16 00:00 syslog.2.gz
-rw-r--r--   1 root      root               13352 Apr 20 06:59 alternatives.log
drwxr-xr-x   2 root      root                4096 Apr 20 06:59 apt
-rw-r--r--   1 root      root               25058 Apr 20 06:59 dpkg.log
-rw-r-----   1 syslog    adm               274706 Apr 22 23:59 auth.log.1
-rw-r-----   1 syslog    adm             14251443 Apr 22 23:59 kern.log.1
-rw-r-----   1 syslog    adm             14666011 Apr 23 00:00 syslog.1
drwxr-xr-x  11 root      syslog              4096 Apr 23 00:00 .
-rw-r--r--   1 root      root               25133 Apr 23 00:12 ubuntu-advantage-timer.log
-rw-r-----   1 syslog    adm                 6129 Apr 23 00:29 auth.log
-rw-rw-r--   1 root      utmp              585600 Apr 23 00:29 wtmp
-rw-rw-r--   1 root      utmp              292584 Apr 23 00:29 lastlog
-rw-r-----   1 syslog    adm                47171 Apr 23 00:29 syslog
-rw-r-----   1 syslog    adm                34724 Apr 23 00:29 kern.log

     And that's why the 'ls' command is my favourite Linux command.

Intro To 'stty' Command In Linux
Intro To 'stty' Command In Linux
Published 2023-10-04
Terminal Block Mining Simulation Game
$1.00 CAD
Terminal Block Mining Simulation Game
Intro To 'nproc' Command In Linux
Intro To 'nproc' Command In Linux
Published 2023-07-15
Intro To 'comm' Command In Linux
Intro To 'comm' Command In Linux
Published 2023-09-06
How To Force The 'true' Command To Return 'false'
How To Force The 'true' Command To Return 'false'
Published 2023-07-09
A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01
Intro To 'chroot' Command In Linux
Intro To 'chroot' Command In Linux
Published 2023-06-23
Join My Mailing List
Privacy Policy
Why Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it.  Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked!  You'll get some emails with examples of things that I sell.  You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right?  Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
© 2025 Robert Elder Software Inc.
SocialSocialSocialSocialSocialSocialSocial
Privacy Policy      Store Policies      Terms of Use