I wanted to note that you can have two kinds of options: short options and long options. Long options use two dashes (--) and can’t be chained together, while short options use only one dash and can be chained together. What this means is that if I wanted to display all files in the current directory alongside their long listing, I could write:
ls -l -a
or, shorter:
ls -la
However, long options (one of which we will talk about in the next post) can’t be chained. Just keep that in mind.
The man command is used to display usage information regarding a certain command. (“man(1) – Linux man page,” n.d.) For example, if I wanted to know how to use the ls command, I would write:
mislav@mislavovo-racunalo:~$ man ls
The man page for the ls command would open and then you can see the usage information regarding the ls command. You could scroll through the man page by using Space on your keyboard (to move forward one page) and Q to exit man page viewing. To go backward for 1 page, press B. The answer in the reference here says to press CTRL + B (or ^B in Linuxspeak), but you can just press B. (as is said in the comment in the reference; it is always good to read stackexchange comments!) (“How to read backward from the end of file in less or more?,” n.d.)
That way, if you forget to use a command, you can always find out its usage information. Although I have found myself very rarely using the man command (because I know the syntax of the commands I often use by heart, or use Google to find their usage in my particular situation), it can come in handy to know that you can always have the man there waiting for you if all else fails.
Hope this helped!
Additional information tidbit:
You can even access the man pages of man by writing man man. Manception!
The cd command is used to change the working directory. Its name, cd, literally stands for “change directory”.(“cd(1) – Linux man page,” n.d.)
For example, if I wanted to go to folder named Downloads relative to my current directory, I would write:
mislav@mislavovo-racunalo:~$ cd Downloads
However, let’s say I was somewhere far, far away from my Downloads folder. Let’s say I was in somewhere like /usr/local/bin. Pretty tough to navigate from here to my Downloads folder (not impossible, but tedious – I would have to write cd .. to go to the parent folder, then repeat that multiple times until I reached the root folder, then cd myself into home and then mislav and then finally Downloads). Here I would use:
mislav@mislavovo-racunalo:/usr/local/bin$ cd /home/mislav/Downloads
and I would get to my desired Downloads folder without a lot of navigation.
To emphasize: You can always use cd .. to go to the parent folder of the current directory and then use cd someFolder to position yourself in the folder someFolder.
Hope this was helpful!
P.S. To be honest with you, I usually change directories the tedious way, as in writing cd .. and cd SomeFolder a lot of times, but I believe that it is much easier to get the work done with providing an absolute pathname. So this is some “I advise doing this even if I do this the other way” type of advice.
pwd prints the name of the current working directory. This is useful when changing directories with cd and you want to know where you are. For example:
mislav@mislavovo-racunalo:~/Documents$ cd django-rest-tutorial
Before we begin learning the commands we are about to learn, let me just note that the commands are case sensitive. Meaning – it is not the same if you use uppercase or lowercase letters in command names.
In the following posts, we are going to cover a lot of commands. Those commands are the bread-and-butter of the Linux command line. You will use them almost daily and almost every tutorial on how-to do something on Linux uses these commands and so it is very important to understand what they do, since most tutorials assume you know what they do.
I will not lie – this will be a little bit dry. However, treat it as learning to add and subtract. It is not fun at the time you are learning it, but you power through it. I am asking you to power through it a little bit. It will pay off.
When talking about paths, you can often hear “absolute path” or “relative path”. What do these mean?
Absolute path is a path which starts from the root directory of your Linux system. (Barrett, 2016) So an absolute path would be something like:
/home/mislav
Relative paths are relative to the directory you are currently in (the so called working directory). So, if I wanted to use the cd command (which allows me to change directories (“cd(1) – Linux man page,” n.d.)):
mislav@mislavovo-racunalo:~$ cd SomeFolder
I would go from ~ (which is a shorthand for /home/mislav) to SomeFolder, not from the root directory (denoted by /) to SomeFolder.
Hope this was useful!
References
Barrett, D. J. (2016). Linux pocket guide (3rd ed.). O’Reilly Media. Page 18
cd(1) – Linux man page. (n.d.). Retrieved January 5, 2020, from https://linux.die.net/man/1/cd
Maybe you heard the terms “parent directory” and “current directory”, “working directory” or “current working directory”. “What do these terms mean?” you might ask yourself. Well, fear not, because I have come to alleviate you from your ignorance! (imagine epic music playing in the background)
Working directory (or its synonyms), in the context of using the Linux command line, refers to the directory you are currently located in. (Barrett, 2016)Let me elaborate:
I just started a new Terminal session and this is what I get as output:
See the ~ between the : and $?Well, that is my working directory.~ actually stands for my home directory, so instead of ~, if we wanted to be fully correct, there should be /home/mislav. If you start a Terminal session, your working directory should also be ~ as well. From within the Terminal, you can change directories (using the cd command), but that is not the topic of this post.
Now, more importantly, why is it important to know in which directory you are in? A good question. It’s like I asked it myself. Let’s look at the following example:
The ls command lists directory contents. (“LS(1),” n.d.) But contents of what directory, exactly? Well, if you don’t explicitly say what directory, it is assumed that you want the ls to list the contents of the working directory.
So that’s why it is useful! Imagine if you were inside the directory you desire to operate upon and every time you wanted to call a command you needed to write out the full “trajectory” (also called a path) to the directory you wanted to operate on (as in ls /home/mislav while already being in /home/mislav). That’s tedious and programmers don’t like tedious. Thus, when calling a command (in our case, ls), it assumes you want to operate on the current directory.
Lastly, parent directory is the directory directly above the current directory. (Shotts, 2019) For example, if I was in the folder
/home/mislav
the parent directory of the mislav directory is the home directory. (3 uses of the word directory in one sentence, whew!)
Hope you learned something useful!
References
Barrett, D. J. (2016). Linux pocket guide (3rd ed.). O’Reilly Media. Pages 17-19