Listing
Great, we can see where we are. That’s pretty useful, but only once. Maybe twice, if you’re forgetful!
Let’s expand on the CLI's usability.
Listing Content
So we know that we're in our home directory and we know that we want to move somewhere. To achieve our aim, we'll need to know where to move to, and what our options are.
Typing the command ls
gives us a list of the non-hidden files and directories in the current working directory:
That's a pretty good selection. But we can only move into a directory, not a file, so we need to be able to find out which of the listed items are indeed directories.
Using Switches
To achieve this, we can run the command ls
as we would normally, but with a switch - something that modifies its behaviour. This translates into appending either a single letter or a word prefixed with a single dash (-) or double-dash (--).
Try: ls -l
Now we have a list of all the contents listed in some sort of invisible table, right?
In the first column, you’ll see something within the lines of drwxr-xr-x
, where “d” stands for directory. If you have other content that is not a directory, the letter “d” is replaced by -, as in the example above. We'll explore this further later.
Combining Switches
You can pass multiple switches to a command.
Try: ls -l -a
You should now be seeing all of the content in your directory, including the hidden ones, which are prefixed with a dot.
When you use a GUI, all of the files prefixed with a dot get hidden in order to keep things tidy. These are normally used by software packages. It’s good to be aware that they exist.
As a side-note, you can combine multiple switches into one, where the order isn’t important:
ls -l -a
is the same as ls -la
and ls ls -al
Finally, you can list the content of a different directory by typing its path after the ls command. Try it with your Desktop:
ls ~/Desktop
What if you want retrieve even the hidden ones? We’ll leave this one to you.