Linux Commands: Learn the basic linux commands, an operating system which is free and open source, you can make changes and re-distribute.
What is Linux?
Linux is a kernel of the operating system. You may have heard of UNIX. Well, Linux is a UNIX clone. But it was actually created by Linus Torvalds from Scratch. Linux is free and open-source, this means that you can modify 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
Linux is basic used on servers. About 90% of the internet is powered by Linux servers. This is because Linux is fast, secure, and free! The main problem with using Windows servers is their cost. Resolved this by using Linux servers. The OS that runs on about 80% of smartphones in the world, Android, is also made from the Linux kernel. Most of the virus in the world runs on Windows, but not on Linux!
Linux Shell or “Terminal”
So, usually, a shell is a program that accepts commands from the user and gives it to the OS to process, and it displays the output. The Linux shell is the main part of it. The its distress is comes in GUI (graphical user interface), but usually, there is a Linux (CLI) command line interface. In this tutorial, we will cover the basic commands we use in the Linux shell.
To open the terminal, press Ctrl + Alt + T on Ubuntu, or press Alt + F2, type gnome-terminal, and press enter. In Raspberry Pi, type in lxterminal . There is also a GUI way of getting it, but it’s even better!
Basic Linux Commands
1. pwd – When you first open the terminal, you are in your user’s home directory. To find out which directory you are in, you can use ” Pwd ” command. It gives us the full path, which means path starting at the root. The root is the base of the Linux file system. It is determined by a forward slash ( / ). The user directory is usually something like “/ home / username”.
2. ls – Use the ” ls ” Command to find out what files in the directory you are in. You can see all the hidden files by using the command ” Ls -a” .
3. cd – Use the “cd” command to go to a directory. For example, if you’re in your home folder, and you want to go to the download folder , you can type “Cd Downloads” . Remember, this command is case sensitive, and you need to type the name of the folder exactly what it is. But there are problems with these linux commands. Imagine you have a folder named “Raspberry Pi”. In this case, when you type “Cd Raspberry Pi ” , the shell will take a second argument of the command as another, so you will get an error saying that the directory does not exist. Here, you can use a back slash. That is, you can use “Cd Raspberry \ Pi” in this case. These spaces are indicated like this: If you type only “Cd” and press enter, you’ll be taken to the home directory. To return from a folder folder before that, you can type ” cd .. “. The two dots represent the back.
4. mkdir & rmdir – Use the mkdir command when you need to create a folder or a directory. For example, if you want to create a directory called “DIY”, you can type ” Mkdir DIY “. Remember, as said before, if you want to create a directory named “DIY Hacking”, then you can type ” mkdir DIY \ Hacking “. Use rmdir to delete a directory. But rmdir can only be used to remove an empty directory. To delete a directory containing the files, use rm .
5. rm – Use the rm command to delete files and directories. Use the ” rm -r “to delete the directory only. It removes the same folder and the files that contain it when using only the rm command.
6. touch – The touch The command is used to create a file. It can be anything, from an empty txt file into an empty zip file. For example, ” pressthe new.txt “.
7. man & – help – To find out more about a command and how to use it, use man command. It shows the manual pages of command. For example, the ” man cd “shows manual pages of cd command. Typing in the name of the command and the argument helps show it which methods can be used (for example, cd – help ) .
8. cp – Use the cp Command to copy files through command line. Two arguments are needed: The first is the file location to be copied, the second is where to copy.
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 ” text “that file in ” before “, we can use the” mv text new “. Two arguments are required, such as cp command.
10. find it – The find it The command is used to find a file on a Linux system, such as the Windows search command. This command is useful when you do not know where you saved the file or the actual file name. Use of – iargument using the command helps to ignore the case (it does not matter if it is uppercase or lowercase). So, if you want a file with the word “hello”, it gives the list of all the files in your Linux system that contains the word “hello” when you type in “find – i hello “. If you remember two words, you can separate them using an asterisk (*). For example, to find a file containing the words “halo” and “it”, you can use the command ” find – i * hello * it “.
Intermediate Linux Commands
1. echo – The command of ” echo “helps us transfer some data, usually text to a file. For example, if you want to create a new text file or add to a completed text file, you just need to type, ” echo hello, my name is offer >> new.txt “. You do not need to separate the spaces in by using backward slash here, as we place two triangular brackets when we finish what we need to write.
2. paint – Use the paint command to display the contents of a file. It is commonly used to easily view programs.
3. nano , vi, jed – nano and vi are installed text editors on the Linux command line. The nano The command is a great text editor indicating keywords color and can identify most languages. At vi is simpler than that nano . You can create a new file or change a file using the editor. For example, if you need to create a new file named ” check.txt “, you can do this by using the command” nano check.txt “. You can save your files after editing by using the order Ctrl + X , then Y (or N for not). In my experience, used nano for HTML editing does not look good, because of color its , so I recommend jed text editor. We’re going to be installing packages soon.
4. sudo – A widely used command in the Linux command line, sudo represents the ” SuperUser Do “. So, if you want any command to do with administrative privileges or root, you can use sudo command. For example, if you want to edit a file you like viz. alsa-base.conf , which requires root permissions, you can use the command – sudo nano alsa-base.conf You can enter the root command line using the command ” sudo bash “, then type your user password. You can also use the command ” su “to do this, but you need to set a root password before that. For that, you can use the command ” sudo passwd “( not wrong, it is passwd ). Then type the new root password.
5. df – Use the df Command to see available disk space on each of the partitions in your system. You can just type df in the command line and you can see each mounted partition and their used / usable space in% and in KBs.If you want it displayed in megabytes, you can use the command ” df -m “.
6. du – Use du to find out the disk usage of a file in your system. If you want to know the disk usage for a particular folder or file in Linux, you can type the command df and the name of the folder or file. For example, if you want to know the disk space used by the Linux documents folder, you can use the command ” du Documents “. You can also use the command ” ls – lah “to view the file sizes of all the files in a folder.
7. tar – Use tar to work on tarballs (or files compressed with a tarball archive) in the Linux command line. It has a long list of uses. It can be used to compress and re- uncompressed different types of tar archives like this .tar, .tar.gz,. tar.bz2 , etc. . It works based on the arguments given here. For example, ” tar – cvf “for creating a . tar archive , – xvf to untar a tar archive, – tvf to list the contents of the archive, etc. Since this is a broad topic, here are some examples of tar linux commands .
8. zip , unzip – Use zip to compress files in a zip archive, and unzip to extract files from a zip archive.
9. uname – Use uname to display information about your Linux system distro is running. Using the command “uname -a “prints most information about the system. Print date of kernel release, version, processor type, etc.
10. apt-get – Use apt to work with packages in the Linux command line. Use apt-get to install packages. It requires root privileges, so use sudo Command it. For example, if you want to install the text editor jed (as I mentioned earlier), we can type the command ” sudo apt-get install jed “. Similarly, any packages can be installed like this. It’s best to update your storage every time you try to install a new package. You can do that by typing ” sudo apt-get update “. You can upgrade the system by typing ” sudo apt-get upgrade “. We can also upgrade the registry to by typing ” sudo apt-get dist- upgrade “. The command ” apt -cache search “is used to search for a package. If you want to search for one, you can type ” apt-cache search jed “( it does not require root).
11. chmod – Use chmod to perform an executable file and to modify the permissions granted here on Linux. Think you have a python code named numbers.py on your computer. You will need to run the ” python numbers.py “whenever you need to run it. Instead, when you do it, you will need to run ” numbers.py “in the terminal to run the file. To make a file enforceable, you can use the command ” chmod + x numbers.py “in this case. You can use the ” chmod 755 numbers.py “to give it root permissions or” sudo chmod + x numbers.py “for executable root. Here are some more information about command of chmod .
12. hostname – Use hostname to know your name in your host or network. Basically, it shows your hostname and IP address. Just typing ” hostname “gives output. Typing in ” hostname -I “gives you your IP address in your network.
13. ping – Use ping to check your connection to a server. Wikipedia says, ” Ping is a utility of computer network management software used to test the reach of a host on an Internet Protocol (IP) network . ” Simply put, when you type, for example,” ping google.com “, It checks if it can connect to the server and back It measures the time of the round-trip and gives you details about it. The use of this command for simple users like us to check your internet connection. If it’s on Google’s server (in this case), you can confirm that your internet connection is active!
Tips and Tricks for Using the Linux Command Line
- You can use clear Command to clear the terminal if it gets filled with too many linux commands.
- TAB can be used to fill in the terminal. For example, You need just type ” cd Doc “and then TAB and the terminal fills the rest and makes ” cd Documents “.
- Ctrl + C Can be used to prevent any terminal command from being safe . If it does not stop then, then Ctrl + Z can be used to force it.
- You can exit from the terminal by using come out command.
- You can kill or reboot the computer by using the command sudo stopped and sudo reboot .