• 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

    1. ls(list all directories)
    2. # list all the files and directories inside the current directory in which you are.
    3. ls -R
    4. # List all the files and directories inside the current directory as well as all the files and directories of the sub-directories as well.
    5. ls -a
    6. # List all the files and directories in the current directory and also lists the hidden files.
    7. ls -al
    8. # Lists files and directories of the current directory along with the details like permissions(read,write,execute),owner,file/dir size,etc.
    9. cd
    10. # This command is used to move to the root directory
    11. cd ~
    12. # move to the root/home directory.
    13. cd dirName
    14. # Move to a particular directory from the current directory.
    15. mkdir
    16. # This command creates a directory
    17. cat > fileName
    18. # This command creates a file in the current directory.
    19. cat fileName
    20. # This command displays the content in a file.
    21. cat f1 f2 > f3
    22. # This command joins the content of two files and store it in the third file.
    23. rmdir dirName
    24. # This command is the remove directory command. It deletes a directory
    25. mv fileName "new file path"
    26. # This command is the move file command. It moves the file to the new path specified.
    27. mv fileName newName
    28. # This command changes the name of the file from the old name.
    29. find
    30. # This command is used for walking a file hierarchy. It is used to find #files/directories and perform operations on them.
    31. grep pattern fileName
    32. # The full form of this command is a global search for regular expression and
    33. # printout. This command searches a file for a particular pattern of characters and
    34. # displays all the lines that contain that pattern. The pattern being searched is
    35. # called a regular expression (regex). There are a lot of available.

    2. System Information Commands

    1. $ history
    2. $ # This command displays the list of all the typed commands in the current terminal session.
    3. $ clear
    4. $ # Clear the terminal screen
    5. $ hostname
    6. $ # shows the name of the system host.
    7. $ hostid
    8. $ # Displays the id of the host of the system.
    9. $ sudo
    10. $ # Allows a regular user to run the programs with the security privileges of a superuser or root
    11. $ apt-get # This command is used to install and add new packages.
    12. $ date # This command is used to show the current date and time.
    13. $ cal # Show the calendar of the current month.
    14. $ whoami # This command displays the name with which you are logged in.
    15. $ 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.

    1. $ cpu-info # This command is used to display the information about your CPU
    2. $ 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.
    3. $ lsusb -tv # List all the USB connected devices.
    4. $
    5. $ du # This command stands for disk usage and is used to estimate the space usage for a file or directory.
    6. $

    5.File and Directory Compression Commands

    1. gzip fileName
    2. # This command is used to compress a file with gzip compression.
    3. gunzip fileName.gz
    4. # This command is used to unzip a file that has gzip compression.
    5. tar cf myDir.tar myDir
    6. # This command is used to create an uncompressed tar archive.
    7. tar cfz myDir.tar myDir
    8. # This command is used to create a tar archive with gzip compression
    9. tar xf file
    10. # This command is used to extract the contents of any type of tar archive.

    6. Enviroment Variable Commands

    1. env
    2. # This command displays all the environment variables.
    3. echo $variable
    4. # This command displays the environment variable.
    5. unset
    6. # This command removes a variable.

    7.User Management Commands

    1. sudo adduser username
    2. # This command is used to add a user
    3. sudo passwd -l 'username'
    4. # This command is used to change the password of a user.
    5. sudo userdel -r 'username'
    6. # This command is used to remove a newly created user.
    7. sudo usermod -a -G GROUPNAME USERNAME
    8. # This command is used to add a user to a particular group.
    9. Sudo deluser USER GROUPNAME
    10. # This command is used to remove a user from a group.
    11. finger
    12. # This command shows the information of all the users logged in.
    13. finger username
    14. # This command gives information about a particular user.

    8. Networking Commands

    1. dir
    2. # This command is used to display files in the current directory of a remote computer.
    3. put file
    4. # This command is used to upload 'file' from local to the remote computer.
    5. get file
    6. # This file is used to download 'file' from remote to the local computer.
    7. quit
    8. # This command is used to log out.

    9. Process Commands

    1. bg
    2. # This command is used to send a process to the background.
    3. fg
    4. # This command is used to run a stopped process in the background
    5. top
    6. # This command is used to get the details of all active processes.
    7. ps
    8. # This command is used to give the status of running for a user.
    9. ps PID
    10. # This command gives the status of a particular process.
    11. pidof
    12. # This command is used to give the process ID of a particular process.
  • 相关阅读:
    C/C++计算表达式值 2020年12月电子学会青少年软件编程(C/C++)等级考试一级真题答案解析
    【干货】STM32通过ADC模拟看门狗实现掉电保存
    leetcode211. 添加与搜索单词 - 数据结构设计
    大模型应用开发:运行你的第一个聊天程序
    【动画笔记】数据结构-AVL树的插入操作
    在方法上打断点?劝你不要乱来
    [附源码]计算机毕业设计JAVA校园兼职招聘系统
    SpringMVC-REST风格简介及RESTful入门案例
    非常经典的电压掉电监测电路,你学废了吗?
    SOLIDWORKS Premium 2022 SP5.0 三维设计绘图软件
  • 原文地址:https://blog.csdn.net/u011868279/article/details/126110445