Linux Commands Interview questions

1.What is Linux and Why use it ?

Linux is an open-source operating system whose source code is available for modification and commercial and non-commercial distribution under the guidelines of the GNU General Public License.

Linux has a number of advantages over the Windows operating system and is used widely because of these advantages Below are a few listed:

  • The major advantage of the Linux Operating System is that it is a freely available open-source OS.
  • Privacy and Security are very important for the users, especially nowadays, when hacking and other cyber malpractices have become so common. Linux maintains the privacy of the user and is a lot more secure than Windows OS.
  • Linux Operating System is highly stable and does not hang or requires to be restarted again and again.
  • Linux is fast and easy to install and can be installed very easily from the internet.
  • Linux is network friendly.

2.File and Directory CRUD Navigation Commands

ls(list all directories)
# list all the files and directories inside the current directory in which you are.

ls -R
# List all the files and directories inside the current directory as well as all the files and directories of the sub-directories as well.

ls -a 
# List all the files and directories in the current directory and also lists the hidden files.

ls -al
# Lists files and directories of the current directory along with the details like permissions(read,write,execute),owner,file/dir size,etc.

cd 
# This command is used to move to the root directory

cd ~
# move to the root/home directory.

cd dirName
# Move to a particular directory from the current directory.

mkdir
# This command creates a directory

cat > fileName
# This command creates a file in the current directory.

cat fileName
# This command displays the content in a file.

cat f1 f2 > f3
# This command joins the content of two files and store it in the third file.

rmdir dirName
# This command is the remove directory command. It deletes a directory

mv fileName "new file path"
# This command is the move file command. It moves the file to the new path specified.

mv fileName newName
# This command changes the name of the file from the old name.

find <starting position to search> <expression determining what to find> <options> <what to find>
# This command is used for walking a file hierarchy. It is used to find #files/directories and perform operations on them.

grep <options> pattern fileName
# The full form of this command is a global search for regular expression and  
# printout. This command searches a file for a particular pattern of characters and
# displays all the lines that contain that pattern. The pattern being searched is   
# called a regular expression (regex). There are a lot of <options> available.

2. System Information Commands

$ history
$ # This command displays the list of all the typed commands in the current terminal session.
$ clear
$ # Clear the terminal screen
$ hostname
$ # shows the name of the system host.

$ hostid
$ # Displays the id of the host of the system.

$ sudo
$ # Allows  a regular user to run the programs with the security privileges of a superuser or root

$ apt-get  # This command is used to install and add new packages.

$ date  # This command is used to show the current date and time.

$ cal  # Show the calendar of the current month.

$ whoami  # This command displays the name with which you are logged in.

$ whereis [options] fileName # This command is used to find the location of source/binary file of a command and manuals sections for a specified file in Linux System.

3. File Permission Commands

There are 3 types of people who can use a file and each type has 3 types of access to the file.

The diagram shows that there are 3 types of people accessing a file and they are:

  1. User (u)
  2. Group (g)
  3. Others (o)

Also, the access that we want to give to each of them is of three types:

  1. Read (r)
  2. Write (w)
  3. Execute (x)
  • Numerical Method for granting file permissions

There are numeric codes for each permission. They are as follows:

  1. r (read) = 4
  2. w (write) = 2
  3. x (execute) = 1
  4. No permissions  = 0

4.Hardware Information Commands.

$ cpu-info # This command is used to display the information about your CPU
$ free -h   # This command is used to display the free and used memory. -h is used for converting the information(to be displayed) to human-readable form.
$ lsusb -tv # List all the USB connected devices.
$
$ du # This command stands for disk usage and is used to estimate the space usage for a file or directory.
$

5.File and Directory Compression Commands

gzip fileName

# This command is used to compress a file with gzip compression.

gunzip fileName.gz

# This command is used to unzip a file that has gzip compression.

tar cf myDir.tar myDir

# This command is used to create an uncompressed tar archive.

tar cfz myDir.tar myDir

# This command is used to create a tar archive with gzip compression

tar xf file

# This command is used to extract the contents of any type of tar archive.

6. Enviroment Variable Commands

env 
# This command displays all the environment variables.

echo $variable

# This command displays the environment variable.

unset

# This command removes a variable.

7.User Management Commands

sudo adduser username
# This command is used to add a user

sudo passwd -l 'username'
# This command is used to change the password of a user.

sudo userdel -r 'username'
# This command is used to remove a newly created user.

sudo usermod -a -G GROUPNAME USERNAME
# This command is used to add a user to a particular group.

Sudo deluser USER GROUPNAME
# This command is used to remove a user from a group.

finger
# This command shows the information of all the users logged in.

finger username

# This command gives information about a particular user.

8. Networking Commands

dir 

# This command is used to display files in the current directory of a remote computer.

put file

# This command is used to upload 'file' from local to the remote computer.

get file

# This file is used to download 'file' from remote to the local computer.

quit

# This command is used to log out.

9. Process Commands

bg

# This command is used to send a process to the background.

fg

# This command is used to run a stopped process in the background

top 
# This command is used to get the details of all active processes.

ps 
# This command is used to give the status of running for a user.

ps PID 
# This command gives the status of a particular process.

pidof 

# This command is used to give the process ID of a particular process.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值