Learn Linux Basics

Not long ago, I shot a video about the 5 most basic Linux commands a beginner should know. I began my learning journey with this lot, and I found it most satisfying. Of course, I spent little time in the terminal back then, compared to today, but I still felt like a magician. Have you ever performed an update from terminal ? It could not be easier, yet seeing the lines of text crazily going down in that black box is something I have never gotten tired of.

This Blog Post On Video

5 Commands You Should Know

You will soon find out that there are a little more than 5 commands in this tutorial, but believe me, you will thank me for adding them into it.

Alright. Now, please, open up a terminal, and let’s get started !

For those of you who do not know how : Press ctrl+alt+T or type terminal in your menu (or app launcher).

pwd

The very first command I decided to present you is pwd, because it is, in my humble opinion, the easiest of all. You give an input to your terminal, and a readable output comes back.

Easy peasy, lemon squeezy

If you click on the picture up above, you should see 3 things :

  • Pwd : Our command / our input for the terminal
  • /home/soimuen : My home directory. Pwd stands for print working directory. This means, Terminal, tell me where I am.
  • scrot : Don’t mind this little guy, this is the program I use to take screenshots directly from terminal.

Pwd stands for print working directory. It literally means “Hello computer, can you tell me where I am?”

It is as simple as that.

ls

ls means list. You are simply asking your computer to list the files in your current directory, if you type a single ls. If you type ls Documents/, then you are asking your computer to list the content of the Documents/ directory.

Flags

Flags may be used with pretty much all the commands you could possibly imagine. A flag is a technical term to speak about an option which is added to a command. For example :

  • ls –all : this is how you added a flag to a command. You simply add “— (dash dash) + [name of your option]”
  • ls -a : Most flags have a shorter way of being written. The flag above this one means “show me everything in this directory, even dotfiles“. As for ls -a, it means the same thing, but it is quicker to write. Do not forget that a terminal user’s philosophy is efficiency. To be even more efficient, I invite you to check out aliases.

cd

To move from one directory to another, you need to use the cd command.

As you can see in the picture up above, you can type cd in several ways. You may type :

  • cd Documents/ [cd + $directory_name]
  • cd .. [cd dot dot] : to go back one directory
  • cd ../../ [cd slash dot dot slash dot dot…] : to go back more than one directory.
  • cd OR cd ~ : to go back to your home directory
  • ~ : to quickly go back to your home directory

mkdir

This simple commands stands for make directory. It allows you to create a folder.

Example :

  • cd Documents
  • mkdir Projects
  • cd Projects
  • mkdir Project-1

In the above example, we created a folder called Projects within our Documents/ directory and went into it to create another folder for our first project.

Of course you may also create several folders in one command :

  • mkdir Project-1 Project-2 Project-3 Project-Xth

touch

Let’s create a file with the touch command :

  • touch index.html

Practical case : Let’s create a new project directory for a website we wish to build.

  • cd Documents
  • mkdir Website-Project
  • cd Website-Project
  • mkdir js css
  • touch index.html js/script.js css/style.css

Here you go, this is the architecture of your first project. Is this not much easier than right-clicking every time you wish to create a file or folder ? I could do it all in one line, of course… I could even write a script and I would never have to type these lines ever again for creating a single website project ever again.

cp

cp stands for copy. It is the equivalent of ctrl+c & ctrl +v when running a GUI. Let’s use the files we have already created in our Website-Project directory.

Example :

  • pwd
  • /home/$username/Documents/Website-Project
  • mkdir html/
  • cp index.html html/index.html

Now, we have our index.html file in 2 places : within the html directory and at the root of our project.

mv

mv stands for move. It is the equivalent of ctrl+x & ctrl +v when running a GUI. If we use the above example (with cp), we can do the same maneuver with a slight difference.

  • pwd
  • /home/$username/Documents/Website-Project
  • mkdir html/
  • mv index.html html/index.html

Now, we have our index.html file in 1 place : within the html directory. The one at the root of our directory was deleted and then pasted into html/.

To rename a file you may also use the mv command.

Example :

  • ls js/
  • script.js
  • cd js/
  • mv script.js index.js

See what I did there ? I merely renamed script.js to index.js. Easy, right ?

rm

Alright, let us now clean up all that we did in our examples. rm stands for remove.

  • cd js/
  • rm index.js

That’s for deleting one file. However, you may delete several files or folders at the same time just like when using mkdir or touch. You may also remove directories with the -r flag.

  • cd ../..
  • rm -r Website-Project/

Here we go, our working directory is clean again! You will find an image down below to sum this all up.

Signing Off & News

If you want to be among all the amazing (and proudly mad) people in this community, you only need follow this blog (via email or WordPress). If you aren’t following this blog yet but trust its future content will rock as the one which preceded, subscribe and get notified whenever I publish a new article.

Regarding my Patreon, I am currently working on customizing it. I would like that platform to become my main means for you to be able to support my endeavors, if you ever wish to do so. It sounds to me like the most honest way to work with you. I will soon publish a blog post about Patreon and a poll I created there (which you can find by clicking here).

I am not yet a superstar on YouTube, but you may still subscribe to my channel to support me. I am working on some new content, which I hope you will enjoy. I also intend to begin shooting French videos some time soon.

Take care of yourselves,

Phil.

This image has an empty alt attribute; its file name is copyright.png

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.