Apisero is now part of NTT DATA - Learn more.

Close this search box.

Getting Started With Linux: A Beginner’s Primer (Part-3)

Author: Ayush Maggo

Advanced Commands
  • du command

The du command gives the size of a directory as a whole.

$ du

Here 4 is bytes. Running du * will calculate the size of each directory individually.

$ du *
0       app
4       ayush
0       orange

du -m display values in MB and du -g display values in GB.

  • PATH variable command

Using the path command, we can see the current PATH of the directory.

$ echo $PATH
  • ping command

The ping command ensures whether you are connected to the internet or not.

$ ping google.com

Press ctrl+c to stop the loop. Use the “-c” flag to pass the number of times you want the packet from the server as a response.

$ ping -c 2 is the Google Public DNS IP address.

  • sudo apt update command

The sudo apt update command is used to update the local package index on our Linux System. When you run this command, it contacts the software repositories configured on your system and checks for any update to the packages.

$ sudo apt update

apt – Advanced Package Tool.

  • sudo apt upgrade command

This command is used to update the Linux system’s installed packages. When you run this command, it checks for any updates available for the installed packages and performs the upgrade process.

$ sudo apt upgrade
  • wget command

The wget (web get) command is used to download the file from the internet. It is used for retrieving files from the web using various protocols, such as HTTP, HTTPS, and FTP.

$ wget [option] [URL]
$ wget https://static.photocdn.pt/images/articles/2018/12/05/articles/2017_8/beginner_photography_mistakes-1.webp
Resolving static.photocdn.pt (static.photocdn.pt)...,,, ...
Connecting to static.photocdn.pt (static.photocdn.pt)||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 29840 (29K) [image/webp]
Saving to: ‘beginner_photography_mistakes-1.webp’
. . .
  • curl command

Using one of the following protocols, HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP, or FILE, Curl sends or receives data to or from a server. We essentially read the contents of the file at the URL.

In order to get a web page and show it in the terminal:

$ curl https://www.javatpoint.com/what-HYPERLINK "https://www.javatpoint.com/what-is-computer" HYPERLINK HYPERLINK "https://www.javatpoint.com/what-is-computer""https://www.javatpoint.com/what-is-computerHYPERLINK "https://www.javatpoint.com/what-is-computer""HYPERLINK "https://www.javatpoint.com/what-is-computer"isHYPERLINK "https://www.javatpoint.com/what-is-computer" HYPERLINK HYPERLINK "https://www.javatpoint.com/what-is-computer""https://www.javatpoint.com/what-is-computerHYPERLINK "https://www.javatpoint.com/what-is-computer""HYPERLINK "https://www.javatpoint.com/what-is-computer"-computer
  • grep command

The grep (Global Regular Expression Print) command is used to search for matching patterns in a file.

Look for the word “Linux” in a file:

$ grep "Linux" free.txt
Hello John, welcome to Linux blog!
Hope this Linux blog gives you insights regarding Linux.
  • less command

The less command displays the content stored inside in a file.

less <filename>

By pressing “q”, you can quit the less session.

  • head command

It displays the starting content of a file. It shows the first 10 lines of any file by default.

$ head <filename>

If we want to display the contents of multiple files:

	$ head <file1> <file2>

“-n” option displays starting n lines of the file.

$ head -n <filename>
  • tail command

The tail command is used to display the last part of a file (ten lines of a file).

$ tail <filename>

If we want to display the contents of multiple files:

$ tail <file1> file2>

“-n” option displays the specific number of lines from the end.

$ tail -n 4 <filename>

4 is the number of lines we want to display.

  • more command

The more is similar to cat command, but the only difference is, in case of larger files, ‘cat’ command output will scroll off your screen while ‘more’ command displays output one screenful at a time.

$ more <filename>

By pressing “q”, you can quit the less session.

  • sort command

The sort command is used to sort file contents, and the output of the operation is printed on standard output.

$ sort <filename>

To reverse the order, use the “-r” flag.

$ sort -r <filename>

Use the “-u” flag to remove the duplicates.

$ sort -u <filename>
  • ps command

The ps command displays the list of currently running processes in the  Current session with their PIDs and some other information.

$ ps
    8 tty1     00:00:04 bash
 9454 tty1     00:00:00 ps
. . .

Use “ax” to list all processes.

$ ps ax
  • tee command

The tee command simultaneously reads from standard input and writes to one or more files as well as standard output. The Tee is frequently used with other commands via piping.

$ df | tee disk.txt
Filesystem     1K-blocks      Used Available Use% Mounted on
rootfs         499473404 185605524 313867880  38% /
none           499473404 185605524 313867880  38% /dev
. . .

$ cat disk.txt
$ df | tee disk.txt
Filesystem     1K-blocks      Used Available Use% Mounted on
rootfs         499473404 185605524 313867880  38% /
none           499473404 185605524 313867880  38% /dev
. . .

$ cat disk.txt
Filesystem     1K-blocks      Used Available Use% Mounted on
rootfs         499473404 185605524 313867880  38% /
none           499473404 185605524 313867880  38% /dev
. . .

  • uname command

This command returns the Operating system name.

$ uname

The “-m” flag gives the hardware name.

The “-p” flag gives the processor architecture.

The “-n” flag gives the network name.

  • df command

The df command displays the disk usage information.

$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
rootfs         499473404 185652532 313820872  38% /
none           499473404 185652532 313820872  38% /dev
. . .

Using the “-h” option will show those values in readable form.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs          477G  178G  300G  38% /
none            477G  178G  300G  38% /dev
. . .
  • awk command

It is used for text manipulation and processing.

$ df -h | awk '{print $1}'
. . .

print $1 – prints the 1st column.

print $2 – prints the 2nd column. And so on

awk ‘{print $2 “ “ $3 “ “ $5}’ – prints the 2nd, 3rd and 5th column.

  • netstat -a command

This command gives the status of the internet connection.

$ netstat -a
  • Counting files in a directory

The ls command shows all the files and directories. If you pipe the output to WC -l then it counts the number of files in the directory.

$ ls | wc -l
  • yum command

Yum – Yellowdog Updater Modified

Yum is a Linux command and package manager used in Red Hat based Linux distribution, such as Red Hat Enterprise Linux (RHEL), CentOS and Fedora. It simplifies the installation, updating, and removal of software packages of the system.

$ yum install <package_name> – To install packages in the system

$ yum list <package_name> – To list a package.

$ yum search <package_name> – To search the package installed in your Linux system.

$ yum remove <package_name> – To remove packages.

$ yum update <package_name> – To update packages.

$ yum info <package_name> – To get information about a package.

$ yum list installed | less – To see installed packages in your Linux system

  • SED command:

SED is a very important command. It is used to edit files quickly and efficiently. It performs various functions like replacing, adding, deleting, inserting, and finding lines from a specified file without opening the file in a text editor. SED stands for Stream Editor.

Replace string using sed command:

$ sed 's/old_text_you want_to_replace/new_new/' filename.txt
  • Extracting and Creating a tar file

Sometimes we download tar files so we need to extract those tar files using the following commands. For below command, open the terminal and navigate to the directory where the tar file is located.

$ tar -xzvf file.tar.gz

This command extracts the files in the current directory:

$ tar -xvf file.tar

Creating a .tar file

$ tar -cvf archive.tar samplefile.txt	
  • ifconfig command:

This command displays network interface information.

$ ifconfig

Below command fetch your public IP address:

$ curl ifconfig.me
  • which command:

Suppose you have a command you can execute, because it is in the shell path, but you want to know where it is located, then we use this command. It gives the exact path of the executable command.

$ which ls
$ which which
$ which sed
  • top command:

When you run the top command, it displays the system’s processes, CPU status, and memory status.

Press “q” to exit from the top.

$ top
  • /etc/passwd file command

This command shows all the users available in the system.

$ cat /etc/passwd
. . .

Each line shows seven different entries:


  • locate command:

Locate command is used to find files in the system. Like below command will search all the files with hello in the name:

$ locate hello

We have one more command to find files and directories i.e. find command.

$ find . -name "*.txt"
. . .
  • Sort files by size:

To sort the files by size, you can use ls -lSh command.

$ ls -lSh
total 0
-rw-r--r-- 1 ayush ayush 524 Jun  5 17:37 disk.txt
-rw-r--r-- 1 ayush ayush 512 Jun  5 14:23 free.txt
-. . .
  • To view all running processes:

The ps aux command displays all the processes running in our system.

$ ps aux
  • To find a particular process:

If I want to know the process id of a particular process, then use the below command.

$ ps aux | grep <process_name>
  • To kill or stop a particular process

Use kill command to kill a particular process.

$ kill <process_id>

We got the process id from the above command.

  • host command

The host command is used to obtain Domain Name System name.

It will show the IP address of any given hostname.

$  host www.google.com
www.google.com has address
www.google.com has IPv6 address 2404:6800:4002:82e::2004
  • Mounting a file

Use the below command to mount a file.

$ sudo mount /dev/sdb2 /mnt

Mounted /dev/sdb2 on the /mnt directory.

  • How to add a new user

The “adduser” command is used to add new user.

$ sudo useradd <user_name>

The next step is to use the “passwd” command to create a password for the 

new user.

$ sudo passwd <user_name>
  • How to add a new group

To add a group, use the “groupadd” command.

sudo groupadd <group_name>
  • How to delete a user

To delete a user, use the “userdel” command.

sudo userdel <user_name>

Important links:

Linux -> https://www.linux.org/forums/#linux-tutorials.122

Happy Learning!

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.