Home Home > 2014 > 07 > 01 > Command Line Tuesdays – Part Three
Sign up | Login

Command Line Tuesdays – Part Three

July 1st, 2014 by

Heya Geekos! New week, new part in our CLT series!

Today, mr Shotts takes us on a first part of a guided tour through our file system. We’ll learn how to visit, list files within directories and we’ll learn to use some options for the first time. So let’s begin with the first command of the week.


ls is a command used to list files in a directory. It can be used in various ways. These various ways come with using a form of adding an option to our command. To make things clearer; You can type only ls. But, you can also add an option, which will modify your command. It can come in useful when you want to sandbox some of the information, when looking for something specific, and the command issues a very long output, you can, for example, narrow it down to only specific information.

That’s what an option is. And formally we can write it down like this:

command -option argument

Command is, well, a command we write in (like pwd, ls or anything else we have learned by now).

We already stated above the purpose of an option. But let me note it should be written exactly as it’s in the form; With a dash in front of it. So, if the option is l, you should put -l after the command.

An argument is an object upon which the command operates (in this case, it will be directories, as we’ll learning how to navigate through them).

So, let’s try out ls, and use it on the /etc directory in our home folder. This time, without any options.

Screenshot - 30. 06. 2014 - 18:41:27

There you go, a whole bunch of files. It also sorts them by colours. The blue ones are directories, the white ones are files, the green one seems like a shell script of some sort. There are more colors, as they represent different file types.

Next, you can use the same command, but with an option -l added. Option -l will list the same files and directories, but in a long format. In case you need more information:

Screenshot - 30. 06. 2014 - 18:45:42

The Long Format

So, using the long format, you see much more information, and some crazy looking signs like -rw-r–r– at the beginning of all lines. Actually, here’s a scheme, representing what all of the given information actually means.

Screenshot - 30. 06. 2014 - 18:48:29

File Name is the name of the file. Modification time is the last time the file has been modified. Size is the size of the file in bytes. Group is the name of the group that has file permissions along with the owner, and Owner is the user who owns the file. The most important one is…

…File Permissions

That’s the gibberish at the beginning of every line in long format. The first character is the file type. If it’s a ‘d’, it means the file’s a directory. If it’s ‘-‘, it means it’s an ordinary file. The next three characters represent the read, write and execution rights of the file’s owner. The next three are the same rights of the group that also has access to the file, and the last three characters represent rights of everyone else trying to use the file.

So for example, if we have a file which in long format displays: -rw-r–r–, it means it’s an ordinary file (the first ‘-‘), the owner of the file can read and write the file, but he can’t execute it, as it’s not an executable file (the ‘rw-‘ characters after the initial ‘-‘), and the user group and everyone else can only read the file (you can see ‘r–‘ sequence repeating twice. If the user group had ‘rwx’ instead of ‘r–‘, it would mean they could read, write and execute the file).

Next option for ls is ls -la .. – this will list all of the files, as in a usual command, hidden files are not shown. It will list all files in the parent of the working directory in long format.


Less is a command which will display your text file. For example, you’re looking for text file os-release in /etc. You have succesfully found it there with ls /etc, and now you want to read it.

You just use less /etc/os-release.

Screenshot - 30. 06. 2014 - 19:02:52

..and there you go.

How do you control less?

Easy, with your keyboard!

less will display only one page of your text at a time. To go forward one page, you can press Page Up, or ‘b’. To go back one page, you can use Page Down, or space. Capital G will take you to the end of the text file, while ‘1G‘ will take you to the beginning of the text. /characters will search for characters inside the text (for example, if you write /suse, it will search for occurances of suse inside your text and mark them). n will repeat the last search you performed, and h will display all your options (h, as in haalp!).


You quit less with the letter q.


The file command will show what kind of file is that you’re looking for, be it ASCII text, a jpg image, a bash script etc. As we performed our exercise with /etc/os-release, let’s use it here also.

Screenshot - 30. 06. 2014 - 19:14:02

There you go, os-release is an ASCII text file. Please, do try it out with something else, and see the output.

And until next time, remember to…


…have a lot of fun!



Both comments and pings are currently closed.

7 Responses to “Command Line Tuesdays – Part Three”

  1. Hmm, I always thought that “option” is a synonym for “argument”. At least C programs start with a variable called “argv” which is an array of anything delimited by space. Also note that full-name options typically use two dashes (–version, or –si because SI is the full name) while single-letter options use one (-v, -h).

    The colours in ls actually have to do with permissions. Green means executable file, for instance. If you do `ls /dev`, you’ll see a rainbow of colours, because devices have complex permission schemes.

    About less, another way to go to the end is by typing ‘>’ (shift-.) and going to the start by typing ‘<' (shift-,). That's a lot more intuitive for me! Also, `cat` is a related tool, it prints text, but doesn't allow scrolling through it (so best used for small text files, like the aforementioned os-release). The good thing about cat is that it doesn't obscure the command history, unlike less. Oh, and it's called cat, and everyone likes cats! :)

    • jetchisel

      Options has the dash it can be a short or a long dash also called short and long options. the long options are GNU standards.

      ls output is colored because ls is aliased in openSUSE. Try running

      command -p ls /dev


      \ls /dev


      In using less you can press

      g to go to the beggining and press
      capital g aka ‘shift + g’ to go to the end ;-)

      • Like I said, using “>” to mean end and “<" to mean beginning is a lot more memorable for me than the random "g" and "G".

        • jetchisel

          Yeah, sorry i just got used to g and G since it works on man,less and vim too :-)

  2. jdd

    In openSUSE and other, many command have aliases that modify them, this makes it difficult to understand the command itself, but aliases are a bit harsh for a beginner :-(

    • jetchisel

      IMHO beginners does not need to worry about aliases, or functions for that matter. Just use those aliases/functions like you don’t care :-), Now if you really want to see/know if the command has an alias/function or whatever… you can run

      type -a «your-command-in-question»


      type -a ls

  3. giocitta

    “…. less will display only one page of your text at a time. To go forward one page, you can press Page Down, or space. To go back one page, you can use Page Up, or ‘b’.”