In This Tutorial, we will Learn About Linux Interview Questions which are always used in Linux, Ubuntu, CentOS, Debian, and other Linux Distro. Linux/Ubuntu/UNIX/CentOS, Fedora, Debian, etc. These commands are required to work in the Terminal of Linux. these commands are used a daily basis for every system administrator and Linux user.
Cal : Display System Calendar
With the help of this command, you can see the current, past and future calendar in Linux.
Syntax: cal [option] [year]
[root@simitech ~]# cal -y
OR
[root@simitech ~]cal 2020
Options | Descriptions |
---|---|
cal | to see the current month calendar |
cal month year | Display a specific month Calendar |
Check and Modify System Date
To check system date and time in Linux terminal, use below command
timedatectl
System timezone
To check the system’s time zone in linux terminal, use the command below
change system time zone
We checked the time zone of the system with the help of the command given earlier, if your system is showing wrong time Zone, then use the method given below to Correct it.
timedatectl set-timezone Asia/dubai
List of time zones
If you want to check all the time zones available in the system with the help of command then see below screenshot and run the command in the Terminal
timedatectl list-timezone
touch : Create Empty File
touch: when you want to create more than one empty file use the touch command.
[root@simitech ~]# touch data
If you want to create many empty files at once, like we have created a file named data1, data2 and data3 below, you can create even more files at once.
[root@simitech ~]# touch data1 data2 data3
if you want to create more than 100 empty files only in one command you can use touch the command
touch data_{1..100}
nano : create and modify file
Like the touch command, you can also create and modify a file with the Nano command this is the most popular command in Linux and other Linux distro. to save and exit from the Current file use the ctrl +x from the keyboard.
[root@simitech ~]# nano data
cat :create and modify file
cat: the cat command is the Most Important text editor In Linux It is used to create, modify the existing files. to save and exit from the file press ctrl +c from the keyboard.
[root@simitech ~] cat > data
you want to display the matter of file please execute below command
[root@simitech ~]# cat data
If a file is already created and you want to add some more content in file with the help of cat command, then use the command given below
[root@simitech ~] cat >> data
vim: Linux most power full text Editor
vim is the most important command in Linux/Ubuntu/Centos etc. with the help of this command you can create, modify the file, vim is an improved version of vi. Click here for a complete tutorial on vim.
[root@simitech ~]# vim data
Create Directory
The mkdir command is used to create a directory in Linux.
[root@simitech ~]# mkdir data
Remove or delete file and Directory
Remove or delete file and Directory from the system use bellow command
rm -rf DirectoryName { Delete Directory without confirmation }.
rm -f Linuxdata { delete file without confirmation}.
cd (Change Directory)
Change the Current Directory. if you type the cd command without any option, this command changes to the current user’s home DIrectory. To enter or exit any directory, use this command.
[root@simitech ~]# cd LinuxData
Options | Descriptions |
---|---|
cd | enter and exit from the Directory |
cd /var/www/html | switch to the specific Directory by path name |
cd .. | switch to parent Directory |
Copy File And Directory
cp: [option] [source] [destination]
The cp command is used to send files and directories from one location to another. In the below step, we will show you some commands related to cp with examples.
copy file from one location to another
Copy Directory from one location to another location .
The bellow command use to copy Directory from Source To Destination.
it’s use to copy file and Directory from source to Destination with Rename
mv: move File And Directory
If you want to cut and paste the files and directories of one place in another place, then you use this command.
mv [option] [source] [destination]
Move one file from one location to another
[root@simitech ~]# mv data /var/www/html/NewData
Move one Directory from one location to another
[root@simitech ~]# mv LinuxData /var/www/html
Getting Help in Linux
man
man is a system manual pager. it provide a quick way to get information most of the utility installed on the system.
[root@simitech ~]# man date [root@simitech ~]# man mkdir
info
Similar to man command but it is more depth.run info without page urges to list all pages. info page provides information like website.
[root@simitech ~]# info cal
whatis
display short Description of command
[root@simitech ~]# whatis df [root@simitech ~]# whatis ls
The Help option:
Displays brief summaries of built-in commands. If PATTERN is specified, give detailed help on all commands matching PATTERN, otherwise, the list of help topics is printed.
[root@simitech ~]# help cal [root@simitech ~]# help time
logout Command
Exits From the current session and display login screen. this command use only in text mode session. do not use it when GUI is running.
[root@simitech ~] logout
shutdown
the shutdown is the most Important Commands In Linux. This command is used to shut down the system. You can do this command only in text mode. You must have root privileges to run this command.
[root@simtech ~]# shutdown
options | Description |
---|---|
shutdown -r now | restart the system without delay |
shutdown -s now | immediately shutdown the system |
shutdown -h +2 | halts the system in two minutes |
startx
This shell scripts,typically supplied with X11 distributions, enable you to start an X Session from the Current User Account.
[root@simitech ~]# startx
Su,sudo (Switch User)
Create a new shell session with a different User’s id and Privileges. if you run su command without specifying a username, you create a shell for the superuser ( root) . that is a user who has gained the root user’s privileges
[root@simitech ~]$ su
The su command is used to switch (login) from one user to another in Linux.
[root@ simtech ~]# su siya
tty (teletypewrite)
The use of this command gives information about which terminal it is logged from.tty stand for teletypewriter. But it is popular with the user in the name of the terminal.
[root@simitech ~]# tty /dev/pts/0
chfn (Change Finger)
chfn stands for change finger, This command is used to add and modify the user’s finger information. such as his address, phone number, etc. This information is stored in the file /etc/passwd.including full name, office phone number, address
chfn siya
hwclock
Display Or set the system ‘s hardware clock . hardware clock are different from system clock , a time keeping routine that is the part of the Linux Kernel although the two are synchronized when you start the system
Syntax hwclock –set –date=’MM/DD/YYYY hh:mm:ss’
[root#simitech ~]# hwclock --set --date='10/10/2020 11:40:10
id command
If you want to get some information related to the user from whom you are logged in like what is his user id and group id then you can use this command.
[root#simitech ~]#id
uname
print certain system information including system architecture, kernel release, kernel version, print processor, os Information, etc.
[root@simitech ~]# uname -a
Some commands related to uname and related examples are given in the table below.
option | Description |
---|---|
uname -n, –nodename | print the network node hostname |
-r, –kernel-release | print the kernel release |
-v, –kernel-version | print the kernel version |
uname –p, –processor | print the processor type |
uname –help | list all options |
-o, –operating-system | print the operating system |
uname -m | print the machine hardware name |
uptime
Display the current time, amount of time the system has been running in the current login session, the number of users logged in the system, and average CPU Load.
[root@simitech ~]# uptime
Display brief list of the current user login to the system
w or who command
With the help of this command, how many users are logged in the system and including which terminal are they using, when they logged on, information about CPU Usage.
[root@simitech ~]# w
whoami
With the help of this command, display the username of the user currently login in the system.
[root@simitech ~]# whoami root
pwd
PWD stands for print working Directory, With the help of this command, we can find out which directory is currently in it.
[root@simitech ~]#pwd root
history
the shell keeps track of the command you have entered, it shows a history list in which each command is given a unique number. delete history from the system use history -c.
[root@simtech ~]# history
bc command
With the help of this command you can use your system calculator
bc
jobs
With the help of this command, you can find out how many jobs are running in the system and suspended jobs.
[root@simitech ~]# jobs
ps command
With this command, we can find out how many processes are running in the system. more details about ps use man helping command.
[root@simitech ~]# ps -T
kill command
Terminate the process specified ID. to kill the process, you must be the owner or have a superuser privileges
[root@simitech ~]# kill 2445
top command
Display all running Process in the system, count number of running task , cpu usage,Users login Details, and PID etc.
[root@simitech ~]#top
adduser
user creation is a most important command in Linux, With this command, a user can be created in the system, All information of the user is stored in the /etc/passwd file. At the same time of creating a user, his home directory is also created /home/ location.
[root@simitech ~]# adduser siya [root@simitech ~]# passwd siya
add group and set passwd
With this command, a group can be created in the system, All information of the group is stored in the /etc/group file. bellow command we are creating a sales group
[root@simitech ~]#groupadd sales
set password to the group
If you have already created a group in your system and want to give it a password.
[root@simitech ~]#gpasswd sales
To delete a group from the system use bellow command.
[root@simitech ~]# groupdel sales
delete user
this command delete user from the system but don’t delete his home directory
[root@simitech ~]# userdel siya
Remove user as well as his home Directory
[root@simitech ~]# userdel -R siya
Add user in Group
syntax usermod -G [groupname] [username]
You can add a common user to the Specify group
[root@simitech ~] usermod -G sales siya
Lock system User
usermod -L [username]
Do not want to allow the user to login to the system or want to lock that user
[root@simitech ~]#usermod -L siya
Unlock or enable system user
usermod -U [username]
If you want to unlock the user already locked in the system, then use the command given below
[root@simitech ~]# usermod -U siya
chage : set password expiry date
The command name ‘chage’ stands for ‘change age’ This command can be used to change the user’s password aging/expiry information.
syntax: chage -l [username]
chage -l siya
You can change information of particular user
root (administrator) can set password expiry date for a specific user
syntax: chage -d [year]-[month]-[date] username
[root@simitech ~]# chage -d 2020-10-05 siya
wc (word count)
With the help of this command, you can count the word, character, line number, and byte of any file.
syntax: wc [option] [filename]
[root@simitech ~]# wc -l data1 356 data
Option | Descriptions |
---|---|
wc -l | count only line |
wc -c | for only byte count |
wc -w | only word count |
wc -m | for only charector count |
ls command
List the content of the current Directory and file OR Specific Directory and file.
ls [option] [file or Directory]
[root@simitech ~]# ls -la
option | Description |
---|---|
ls -R | list subdirectories recursively |
ls -a | list included hidden file |
ls -l | Display Extra Information |
rmdir Delete Directory
Syntax : rmdir [empty Directory Name]
this command use to Delete Empty Directory
[root@simitech ~]# rmdir data
Network tools
ifconfig
With the help of this command, you can see the information of the system Ethernet, such as IP address netmask, broadcast Address, MTU status attached network Card, It is used at boot time to set up interfaces as necessary.
[root@simitech ~]#ifconfig
ip addr show | Display ethernet Configuration |
ifdown [ethernet device name] nmcli connection down [device name] | Ethernet disable |
ifup [ethernet device name] nmcli connection up [device name] | Ethernet enable |
df commad
df shows the all mounted partition.df displays the amount of disk space available on the file system containing each file name argument. If no filename is given, the space available on all currently mounted file systems is shown. Disk space is shown in 1K. df -h show mount partition in Human Readable format,
[root@simitech ~]#df -h
du command
With the help of this command, you can see the report of the disk usage of the system, which files and directories have taken how much disk.
[root@simitech ~]#du -h
lscpu
Display all System Cpu Architacture Related Information.
[root@simitech ~]#lscpu
clear
Using this command, you can clear the content being displayed in the system. or Use the Short Cut key ctrl+l.
[root@simitech ~]# clear # Clear system Screen
last
last, lastb – show a listing of last logged in users.
[root@simitech ~]#last
lsusb
lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.
[root@simitech ~]# lsusb
ps
pstree shows running processes as a tree in the system.
[root@simkitech ~]# pstree
hdparm
hdparm display hard drive related parameter and test performance.
[root@simitech ~]# hdparm
vmstat
vmstat displays information about processes, memory, paging, block IO, traps, disks, and CPU activity.
[root@simitech ~]#vmstat
Also read these articles
Which is the Best Antivirus for Indian Users
10 best inverter ups for home in India 2021
top 10 best speakers brands review in India 2021
In this Tutorials, we learned About Linux Interview Questions. I hope that now you are comfortable in Any open-source operating system. If your problem is still not solved share your Problem via comments.