Top Basic Linux Commands That You Must Know

To learn the basic and useful commands of Linux that will help you to monitor and control the system in an efficient manner

To use Linux in an effective manner, you can use a terminal(command line) that gives you control over the operating system services. To use a command line for more control and quicker execution of tasks, you must know the basic commands. In this hands-on lab, we are going to learn the top basic Linux commands that help you to understand and use Linux systems in an effective manner. So let’s get started

reference-https://kinsta.com/wp-content/uploads/2021/09/linux-commands-1024x512.jpg
reference-https://kinsta.com/wp-content/uploads/2021/09/linux-commands-1024×512.jpg

What is a Linux command?

Linux command is a program or utility that runs on the command lineThe command line is an interface that takes text from the user’s keyboard and processes them into instructions for your system. The Linux command line is case-sensitive.

Linux commands are basically used to perform multiple tasks, like handling different processes, monitoring the whole system, installing packages, file manipulating, handling system services, etc.

Syntax:

command [option(s)] <arguments>

command – is a small executable program located on a Linux disk (generally at /usr/local/bin location)

option(s) – works as a switch, used to pass the parameter to a program(command). It modifies or changes the execution of the command.

argument(s) – provides the required information for a command to execute.

Linux commands

The Linux system has a number of commands. In this hands-on lab, we will learn the top primary and most useful commands, which will help us understand the Linux system and complete some basic tasks.

Linux Commands Cheat Sheet

For quick reference, review the below table for basic Linux commands.

IndexCommandUsage
1man This command provides a user manual for commands.
2ls This command lists the content of a directory.
3cd This command is used to change directory.
4cp This command is used to copy files and directories.
5mv This command is used to move or rename the files and directories.
6cat This command is used to show file content.
7touch This command is used to create a new empty file.
8mkdir This command is used to create directories.
9rm This command is used to delete(remove) file or directory (directory recursively can be deleted)
10pwd This command is used to print the working directory.
11findThis command is used search the file in directories.
12apt or apt-get This command is used to install/update/delete the package as it is a package manager tool.
13grepThis command is used to search and print the lines on a terminal that match the pattern.
14lessThis command is used to read/inspect files interactively (page wise)
15headDisplay first lines of a file (by default shows 10 lines)
16tailDisplay last lines of a file (by default shows 10 lines)
17echoDisplay text/string on terminal
18psThis command is used to print processes status from the linux system.
19topThis command is used to print processes status and detailed information in real-time (dynamic)
20sudoThis command is used to execute the command as a super user by giving root user privileges.
21useraddThis command is used to add new users to the system.
22passwdThis command is used to set passwords for users.
23userdelThis command is used to delete user.
24historyThis command is used to show the list of previously executed commands

Now, let’s dive deep into all the commands mentioned in the cheat sheet above one by one.

man command

man [OPTION]... [COMMAND NAME]...

This is one of the most useful commands in the Linux system. There are multiple commands(packages) with different functionalities and as a user/programmer who wants to get a user manual for that specific command. The man command provides detailed information about that specific command.

man mkdir

NOTE:If the above command doesn’t work , then run unminimize command and then again execute the man command.

MKDIR(1)                         User Commands                        MKDIR(1)

NAME
       mkdir - make directories

SYNOPSIS
       mkdir [OPTION]... DIRECTORY...

DESCRIPTION
       Create the DIRECTORY(ies), if they do not already exist.

       Mandatory  arguments  to  long  options are mandatory for short options
       too.

       -m, --mode=MODE
              set file mode (as in chmod), not a=rwx - umask

To exit the manual page press q.You can use the man --help command for more information about options.

ls Command

ls [options] [file...|directory..]

The ls command is used to display all the content (files and directories) from the current and other directories. 

ls

And if you want to see all content along with hidden directories and files, you can use the -a option.

ls -a /etc
root@master:/etc# ls -a
.                       dconf           hosts            mailcap                 profile      ssh
..                      debconf.conf    hosts.allow      mailcap.order           profile.d    ssl
.pwd.lock               debian_version  hosts.deny       mdadm                   protocols    subgid
NetworkManager          default         init.d           mime.types              python3      subgid-
X11                     deluser.conf    initramfs-tools  mke2fs.conf             python3.8    subuid
adduser.conf            depmod.d        inputrc          modprobe.d              rc0.d        subuid-
alternatives            dhcp            iproute2         modules                 rc1.d        sudoers
apparmor                dpkg            iscsi            modules-load.d          rc2.d        sudoers.d

The -foption is used to list the files without sorting.

ls -f *.conf /etc
root@master:/etc# ls -f *.conf
adduser.conf          deluser.conf  gai.conf         ld.so.conf     nsswitch.conf           resolv.conf  xattr.conf
ca-certificates.conf  e2scrub.conf  host.conf        libaudit.conf  overlayroot.local.conf  sysctl.conf
debconf.conf          fuse.conf     kernel-img.conf  mke2fs.conf    pam.conf                ucf.conf

Few other important options for ls command

-l – option used for long listing format

-t – to sort files depends on modification time, priority is for newest file

-r – reverse the order

ls -ltr /etc
root@master:/etc# ls -ltr
total 628
-rw-r--r-- 1 root root     887 Apr  1  2013 rpc
-rw-r--r-- 1 root root    2932 Apr  1  2013 protocols
-rw-r--r-- 1 root root     280 Jun 20  2014 fuse.conf
-rw-r--r-- 1 root root     604 Sep 15  2018 deluser.conf
-rw-r----- 1 root daemon   144 Nov 12  2018 at.deny
-rw-r--r-- 1 root root    1260 Dec 14  2018 ucf.conf
-rw-r--r-- 1 root root    2969 Aug  3  2019 debconf.conf

The hidden file and folder are shown as dot (.). For more information about options, you can use the ls –help command.

cd command

cd <directory path>

While using the terminal due to different tasks it’s important to move through the different directories. The cd command (change directory) is used to change the current working directory.

cd /etc/
root@master:~# cd /etc/
root@master:/etc# 

For more information about options, you can use the cd --help command.

cp command

cp [option(s)] <source path> <destination path>

cp(copy) command stands for copying files and directories from the source path to the destination path. with the help of the cp command.

cp /etc/os-release /tmp/
ls /tmp/
root@master:~# cp /etc/os-release /tmp/
root@master:~# ls /tmp/
90c64056-cc2c-4ab1-bf2b-483710782cb5  snap-private-tmp                                                                   theia_upload
github-remote                         systemd-private-18d3f426ac60466095bf08e28614578f-systemd-logind.service-R42Ifi     tmp.TLTiecjcIl
http-remote                           systemd-private-18d3f426ac60466095bf08e28614578f-systemd-resolved.service-2DHEyi
os-release                            systemd-private-18d3f426ac60466095bf08e28614578f-systemd-timesyncd.service-S21i9h

You can also copy the whole directory in a recursive manner by using the “-r” option.

 cp -r <source_dir_name> <destination path>
cp -r /tmp ~/temp
ls ~/temp
root@master:~# cp -r /tmp ~/temp
root@master:~# ls ~/temp
90c64056-cc2c-4ab1-bf2b-483710782cb5  snap-private-tmp                                                                   theia_upload
github-remote                         systemd-private-18d3f426ac60466095bf08e28614578f-systemd-logind.service-R42Ifi     tmp.TLTiecjcIl
http-remote                           systemd-private-18d3f426ac60466095bf08e28614578f-systemd-resolved.service-2DHEyi
os-release                            systemd-private-18d3f426ac60466095bf08e28614578f-systemd-timesyncd.service-S21i9h

For more information about options, you can use thecp --help command.

mv command

mv [option(s)] <source path> <destination path>

mv(move) command is similar to the cp command, the difference between these two commands is the mv command is used to do cut-paste(move) or to rename the files or directories from your system.

For example:  to move(cut-paste) one directory into another directory

mv <source_dir_name> <destination_dir_name>
mv /tmp/os-release /tmp/os-info
ls /tmp/
root@master:~# mv /tmp/os-release /tmp/os-info
root@master:~# ls /tmp/
81678758-56d1-4a41-afdb-7e80089a65b8  systemd-private-a5aeebe8b1ef473e80fe727f834d8a29-systemd-logind.service-UQRQjg
github-remote                         systemd-private-a5aeebe8b1ef473e80fe727f834d8a29-systemd-resolved.service-K9FpXe
http-remote                           systemd-private-a5aeebe8b1ef473e80fe727f834d8a29-systemd-timesyncd.service-Fu3fFh
os-info                               theia_upload

To rename any folder or file we can use the mv command

mv <old_file/dir_name> <new_file/dir_name>
mv ~/temp ~/temp_data
ls ~/temp_data
root@master:~# mv ~/temp ~/temp_data
root@master:~# ls ~/temp_data
81678758-56d1-4a41-afdb-7e80089a65b8  systemd-private-a5aeebe8b1ef473e80fe727f834d8a29-systemd-logind.service-UQRQjg
github-remote                         systemd-private-a5aeebe8b1ef473e80fe727f834d8a29-systemd-resolved.service-K9FpXe
http-remote                           systemd-private-a5aeebe8b1ef473e80fe727f834d8a29-systemd-timesyncd.service-Fu3fFh
os-release                            theia_upload
root@master:~# ls
temp_data

For more information about options, you can use themv --help command.

cat command

cat [option(s)] <filename>

When you want the content of the file on the terminal, or if you want to write file content, or combine the output of files into another file we can use the cat(concatenatecommand.

For example to display file content

cat /etc/os-release

 In the below example, by using the “cat” command we are going to merge 2 files(filename1 and filename2) and store the output in 3rd file(filename).

cat filename1 filename2 > filename3
cat test1.txt test2.txt > test3.txt
cat test3.txt
root@master:~# cat test1.txt test2.txt > test3.txt
root@master:~# cat test3.txt
In the Soviet Union in 1973, there is perhaps no greater honor for a young girl than to be chosen to be part of the famed USSR gymnastics program. So when eight-year-old Anya is tapped, her family is thrilled. As Anya moves up the ranks of competitive gymnastics, and as other girls move down, Anya soon comes to realize that there is very little margin of error for anyone. Winterland tells the story of a previous era, shockingly pertinent today, shaped by glory and loss and finding light where none exists.

This is test2

the cat command can be used to create a new file and insert data into that file with the help of the > greater than sign. The file can be saved with the help of the ctrl+d keys.  By using > the content of the existing file will be overwritten.

cat > test4.txt
hello this is file number 4
root@master:/etc# cat > test4.txt
hello this is file number 4
root@master:/etc# cat test4.txt 
hello this is file number 4

The cat<< EOF > file_name command can be used to create a new file, and also displays an end marker at the end of the file which saves the content till the given end marker. The file can be saved with the help of the ctrl+d or EOF word at end of the file.

cat << EOF > test5.txt
This is ubuntu
To see user info see /etc/passwd
EOF
root@master:/etc/opt# cat << EOF > test5.txt
> This is ubuntu
> To see user info see /etc/passwd
> EOF
root@master:/etc/opt# cat test5.txt 
This is ubuntu
To see user info see /etc/passwd

For more information about options, you can use the cat --helpcommand.

touch command

touch [option(s)]<file name>

To create a new empty file touch command is used.

touch file1.txt
ls
touch file1.txt
root@master:~# ls
file1.txt  temp_data  test1.txt  test2.txt  test3.txt  test4.txt  test5.txt

To modify the timestamp of the file touch command is used with the -m option.

For more information about options, you can use the touch --help command.

mkdir command

mkdir [option(s)]<directory name>

To create a new directory(s) mkdir(make directory) command is used. The user must have the privilege to create a new directory.

for example to create a new directory.

mkdir linux
ls -l
mkdir linux
root@master:~# ls -l
total 28
-rw-r--r--  1 root root    0 Mar 29 07:17 file1.txt
drwxr-xr-x  2 root root 4096 Mar 29 07:17 linux
drwxr-xr-t 14 root root 4096 Mar 29 07:03 temp_data
-rw-r--r--  1 root root  512 Mar 29 07:06 test1.txt
-rw-r--r--  1 root root   14 Mar 29 07:07 test2.txt
-rw-r--r--  1 root root  526 Mar 29 07:09 test3.txt
-rw-r--r--  1 root root   29 Mar 29 07:11 test4.txt
-rw-r--r--  1 root root   10 Mar 29 07:15 test5.txt

-p or --parents command is used to create subdirectories.

mkdir -p ~/app/frontend
ls -l ~/app
root@master:~# mkdir -p ~/app/frontend
root@master:~# ls -l ~/app
total 4
drwxr-xr-x 2 root root 4096 Mar 29 07:18 frontend

Also to create a directory with full permissions(read, write, execute) you can use the -m (mode) option.

mkdir -m 777 <directory name>
mkdir -m 777 fullpermission
ls -l

For more information about options, you can use the mkdir --help command.

rm command

rm [option(s)] <file/directory name>

The rm(remove) command is used to delete files or directories.

rm /tmp/os-info
ls -l /tmp/

you can use the -r (recursive) option to delete an empty directory.

rm -r <directory name>

To delete a directory with content inside of it, you can use (force-f and (recursive) -r options.

rm -rf <directory name>
rm -rf ~/temp_data

For more information about options, you can use the rm --help command.

pwd command

pwd <options>

To get the absolute path of the current working directory on the terminal the pwd(present working directory) is used.

pwd
root@master:~# pwd
/root

For more information about options, you can use the pwd --help command.

find command

find [option(s)] [path] <expression>

To search files in the directory find command is used. The find command takes the regex expression With the -name option.

find -name <expression>
find /etc -name opt
root@master:~# find /etc -name opt
/etc/opt

For more information about options, you can use the find --help command.

apt or apt-get command

apt install <package name>

To install, update, and remove any software(pkg) from the system the apt command is used. It is a package management tool that helps to manage software(pkg) and its dependencies as well.

apt update && apt install mysql-server -y
root@master:~# apt update && apt install mysql-server -y
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Get:2 https://deb.nodesource.com/node_12.x focal InRelease [4583 B]                                                    
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]                                                
Get:4 https://dl.yarnpkg.com/debian rc InRelease [17.1 kB]                                                
Err:4 https://dl.yarnpkg.com/debian rc InRelease                                                                     
  The following signatures were invalid: EXPKEYSIG 23E7166788B63E1E Yarn Packaging <yarn@dan.cx>
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]      
Get:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]                 
Get:7 https://deb.nodesource.com/node_12.x focal/main amd64 Packages [774 B] 

Some of the most commonly used options are updateupgrade, etc.

Update– it synchronizes package files from their source files.

Upgrade– it installs the latest dependencies of installed packages.For example-

For more information about options, you can use the apt --help command.

grep command

grep [option(S)] <search string> <file name>

To search specific string from a file grep(global regular expression print) command is used. This is one of the most common command. It prints all lines that match the regular expression.

cat /etc/os-release | grep VERSION
root@master:~# cat /etc/os-release | grep VERSION
VERSION="20.04.3 LTS (Focal Fossa)"
VERSION_ID="20.04"
VERSION_CODENAME=focal

For more information about options, you can use the grep --help command.

less command

less [option(s)] <file_name>

less command helps you to read large files page-wise. less command helps you to inspect files backward and forward manner. The less command doesn’t load the entire file, it loads in parts which makes it easy to read the large file. To come out from this terminal press q

less /boot/grub/grub.cfg

or
you can also use this 

cat /boot/grub/grub.cfg | less
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env

For more information about options, you can use the less --help command.

head command

head [option(s)] <file_name>

The head command is used to display the first line’s content from a file. by default, it shows the first 10 lines of the file. It prints N number of data of given input. It also considers blank lines not only text lines.

For example to see the first 10 lines from the file.

cat -n /boot/grub/grub.cfg | head
root@master:~# cat -n /boot/grub/grub.cfg | head
     1  #
     2  # DO NOT EDIT THIS FILE
     3  #
     4  # It is automatically generated by grub-mkconfig using templates
     5  # from /etc/grub.d and settings from /etc/default/grub
     6  #
     7
     8  ### BEGIN /etc/grub.d/00_header ###
     9  if [ -s $prefix/grubenv ]; then
    10    set have_grubenv=true

For more information about options, you can use the head --help command.

tail command

tail [option(s)] <file_name>

The tail command is opposite to the head command it is used to display the last line’s content from a file. by default, it shows the last 10 lines of the file. It prints N number of data of given input. It also considers blank lines not only text lines. The tail command is useful for reading the error message.

For example to see the first 10 lines from the file.

cat -n /boot/grub/grub.cfg | tail
root@master:~#cat -n /boot/grub/grub.cfg | tail
 295	# the 'exec tail' line above.
   296	### END /etc/grub.d/40_custom ###
   297	
   298	### BEGIN /etc/grub.d/41_custom ###
   299	if [ -f  ${config_directory}/custom.cfg ]; then
   300	  source ${config_directory}/custom.cfg
   301	elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
   302	  source $prefix/custom.cfg;
   303	fi
   304	### END /etc/grub.d/41_custom ###

For more information about options, you can use the tail --help command.

echo command

echo [option(s)]<string>

The echo command is used to display text/string which is passed as an argument on the terminal. This command is mostly used in shell script and batch files to give output on screen or to insert data into a file.

echo "This is ubuntu"
root@master:/etc# echo "This is ubuntu" 
This is ubuntu

echo * command will print all present files/directories, it’s similar to the ls command.

echo *
root@master:~# echo *
app file1.txt fullpermission linux test1.txt test2.txt test3.txt test4.txt test5.txt

NOTE: – echo /etc/* command is similar to cd /etc && echo *

Also, to create a new file and redirect the echo command output to the file by using > OR >> rather than printing it on the screen. When you use the > operator, the file will be overwritten. If the file does not exist, it will be created by using the > OR >> operator

echo "This is file1" > file1.txt
cat file1.txt

when you use the >> operator, the data get appended to the file.

echo "file1 is modified" >> file1.txt
cat file1.txt

For more information about options, you can use the echo --help command.

ps command

ps [options(s)]<optional paramter>

To list out the currently running process in the shell ps command is used. It gives a snapshot and useful information on the running process. It gives information like PID(process ID), TTY(type of the terminal), TIME(running time), CMD(executed command), etc.

ps

There are multiple options for example if you want to see all running processes.

ps -A
root@master:~# ps -A
    PID TTY          TIME CMD
      1 ?        00:00:01 systemd
      2 ?        00:00:00 kthreadd
      3 ?        00:00:00 rcu_gp
      4 ?        00:00:00 rcu_par_gp
      6 ?        00:00:00 kworker/0:0H-kblockd
      8 ?        00:00:00 mm_percpu_wq
      9 ?        00:00:00 ksoftirqd/0
     10 ?        00:00:00 rcu_sched
     11 ?        00:00:00 migration/0
     12 ?        00:00:00 cpuhp/0

If you want to display all process(a) with user name(u), which are executing(x), you can use the ps command.

ps aux
root@master:/etc# ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.5 101428 10744 ?        Ss   18:21   0:01 /sbin/init
root           2  0.0  0.0      0     0 ?        S    18:21   0:00 [kthreadd]
root           3  0.0  0.0      0     0 ?        I<   18:21   0:00 [rcu_gp]
root           4  0.0  0.0      0     0 ?        I<   18:21   0:00 [rcu_par_gp]
root           6  0.0  0.0      0     0 ?        I<   18:21   0:00 [kworker/0:0H-kblockd]
root           8  0.0  0.0      0     0 ?        I<   18:21   0:00 [mm_percpu_wq]
root           9  0.0  0.0      0     0 ?        S    18:21   0:00 [ksoftirqd/0]

For more information about options, you can use the ps --help command.

top command

top <option(s)>

The top (table of processes) command is used to monitor the CPU performance. The top command is similar to the ps command, but the difference between these two commands is, the top command displays real-time data. the top command gives detailed information. The first top section of the top command displays statistics of the overall running process and usage of the system, and the second part contains a list of currently running processes.

top
top - 19:26:44 up 1 min,  0 users,  load average: 0.07, 0.05, 0.01
Tasks:  84 total,   1 running,  83 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.8 us,  0.2 sy,  0.0 ni, 99.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   1949.3 total,   1526.6 free,    128.1 used,    294.5 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   1796.3 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                             
    434 root      20   0  903296  64264  33164 S   2.0   3.2   0:02.33 node                                                
    496 root      20   0 1151992  38044  29488 S   1.0   1.9   0:00.54 node                                                
    433 root      20   0  572224  41024  30192 S   0.3   2.1   0:00.37 node                                                
    545 root      20   0    7852   3600   3112 R   0.3   0.2   0:00.04 top                                                 
      1 root      20   0  101416  10888   8344 S   0.0   0.5   0:01.04 systemd                                             
      2 root      20   0       0      0      0 S   0.0   0.0   0:00.00 kthreadd                                            
      3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp                                              
      4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par_gp            

Top command provides information such as 

  • PID– process ID which is unique for each process
  • USER– user name of (owner) process
  • PR– Process Priority, As lower the number higher in priority(-20 have higher priority-20   have less priority)
  • NI– The nice value of task (-ve value have higher priority than +ve value).
  • VIRT– The Total virtual memory used by the process.
  • RES– Physical RAM used by the process in kilobytes(kb)
  • SHR– Shared memory size used by the process in kilobytes (kb)
  • S–  Process status, It can be anything between {
  • D– uninterruptible sleep state 
  • I – idle state
  • R – running state
  • S – sleeping state
  • T – stopped by a job control signal state
  • t – stopped by debugger during trace state
  • Z – zombie(process are stopped but still exist in the process table) }
  • %CPU – CPU usage by a process in percentage.
  • %MEM – memory usage of a process in percentage.
  • TIME+ – CPU time (time from the start of the process )
  • COMMAND – A command which is used to start the process.

For more information about options, you can use the top --help command.

sudo command

sudo <command>

To assign super user privilege or root user privilege sudo(superuser do) command is used. You have just to add the sudo command before the others’ command. The sudo command is commonly used to install software or edit files, which normal user cant edit.

For example to download package information from all configured sources 

sudo apt update
root@master:/etc# sudo apt update
Hit:1 https://deb.nodesource.com/node_12.x focal InRelease
Get:2 https://dl.yarnpkg.com/debian rc InRelease [17.1 kB]                                                                 
Err:2 https://dl.yarnpkg.com/debian rc InRelease                                                                           
  The following signatures were invalid: EXPKEYSIG 23E7166788B63E1E Yarn Packaging <yarn@dan.cx>
Hit:3 http://archive.ubuntu.com/ubuntu focal InRelease                                                   
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease          

For more information about options, you can use the sudo --help command.

useradd command

useradd or adduser [option(s)] <username>

To create a new user in the linux system useradd or adduser the command is used. These two commands are the same. you can see the new user name in the /etc/passwd file. Only those users who have root privilege or sudo can add a new user. adduser also requires a new password for that new user.

useradd ubuntu007
root@master:~# useradd ubuntu007
root@master:~# cat /etc/passwd | grep ubuntu007
ubuntu007:x:1001:1001::/home/ubuntu007:/bin/sh

For more information about options, you can use the passwd --help command.

passwd command

passwd <user name>

To set a new password for the user passwd(password) command is used. you can see the new password for that specific user in the /etc/shadow file in an encrypted format. Superusers have the privilege to change passwords for other users as well.

passwd ubuntu007
root@master:~# passwd  ubuntu007
New password: 
Retype new password: 
passwd: password updated successfully

For more information about options, you can use the passwd --help command.

userdel command

userdel [options] LOGIN

To delete a user account and related files to that user userdel command is used. It deletes entries from the user’s list (/etc/passwd) as well. Superusers have the privilege to delete other users as well.

for example, by using -f used to forcefully remove the user account even if the user is still logged in. It also deletes the user’s home directory and mail spool (/var/spool/mail or /cron).

userdel -f <username>
userdel -f ubuntu007
root@master:~# userdel ubuntu007
root@master:~# cat /etc/passwd | grep ubuntu007

For more information about options, you can use the userdel --help command.

history command

history [option(s)]

To see previously executed commands by the user on the terminal history command is used. This command list up to 500 commands.

history
root@master:~# history
    1  top
    2  apt update
    3  clear
    4  sudo apt update
    5  clear
    6  cd /etc/
    7  sudo apt update
    8  useradd ubuntu007
    9  cat /etc/passwd | grep ubuntu007
   10  passwd ubuntu007
   11* userdel
   12  /var/spool/clea
   13  clear
   14  userdel -f ubuntu007

For more information about options, you can use the history --help command.

Conclusion

If you want to learn and use Linux effectively, you must know the basic commands. The more you practice and use Linux commands, the better you will do productive work. In this hands-on lab, you learned the most used basic commands to take control of your system’s privileges. 

There are lots of more helpful commands. If we have left something out, please let us know and share your favorite Basic Linux commands in the comment section.

In the next hands-on lab, you will learn about Advanced Linux commands to perform Administrator tasks. Have Great learning!

Join Our Newsletter

Share this article:

Table of Contents