Use Linux Terminal like a pro after Learning this Linux Commands:become zero to Hero in linux

linux commands

What is Linux?

tux penguin

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 facts:

  1. “Linux” is only the kernel and is not the full system that you use.
  2. 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.
  3. The killer app that made more people to adopt Linux was Apache Web Server.
  4. The Department of Defence of the US also uses Linux extensively. The Red Hat Linux runs the nuclear submarines of the State.
  5. The Scientific Linux controls the particle accelerator at CERN. It is based on Red Hat Linux and is again a free and open OS.
  6. 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.

Shell Types

 

  • 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)

Shell Prompt

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:

linux file structure

Shell commands for basic navigation:

cd:

 cd (change directory)  is useful to change current working directory.directory is nothing but the folder in windows terminology.

Usage:

$cddirectory 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:

ls lists files and directories.

Usage:

$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,sizels


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


mkdir:

mkdir is for creating the new directory.

Usage:

$mkdir “directory name”


rmdir:

rmdir is for deleting the directory:

usage:

rmdir “directory name”


rm:

rm command is used delete file.

usage:

rm “filename to delete”


cp:

cp is used to copy files from one directory to another directory.

usage:

cp “source”    “destination”


mv:

mv is used to move files from one directory to another directory.

usage:

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

———————-root  ——————user—————–group———————————-

read-write-execute————–read-write-execute———————-read-write-execute

1-1-1—————————————-1-0-1 —————————————-1-0-1

7 is 111 in binary.

5 is 101 in binary.

sudo:

sudo is used to run any program or file  as root.

example:

$sudo apt-get install python

it runs apt-get as the privileged user.

ping:

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.


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. 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:

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.

Usage:

nano “filename”  it opens file if exits else creates the file

CTRL+O for saving changes.

CTRL+X for exiting nano.


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 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.

 

Conclusion:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *