Linux basic commands

From HPC Guide
Jump to navigation Jump to search

What Is Linux?

Linux is an operating system. You might have heard of UNIX. Well, Linux is not UNIX clone. It is GNU project and GNU is a recursive acronym for "GNU's Not Unix!", chosen because GNU's design is Unix-like, but differs from Unix by being free software and containing no Unix code First kernel and gcc compiler was actually created by Linus Torvalds.
Linux is free and open-source, that means that you can simply change anything in Linux and redistribute it in your own name!
There are several Linux Distributions, commonly called “distros”.

  • Ubuntu Linux
  • Red Hat Enterprise Linux
  • Linux Mint
  • Debian
  • Fedora

About 90% of the internet is powered by Linux servers. If You use Android - it is Linux distributive.
All of the viruses in the world run on Windows.

Linux Shell or “Terminal”

So, basically, a shell is a program that receives commands from the user and gives it to the OS to process, and it shows the output.
In this tutorial, we are going to cover the basic commands that we use in the shell of Linux.

Linux Commands

1. pwd — When you first open the terminal, you are in the home directory of your user. To know which directory you are in, you can use the “pwd” command.
It gives us the absolute path, which means the path that starts from the root. The root is the base of the Linux file system.
It is denoted by a forward slash( / ). The user directory is usually something like "/home/username".

Pwd-Example3.png


2. ls — Use the "ls" command to know what files are in the directory you are in. You can see all the hidden files by using the command “ls -a”.

Ls-example.png


3. cd — Use the "cd" command to go to a directory. For example, if you are in the home folder, and you want to go to the downloads folder, then you can type in “cd Downloads”.
Remember, this command is case sensitive, and you have to type in the name of the folder exactly as it is.
If you just type “cd” and press enter, it takes you to the home directory.
To go back from a folder to the folder before that, you can type “cd ..” . The two dots represent back.

Cd-example.png


4. mkdir & rmdir — Use the mkdir command when you need to create a folder or a directory.
For example, if you want to make a directory called “DIY”, then you can type “mkdir DIY”.
Use rmdir to delete a directory.But rmdir can only be used to delete an empty directory. To delete a directory containing files, use rm.

Rm-example.png


5. rm - Use the rm command to delete files and directories. Use "rm -r" to delete just the directory.
It deletes both the folder and the files it contains when using only the rm command.

Rm-example2.png


6. touch — The touch command is used to create a file. It can be anything, from an empty txt file to an empty zip file. For example, “touch new.txt”.

Touch-example.png


7. man & --help — To know more about a command and how to use it, use the man command. It shows the manual pages of the command.
For example, “man touch” shows the manual pages of the touch command. Typing in the command name and the argument helps it show which ways the command can be used (e.g., cd –help).

Help-example.png


Man-example.png


8. cp — Use the cp command to copy files through the command line. It takes two arguments: The first is the location of the file to be copied, the second is where to copy.

Cp-example.png


9. mv — Use the mv command to move files through the command line. We can also use the mv command to rename a file.
For example, if we want to rename the file “text” to “new”, we can use “mv text new”. It takes the two arguments, just like the cp command.

Mv-example.png