Skip to main content

TheWeeklyLinux : ls


[sh_clear ]In TheWeeklyLinux I try to renew the interest in Linux. Here we provide weekly one command/trick. It is up to the community to make suggestions what next command to publish. You can see these posts as a platform to share your experience with each command[/sh_clear]

Being the first week of publishing I’ll start of whit the most basic command. The ls command and all of its variants is well known among Linux/Unix users. The basic functionality is to view a list of all the folders (typically named directory’s) and files you have in a specific directory.

The typical syntax is as follows

 ls [options] [list of files] 

Note that in Linux a directory is in its basic form a file. Therefore we will not state a difference in files/directory’s where its not needed. In this case when you give a file as a parameter it will return only the information concerning that specific file.

“Everything is a file”


[bash]ls -l (long)[/bash]

Gives a long list of properties featuring a file on each line. Here are the shown values from left to right: user/group/other rights (read, write, execute), user, group, size of the file, time last touched.

[bash] <pre>drwxr–r– 1 fred editors 4096 Mar 1 2007 drafts [/bash] [bash]ls -a (all)[/bash]

Normally ls only features the ‘visible’ files in that specific directory. In orde to view ‘hidden’ files you need to append the option -a to the command. Notice: The concept of hidden files only means that it is hidden from default ls views, its not managed by the file itself.

[bash]ls -d (directory only)[/bash]

Self Explanatory Isn’t it?

[bash]ls -s </em>(<em>size)[/bash]

This options show the amount of physical blocks that particular directory/file claims on the HDD. !warning! Don’t confuse this ‘size’ with the size shown by the ll (ls -l) option. Claiming isn’t the same as populating. For example if I am a file that consists of 2049 bytes (2×1024 bytes || 2x2KB). Then I am claiming 3 blocks of physical space and only population 2049 bytes of space. Leave the rest of that last physical block going to waste. Proceed to the Relating to… section to expand your wisdom on other related commands concerning physical and actual sizes.

[bash]ls-h (human readable)[/bash]

Although favoured by many programmers not many people know this option. This calculates the size in terms of KB,MB,GB. Which is, in fact, more readable for humans.

Fun note: Try installing “Steam Locomotive”. sudo apt-get install sl If you now type sl with options -l -s etc. You will se a locomotive passing by. The sl command is often typed by error therefore this is a neat bash extension that will amuse you everytime you misspel the sl command. (Meant ls)

Relating to…

INTRO: In this section we discuss other commands that relate to the weekly chosen one. (a command that is)

As stated before the ll -s command does include both blocks claimed and the actual populated size of the file. Here are the other brothers and sisters in the Linux family to receive related information.


Du (disk usage) is a shell command that works similarly to ls -s. The biggest difference as opposed to ls-s is that this command show the total combined claimed blocks of all the children of a specific directory listed in the overview.

[bash]du -a (all) [/bash]

Shows not only directory’s but also files

[bash]du -b [/bash]

Shows the quantities in bytes instead of blocks of Kb (1024 bytes)


Named after the bathroom a.k.a. toilet wc (word count) gives a rundown of used lines/wordes/charactes (in that order) in a file.
Only interested in -w words, -c characters, -l lines? Then use the corresponding options for it.


Read trough this all and never encountered all of the listed commands? Terminal opened up and executed the commands? If not here is a little assignment/challenge to get you going.

  1. “Everything is a file”. But exactly how much space does a directory populate/claim?
  2. “Folders are, in essence, files” How does wc react on a directory? How many lines are used here? Sneak peak: In W3 we will feature the exact directory architecture.
  3. Make a file with one user then copy it (cp) using another. Analyse what happens to the rights, user and group listed in the ll command. Hint: try copying the same file but use the -p (preserve) option.

That’s it! We are done for this week! Looking for the answer to the above challenges? Hit the community up on Twitter/Instagram with a picture of you showing the solution. Don’t care about social life? Check in next week for a new command and the solution to the assignment!

Oh! Here is a sneakpeak for next week: rm -rf /

Thanks for Reading

Enias Cailliau