Image- Umang Bhalla

Getting Started with Linux

Tanav Bajaj

--

This is an article for Linux Newbies. Here I’ll be writing about the simple day to day commands that most Linux users use.

To know the various methods of using Linux I recommend reading the article by my buddy Kushagra — https://medium.com/@kushagra9nov/methods-of-installing-linux-67adbee8ab0c

Before I start with the commands. I’d like to get to some terminology that should be known to every user.

Terminal vs Shell vs Terminal Emulator

Terminal

It is the piece of hardware that helps you interact with the laptop. For simplicity purposes think Keyboard + Text Screen.

Shell

This is a special program that makes controlling the Terminal an easier task. It is also used to launch other programs. Basically, the command line interpreter that translates your words to help the terminal understand you. Different Shells provide a variety of customisation and elegance. The most famous is Bash and I use zsh.

Terminal Emulator

This is a program that “emulates” the physical terminal. It is the place where you write your commands and expect your computer to work exactly how you want it to.

So they are interconnected as Terminal Emulator is used as the place to write Shell commands to make the Terminal do its work.

Directory- The location of the files on your computer. Like if I say current directory it means the directory you are in. It could be your Desktop or Documents folder.

Root- Root is the user on your computer with the permission to do anything and yes that involved deleting everything in your system (though I do not recommend using this power for such evil work)

Flags- These are parts of a command used to modify the behaviour of the command you are using in the terminal emulator.

I’ll use a simple date command to show how these work.

As in the name, date command gives the date as an output on the screen.

What would happen if I add a simple -R in front of it?

Well, it changed a little. Now what if I add -I ?

It’s different again. So these -R and -I are called flags of the command.

Common Linux Commands

echo

While learning programming languages we start with “hello world”. So why not do the same for working with the Terminal.

echo command is used to display a line of text as output.

So let’s say our prayers to Linux Chad and type echo “Hello World”

man

Shows the manual pages. Linux is open source and heavily relies on documentation to guide the users. Manual Pages are documents that give you details about Linux commands.

These details involve what can be done with the command and all the flags that can be used with it. Here is an example of man page of the echo command which is opened by typing man echo in the terminal emulator.

Press q and exit the man pages to get back to the terminal.

Now let’s read the manual page entry for the man command.

I used the command man man

man man

free

free command shows the amount of free and used memory in your system.

This is what happened when I used free on my system. I don't understand it properly. So let’s use the -h flag to make it more readable.

Yeah, now that’s better.

pwd

This prints that path for your current directory.

Usually used when you forget which directory you are in while working and wish to remember again or to copy and paste the path of where you are working.

Note- By default Copy’s shortcut is Ctrl + Shift + c and for Paste it is Ctrl + Shift + v.

This image shows that I am currently in the folder called “articles” which is inside “tanav” which is in the “home” directory.

cd

cd refers to change directory. This command is used to move from one directory to another. In the pwd example, I was in the articles directory but now I wish to go to the Music directory I will type

My terminal

pwd here shows I am successfully in the Music directory.

My terminal

cd “Path to where I wish to go” is the basic syntax.

Now if I wish to go to a directory inside my current directory I just need to type cd “Name of directory”

Here I have gone to the Pop directory inside the music directory.

Other shortcuts used-

cd .. is used to move one directory above. i.e it will take me from Pop to Music directory.

cd or cd ~ This takes you directly to your home directory. For me it is /home/tanav/

cd . The dot here means the current directory. So this does absolutely nothing ( pretty useless command)

ls

This command lists the directories and files present inside the current directory.

Here the blue ones ( chad , linux and nice) are directories while file.txt and xyz are files.

Now there is another type of files called the “Dot Files” which are hidden files in the system. We use the -a flag to see such files along with normal ls outputs.

if you notice . .. and .something were not present in the output of ls

If you wish to see the files in verticle format -l flag used

These flags can be used together as well, -la flag shows both hidden files and files in verticle format.

Here the size 4096 isn’t in human-readable form so we use the -h flag to make it easier to read.

So, using the above flags together we get.

mkdir

mkdir is used to make new directories.

So, if I type mkdir noiceit will create a new directory called noice where I am.

Now in this series of commands, I made a directory called noice then moved into it using cd and showed its path using pwd

touch

touch means creating a new file.

Not only .txt but you can create any type of file using touch.

rm

This shows all the files and directories present inside the current directory.

rm in its normal state only deletes files. So, we use -d flag to delete empty directories.

Now see the file.txt and nice have been deleted. But using rm to delete the directory nice gave an error which was resolved by adding the -d flag.

Now, what will happen if we have to delete a directory with files/directories inside?

If you notice the -rf flags helped remove linux directory which was not empty.

-r here means recursive which recursively deletes the directory and its contents.

-f here is used to force delete.

At times rm command requires root user privileges (I will be explaining this in later articles).

Warning: Use rm -rf only and only if you are sure about what you are deleting. Do not delete any files/folders that are necessary for running Linux because being open source you do have the ability to delete/edit anything.

That’s all for today’s article. Stay Tuned for more.

--

--

Tanav Bajaj

Caffeine-fueled Prompt Engineer who can say "Hello World!" and train ML models like it's nobody's business!