A beginners guide to must know linux commands
What is Linux
Linux is an operating system’s kernel.
It was created by Linus Torvalds from Scratch.
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”.
Why and where is Linux used
Linux is Mainly used in servers.
About 90% of the internet is powered by Linux servers.
This is because Linux is fast, secure, and free!
The main problem of using Windows servers are their cost. This is solved by using Linux servers.
The OS that runs in about 80% of the smartphones in the world, Android, is also made from the Linux kernel.
Most of the viruses in the world run on Windows, but not on Linux!
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. Linux’s shell is its main part. Its distros come in GUI (graphical user interface), but basically, Linux has a CLI (command line interface). In this tutorial, we are going to cover the basic commands that we use in the shell of Linux.
To open the terminal, press Ctrl+Alt+T in Ubuntu. There is also a GUI way of taking it, but this is better!
pwd: Tells the absolute path of current directory.
ls: list files in current directory.
ls -a: list files including hidden files.
cd: Change directory. Allows you to move to the desired directory.
eg. $cd games: navigates to game directory.
cd .. takes to parent directory
cd without any arguments takes to home directory.
mkdir and rmdir: Make and remove directories
eg. $mkdir dirname
rm : To delete files and directories. But rm cannot simply delete a directory. Use “rm -r” to delete a directory. In this case, it deletes both the folder and the files in it.
eg. $rm filename
$rm -r dirname
touch: Used to create a file. It can be anything, from an empty .txt file to an empty .zip file.
eg. $touch new.txt
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.
eg. $cp new.txt Desktop
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.
sudo: A widely used command in the Linux command line, sudo stands for “SuperUser Do”. So, if you want any command to be done with administrative or root privileges, you can use the sudo command.
apt-get: Use apt to work with packages in the Linux command line.
Use apt-get to install packages. This requires root privileges, so use the sudo command with it. e.g if you want to install the text editor jed, we can type in the command “sudo apt-get install jed”. Similarly, any packages can be installed like this. You can upgrade the system by typing “sudo apt-get upgrade”.
We can also upgrade the distro by typing “sudo apt-get dist-upgrade”.
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 cd” shows the manual pages of the cd command. Typing in the command name and the argument helps it show which ways the command can be used (e.g., cd –help).
locate: The locate command is used to locate a file in a Linux system, just like the search command in Windows. This command is useful when you don’t know where a file is saved or the actual name of the file.
Using the -i argument with the command helps to ignore the case (it doesn’t matter if it is uppercase or lowercase). So, if you want a file that has the word “hello”, it gives the list of all the files in your Linux system containing the word “hello” when you type in “locate -i hello”. If you remember two words, you can separate them using an asterisk (*). For example, to locate a file containing the words “hello” and “this”, you can use the command “locate -i *hello*this”.
echo — The “echo” command helps us move some data, usually text into a file. For example, if you want to create a new text file or add to an already made text file, you just need to type in, “echo hello, my name is alok >> new.txt”. You do not need to separate the spaces by using the backward slash here, because we put in two triangular brackets when we finish what we need to write.
cat — Use the cat command to display the contents of a file. It is usually used to easily view programs.
e.g $cat new.txt
Tips and Tricks for Using Linux Command Line
- You can use the clear command to clear the terminal if it gets filled up with too many commands.
- TAB can be used to fill up in terminal. For example, You just need to type “cd Doc” and then TAB and the terminal fills the rest up and makes it “cd Documents”.
- Ctrl+C can be used to stop any command in terminal safely. If it doesn’t stop with that, then Ctrl+Z can be used to force stop it.
- You can exit from the terminal by using the exit command.
- You can power off or reboot the computer by using the command sudo halt and sudo reboot.
Thank you for reading. If you like the article give it a clap 👏
Do consider Buying me a Coffee https://www.buymeacoffee.com/ananya, If you loved the article.
I am Ananya Agrawal. I am currently working as a software engineer at Gojek. I am working on building Feature Monkey a customer feedback tracker that can be used for feature request tracking, internal feedback, public roadmap, etc.
Reach out to me over https://twitter.com/AgrawalAnanyaa.