Categories
Linux Tutorial Series

Linux Tutorial Series – 32 – The ls command

Here is the video version, if you prefer it:

The ls command lists directory contents. (“ls(1) – Linux man page,” n.d.)⁠ Its usage goes as follows:

mislav@mislavovo-racunalo:~$ ls

anaconda3 Downloads Pictures stanfordnlp_resources

'Calibre Library' grep-hadoop-example Public Templates

Desktop hadoop-example Python-3.7.4 Untitled.ipynb

Documents Music snap Videos

A useful option of the ls command is -l. The -l option is the “long listing format”, which lists the following (from the first to the last column):

  • file permissions,
  • number of links,
  • owner name,
  • owner group,
  • file size,
  • time of last modification, and
  • file/directory name (“What do the fields in ls -al output mean?,” n.d.)⁠

I use the ls -l option to find out the size of the files within a directory. My main concern is if the files are empty (0 bytes) or if they are larger. This is because I write programs and if a program is actually writing something to a file, the files should be larger than 0 bytes.

An example output of the ls -l command is:

mislav@mislavovo-racunalo:~/grep-hadoop-example$ ls -l

total 4

-rw-r--r-- 1 mislav mislav 22 Nov 9 18:32 part-r-00000

-rw-r--r-- 1 mislav mislav 0 Nov 9 18:32 _SUCCESS

The option I use less often, but is mentioned in the above reference is the -a option. The -a option flag lists all files, even the hidden files (hidden files are specific in that their filename starts with a .). I never had the need to look at hidden files as those are usually reserved for some operating system things or some program configuration things, but if you want to explore, off you go with ls -a! You can combine both the l option and the a option by writing ls -la. You can usually combine options like that.

Hope you learned something useful!

References

ls(1) – Linux man page. (n.d.). Retrieved January 6, 2020, from https://linux.die.net/man/1/ls

What do the fields in ls -al output mean? (n.d.). Retrieved January 6, 2020, from https://unix.stackexchange.com/questions/103114/what-do-the-fields-in-ls-al-output-mean