Basic Commands In Linux

Windows, one of the most popular OS is now shipping a Linux kernel in it. Don’t you think this itself is enough to imagine how important Linux is?

Linux seems to be difficult for many, because of it’s command line. You may disagree with my statement here but none of the lazy people like this, mark my words.

Windows and Mac on the other hand make things simple because they execute or accomplish most of the things in simple click of buttons but internally they use commands only.

All the developer go through command executions everyday and if you ever wish to be one of them, you need to work with the available Commands in Linux.

To make your journey easier, I will explain everything about Linux Commands by taking an example of either Windows OS or Mac OS or even both.

Screenshot

What is Linux?

The first question that must be answered is this, before we move on to the other topics!

Linux is never available as an interface based OS that you can directly interact with either Window based visual interface or just a black and white command line terminal.

Linux is just the core of on OS and nothing on top of it. Literally, there is no way you can directly use a Linux Kernel as an OS without modifying it.

The one that you see online such as Ubuntu, Linux Mint, RHEL, Cent OS, etc. are all Linux kernel based OS distros.

Yes, that’s right. They are all Linux based OS and not Linux by themselves.

Linux the way it is available is known as Linux Kernel and not Linux OS that you can interact with and use it out of the box.

This is where company’s like RedHat and WindRiver took this Linux Kernel, modified it to have a Window based or just a command line or a terminal based user interface and sell it to others.

Think of Linux as a Text based command line Terminal

Almost all modern day Linux based OS are also come with Window based visual interfaces.

To be able to understand Linux command line, I want you to imagine Linux as a black and white command based terminal. I mean, you imagine there is no other way of interacting with whole system than this command line.

What is a Command in Linux?

When you double click on an icon in Windows OS, an application window opens for you.

This application may consists of a single .exe file or a .exe file with many internally dependent .dll files.

In Linux, a Command is exactly like a .exe file and it does not have any extension and it is of executable file type.

Either the command can run from it’s own binary file location or it may be dependent on something called as libraries, just like the .dll files on Windows.

Commands in Linux vs User Interface on Windows or Mac

When you turn on a Windows PC, what do you see when the system is ready? You see a screen that is called as desktop.

Now, from that screen what do you do? Let me guess…

  1. Either you open My Computer
    • This is equal to executing the cd command to the My Computer folder.
    • The My computer window visually shows different partitions as drives
    • cd to My Computer in Windows is equivalent to cd /mnt in Linux which shows the different mount points
  2. Or you double on an icon of an application or a game to open it
    • Basically this icon is equivalent to a soft link in Linux. Soft link is a link that points to the actual file.
    • Same in windows, if you right-click on the icon and see properties, it actually points to the locations of the .exe file of the app.
    • A double click is basically opening that file location or executing the application file or game.
    • In Linux, on the command line if you give the full path of the executable file it will start running just like an app on Windows.

So, what is the difference in Windows / Mac and Linux then?

You must be wondering if the underlying things are all same then what is the difference?

The difference is that, you just have to double-click the mouse left button to open either a folder / directory or an application on Windows.

But on Linux, you have to type the relevant commands to open the directory or an application using a command line.

So, the biggest difference is user experience. Windows seems to be easier to do things like this and Linux it seems to be difficult.

Also, on Windows you see what are the file names and directories easily on a visual format but on Linux everything is on the boring black colored command line.

Many modern-day Linux based OS or commonly known as Distros like Ubuntu, Linux Mint etc. have Windows like visual appearance of folders which makes life easier for beginners.

Well, these are some of the very basic usage when you login to a system. I hope you enjoyed reading and understanding till now.

Now, let’s look at some other day-to-day usage on User Interface based OS like Windows or Mac with respect to Linux command based.

Handling Files and Folders

Everything starts from a folder or directory location. The same is true on a Window based OS as well as command line line based Linux OS.

Present Working Directory Command

You cannot operate on let’s say D:\ drive while opening the C:\ drive in Windows, correct?

Which means, to be able to deal with a file or folder in a specific location, you need to go to that directory and do all the copy, delete operation you want to do.

So, the current directory is known as Present working directory in Linux. Because of a command line based OS, there is a pwd command in Linux that prints the whole path of the current directory you are operating on:

  • pwd
    • returns the full path of the current working directory.

PRO TIP:
Unlike visual interface based OS, Linux can copy, move or delete any files or directories without even entering to there.

For example, my pwd is /home/siba/

I can use this command to remove a file which is in some other directory.
rm /mnt/c-partition/delete-this-file.txt

While I am in /home/siba directory, I am still able to operate on a file which is in /mnt/c-partition/ in Linux. But in case of Windows or similar OS, you need to open that particular folder in a window and then click on the file to delete it.

Once you have understood the pwd concept and why it is important, let’s move on to understand what other things we can do with files and folders.

Dealing with files involve knowing the actual path of the file which we call as the source path. If it needs to be copied or moved to another location, then the new location is known as destination path.

The very basic thing involves listing of the files under a directory.

List command

What happens when you open a folder?

By default on a user interface based OS, it lists all files and directories in it and shows as an icon to interact with the file.

The same is done with ls command in Linux as below:

  • ls (lists all content of the current directory)
  • ls <location of a directory> lists down files and directories inside the folder path given in the command

As I gave an example on the pwd command explanation, if you know the actual file or directory name and the whole path, you do not need the ls command that frequently.

Copy Command

Let’s see how do we copy on a user interface based OS.

Select the file or folder, press Ctrl + c on Windows or command + c on Mac to copy it, and then on the destination folder and press Ctrl + v on Windows or command + v on Mac that copies in the same name.

You can also use eight click on mouse and do copy/ paste from there.

Let’s see how does it happen in Linux?

Well, on the command terminal, you execute the following command

  • cp source_folder/<filename> destination_folder/<filename>
  • cp -r source_folder/<folder-to-copy> destination_folder/

The difference is that, on the user interface based OS you just use the keyboard or mouse clicks to accomplish a task and also, you see a visual presentation of the copy progress and what is happening.

Move Command

Similarly when you do cut and paste with keyboard or mouse, you intend to remove the file or directory from the current location and move it to another location.

Here we use mv command in linux as below:

  • mv source_folder/<file or folder name to move> destination_folder/<filename>

Remove Command

To delete or remove a file you either use the Del key on keyboard or right click and select delete on a file or folder name.

You need to use rm command in linux to delete a file or folder

  • rm <filename> filename can be just the filename if it is present in the current directory.
  • rm -rf <directory-name> If you want to remove a directory in Linux, you need to add -rf option with the rm command.
    • -r recursively
    • -f forcefully

Conclusion

Human mind is design to do the easy things. That’s why Windows or others as a visual interface OS seems more easier to operate.

But you will never know how things are being carried out internally until you wish to learn command line in Linux.

This is where I came as a bridge to make you understand how things are done in a Linux command line interface as compared to what is happening in Windows, Mac, Ubuntu or any other visual based OS.

When you start working with commands in Linux, you will understand how powerful Linux is as compared to let’s say Windows OS.

Well, this is just the beginning and not the end of anything. Keep exploring other content on our site and I am sure this will help you understand Linux in a better way.

If you need any help for anything in Linux, leave a comment for me and I will reply you as soon as possible.