What is Linux?
Just like Windows XP, Windows 7, Windows 8, and Mac OS X, Linux is an operating system. An operating system is a software that manages all of the hardware resources associated with your desktop or laptop. To put it simply – the operating system manages the communication between your software and your hardware. Without the operating system (often referred to as the “OS”), the software wouldn’t function.
- “Linux” is only the kernel and is not the full system that you use.
- Out of the top 500 fastest supercomputers of the world, Linux or its variants power 498 of those badass machines. No wonder Linux is termed as the king of supercomputing. The other run a Unix variant.
- The killer app that made more people to adopt Linux was Apache Web Server.
- The Department of Defence of the US also uses Linux extensively. The Red Hat Linux runs the nuclear submarines of the State.
- The Scientific Linux controls the particle accelerator at CERN. It is based on Red Hat Linux and is again a free and open OS.
- Even the best smartphones (Android, Maemo) are built on Linux kernel. You can also run your Ubuntu Phone in a windowed mode with slight tweaks.
What is terminal?
A terminal emulator is a program that allows the use of the terminal in a graphical environment. As most people use an OS with a graphical user interface (GUI) for their day-to-day computer needs, the use of a terminal emulator is a necessity for most Linux server users.
Here are some free, commonly-used terminal emulators by operating system:
- Mac OS X: Terminal (default), iTerm 2
- Windows: PuTTY
- Linux: Terminal, KDE Konsole, XTerm.
What is the shell?
A Shell provides you with an interface to the Unix system. It gathers input from you and executes programs based on that input. When a program finishes executing, it displays that program’s output.
Shell is an environment in which we can run our commands, programs, and shell scripts. There are different flavours of a shell, just as there are different flavours of operating systems. Each flavour of a shell has its own set of recognized commands and functions.
- Bourne shell − If you are using a Bourne-type shell, the $ character is the default prompt.
The Bourne Shell has the following subcategories −
- Bourne shell (sh)
- Korn shell (ksh)
- Bourne Again shell (bash)
- POSIX shell (sh)
The prompt, $, which is called the command prompt, is issued by the shell. While the prompt is displayed, you can type a command.
Linux File Structure:
Shell commands for basic navigation:
cd (change directory) is useful to change current working directory.directory is nothing but the folder in windows terminology.
$cd “directory path you need to choose” =>this takes to the specified directory
$cd .. => This takes us to the previous directory
For example you are in home folder and
hemanth@ubuntu:~$ cd / this takes us to root
hemanth@ubuntu:/$ cd /home/hemanth this takes us to /home/hemanth directory here hemanth is sub folder in home folder
hemanth@ubuntu:/home/hemanth$ cd ../ it takes us to previous folder
hemanth@ubuntu:/home$cd ~ it takes us to home directory
ls lists files and directories.
$ls =>lists files,folders in the directory.
$ls “path” =>lists files,folders in the specified path.
$ls -a =>shows hidden folders.
$ls -l =>show all files in list with permissions,date,size
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”.
mkdir is for creating the new directory.
$mkdir “directory name”
rmdir is for deleting the directory:
rmdir “directory name”
rm command is used delete file.
rm “filename to delete”
cp is used to copy files from one directory to another directory.
cp “source” “destination”
mv is used to move files from one directory to another directory.
mv “source path” “destination path”
Till now we have explored commands that are used for file operation and navigation.Now let’s see some more useful linux commands.
chmod — Use chmod to make a file executable and to change the permissions granted to it in Linux. Imagine you have a python code named supercode.py in your computer. You’ll need to run “python supercode.py” every time you need to run it. Instead of that, when you make it executable, you’ll just need to run “supercode.py” in the terminal to run the file. To make a file executable, you can use the command “chmod +x supercode.py” in this case. You can use “chmod 755 supercode.py” to give it root permissions or “sudo chmod +x numbers.py” for root executable.
you might me be thinking that what is this 755.
it’s permissions for the given files
7 is 111 in binary.
5 is 101 in binary.
sudo is used to run any program or file as root.
$sudo apt-get install python
it runs apt-get as the privileged user.
Use ping to check your connection to a server. Wikipedia says, “Ping is a computer network administration software utility used to test the reachability of a host on an Internet Protocol (IP) network”. Simply, when you type in, for example, “ping howthingswork.club”, 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. The use of this command for simple users like us is to check your internet connection.
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. For example, if you want to install Wireshark, we can type in the command “sudo apt-get install wireshark”. Similarly, any packages can be installed like this.
sudo apt-get update updates repository
sudo apt-get upgrade updates packages
sudo apt-get dist-upgrade updates distro
apt search “package name” search packages
sudo apt-get remove “package name” remove package binaries
sudo apt-get purge “package name” removes packages,dependencies
nano is already installed text editor in the Linux command line. The nano command is a good text editor that denotes keywords with colour and can recognize most languages. You can create a new file or modify a file using this editor.
nano “filename” it opens file if exits else creates the file
CTRL+O for saving changes.
CTRL+X for exiting nano.
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 world”. 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 *world*that”.
Some Linux terminal tricks/tips:
- You can use the clear command to clear the terminal if it gets filled up with too many commands or by using shortcut Ctrl+L.
- TAB can be used to fill up in the terminal. For example, You just need to type “cd Des” and then TAB and the terminal fills the rest up and makes it “cd Desktop”.
- 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 power off or reboot the computer by using the command sudo poweroff and sudo reboot.
Linux is very powerful and it’s opensource.I heard stories of many people who tried Linux and then removed windows from their computers.
Mention your favourite distros or commands in the comments.