A shell is a program that receives commands from the user and gives it to the OS to process, and it shows the output.
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 /
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”.
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 have spaces in the name of the Dirctory use backslash cd Raspberry\ Pi
.
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.
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.
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”.
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.
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.
Moving file to another directory:
The locate command is used to locate a file in a Linux system, just like the search command in Windows.
Using the -i argument with the command helps to ignore the case.
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
.
Use the cat command to display the contents of a file. It is usually used to easily view programs.
nano and vi are already installed text editors in the Linux command line. vi is simpler than nano.
You can create a new file or modify a file using this editor. For example, if you need to make a new file named "check.txt", you can create it by using the command “nano check.txt”.
You can save your files after editing by using the sequence Ctrl+X, then Y (or N for no).
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.
Use chmod to make a file executable and to change the permissions granted to it in Linux.
Imagine you have a python code named numbers.py in your computer. You'll need to run “python numbers.py” every time you need to run it. Instead of that, when you make it executable, you'll just need to run “numbers.py” in the terminal to run the file.
To make a file executable, you can use the command “chmod +x numbers.py” in this case.
You can use “chmod 755 numbers.py” to give it root permissions or “sudo chmod +x numbers.py” for root executable.
Use hostname to know your name in your host or network. Basically, it displays your hostname and IP address. Just typing “hostname” gives the output.
Use ping to check your connection to a server.
Simply, when you type in, for example, ping google.com
, it checks if it can connect to the server and come back. It measures this round-trip time and gives you the details about it.
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.