Skip to main content

Basic Linux Commands For Beginner's


Basic Linux Commands for Beginners
Linux is an Operating System’s Kernel. You might 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, 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”. A few of them are:
  • Mint
  • Ubuntu Linux
  • Red Hat Enterprise Linux
  • Debian
  • Fedora
  • Kali
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. Forgot to mention, the OS that runs in about 80% of the Smartphones in the World, Android, is also made from the Linux Kernel. Yes, Linux is amazing! A simple example of its security is that most of the viruses in the world run on Windows, but not on Linux!
Linux Shell or “Terminal”
So, basically, 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.
We can open the terminal by Ctrl+Alt+T in Ubuntu, or by pressing Alt+F2 and then typing in gnome-terminal and press Enter. In raspberry Pi, it is lxterminal that we should type in. There is also a GUI way of taking it, but this is better!
Linux Commands

Basic Commands

1. 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 “pwdcommand. It gives us the Absolute Path, which means the path that starts from the root. The root is the base of the Linux filesystem. It is denoted by a forward slash( / ). The user directory is usually something like /home/username.

2. ls
The “Is” command is used to know what files are there in the directory you are in. You can see all the hidden files by using the command “ls -a.
 Is
3. cd
cd” is the command used 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. But there is a problem with these commands. Imagine you have a folder named “Raspberry Pi”. In this case, when you type in “cd Raspberry Pi”, the shell will take the second argument of the command as a different one, so you will get an error saying that the directory does not exist. Here, you can use a backward slash. That is, you can use “cd Raspberry\ Pi” in this case. Spaces are denoted like this: 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.
 cd
4. mkdir & rmdir
The mkdir command is used 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. Remember, as told before, if you want to create a directory named “DIY Hacking”, then you can type mkdir DIY\ Hacking”.
rmdir is the command used for deleting a directory. But, rmdir can only be used to delete an empty directory. To delete a directory containing files, rm is used.
 mkdir-rmdir
5. rm
The rm command is used to delete files and directories. rm cannot simply delete a directory. “rm -ris used to delete a directory. In this case, it deletes both the folder and the files in it.
 rm
6. touch
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
 touch
7. man & –help
To know more about a command and on how to use it, the man command is used. It shows the manual pages of the command. For Example, “man cdshows 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 (Example – cd –help).
 

8. cp
The cp command is used to copy files through the command line. It takes two arguments, the first one is location of the file to be copied, the second is where to copy.
 
9. mv
The mv command is used 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.
mv
10. 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 Capital or Small). 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 it using asterisk (*). For example, to locate a file containing the words “hello” and “this”, you can use the command “locate –i *hello*this ”
locate

Intermediate Commands

1. echo
echo” is a command that helps us move some data, usually text into a file. For example, if you want to create a new text file or add into an already made text file, then 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.
2. cat
The cat command is used to display the contents of a file, usually used to easily view programs.
This command can also be used to create a file. Append contents to a file etc.
Eg:$cat >a.txt ( enter the file contents and press contl-D)
$cat >>a.txt ( append contents to a file)
$cat a.txt ( display the file content)
3. nano, vi
nano and vi are already installed text editors in the Linux command line. nano is a good text editor which denotes keywords with color and can recognize most of the languages. vi is simpler than nano. You can create a new file or modify one 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).
4. sudo
sudo is a widely used command in the Linux command line. sudo stands for “SuperUser Do”. So, if we want any command to be done with administrative or root privileges, then you can use the sudo command. For Example, if you want to edit a file like viz. alsa-base.conf which needs 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 in 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(it wasn’t misspelled, it is passwd). Then type in the new root password.
 5. df
The df command is used to see the available disk space in each of the partitions in your system. You can just type in df in the command line and you can see each mounted partition and their used/available space in % and in KBs. If you want it shown in megabytes, you can use the command “df -m
6. du
du is a command to know 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, then you can type in the command du and the name of the folder or file. For example, if you want to know the disk space used by the folder Documents in Linux, 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. uname
uname is a command used to show the Information about the system your Linux distro is running. Using the command “uname -aprints most of the information about the system. This prints the Kernel release date, version, processor type. etc.
8. apt-get
apt is a command used to work with packages in the Linux command line. apt-get is a command used to install packages. This requires root privileges, so we use the sudo command with it. For example, if we want to install the text editor gedit we can type in the command “sudo apt-get install gedit. Similarly, any packages can be installed like this. It is good to update your repository each 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 distro 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 in “apt-cache search gedit(This doesn’t require root).
9. hostname
hostname is a command used to know your name in your host or your network. Basically, it displays your hostname and IP address. Typing just “hostname” gives the output, your hostname. Typing in “hostname -Igives you your IP address in your network.
10. ping
ping is a command used to check your connection to a server. Wikipedia says that “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 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. The use of this command for simple users like us is to check your internet connection. If it pings the Google server (in this case), you can confirm that your internet connection is active!
Tips and Tricks in Using Linux Command Line
  • You can open a terminal by typing Ctrl-Alt-t
  • You can use clear command to clear the terminal if it gets filled up with too many commands!(Ctrl-l).
  • 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.

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Your 10 basic commands is very useful. Thanks for sharing. I am now learning using man pages. Found some more linux commands with 38 basic linux commands. Have a look.


    https://linoxide.com/linux-command/essential-linux-basic-commands

    ReplyDelete
  3. APTRON Gurgaon located in different places in Gurgaon. We are the best Training Institute offers certification oriented Linux Training in Gurgaon.
    For More Info: Linux Training in Gurgaon

    ReplyDelete

Post a Comment

Popular posts from this blog

Introduction to Data Structures

Visit My Data Structure Blog for Programs... It is important for every Computer Science student to understand the concept of Information and how it is organized or how it can be utilized. If we arrange some data in an appropriate sequence, then it forms a Structure and gives us a meaning. This meaning is called Information . A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. Data may be organized in many different ways. The logical model of a particular organization of data in a computer is called data structure. The choice of the model based on two considerations. It should be reflect the data in the real world. It should be simple that one can effectively process the data when necessary. E.g. Array, linked list, stack, queue, tree, graph Data structure can be classified into two: Linear: A data structure is said to be linear if its elements form a sequence E.g. Array, linked list, stack, queue Non-Linear: A dat

KTU-FOSS LAB Solutions

Write shell scripts to show the following  ( you can write menu driven programs)  Currently logged user and his logname   ( logname, id -un, echo $USER)  Your current shell ( echo $SHELL)  Your home directory ( echo $HOME)  Your operating system type (echo $OSTYPE)  Your current path setting ( echo $PATH)  Your current working directory ( echo $PWD )  Show Currently logged  users ( w or who -H)      Show only the user name of logged users in the host ( users)      Details of last login ( last mec  ;where mec is the user id )  About your OS and version, release number, kernel version                                                 ( uname -a or  cat  /proc/version)  Show all available shells ( cat /etc/shells )  Show mouse settings (cat  /sys/class/input/mouse*/device/name )  Show computer CPU information       CPU details      ( cat /proc/cpuinfo | more )       Show information on  CPU architecture ( lscpu)       Number of Processo