Linux interview questions and answers, suitable for graduates and novices, suitable for checking vacancies

    Answering linux questions has two major effects. First, it can prove that you can check online problems by looking at Linux logs in addition to coding. Second, it can prove that you have done deployment and release-related work on Linux.

    On the contrary, if you don't even know the basic commands of Linux, the interviewer thinks that you only have the ability to write code on windows, and more importantly, they will question that your project is a learning project.

    In this article, we will combine the two themes of "Troubleshooting Online Problems" and "Deploying Projects on Linux" to comprehensively analyze Linux-related interview questions that are often asked in interviews.

1. How to enter the directory with absolute path and relative path? How do you see which directory you are currently in?

Use the cd command, for example, to enter the absolute path, you can use cd /etc, and to enter the superior path, you can use cd ../

To enter the home directory, you can use cd ~/

You can view the current path through the pwd command

2. How to see the current process? How to perform exit?

You can use the ps command to view the current process, and you can use the exit command to exit. You can use kill + process number to terminate the specified process.

3. How to clear the screen? How to exit the current command? How to check the current user id? What command is used to view the specified help?

Clear the screen command, clear

Exit the current command: ctrl+c exit completely

The command to view the current user id: enter the id command

View specific help: such as man adduser 

4. What function does the ls command perform?

This is the most commonly used command to list files and subdirectories in the current or specified directory

5. Establish soft links (shortcuts) and commands for hard links

Create a soft link: ln -s slink source

Create a hard link: ln link source

6. What command is used to create a directory? What command is used to create a file? What command is used to copy files?

Create a directory command with mkdir

Commands to create files: typically touch, vi can also create files, in fact, as long as output to a non-existent file, the file will be created

Copy file command cp

7. What command is used to modify file permissions?

The file permission modification command is chmod

The following is an example:

chmodu+xfile adds execution permissions to the owner of file chmod 751 file assigns read, write, and execute (7) permissions to the owner of file, assigns read and execute (5) permissions to the group where the file is located, and assigns other users Permission to execute (1)

chmodu=rwx,g=rx,o=xfile Another form of the above example chmod =r file assigns read permissions to all users

8. What commands can be used to view the contents of a file?

The name of the vi file is viewed in edit mode and can be modified

cat file name This is to display all file contents

more file name This is to display the contents of the file in pages

less file name This command is similar to more, and better is that you can page forward

tail file name This is to view only the tail, you can also specify the number of lines

head file name only view the head, you can also specify the number of lines

9. How to output a string with spaces, such as "hello world" to the screen?

Command to output a string with spaces to the screen: echo hello world

10. Which file is under which folder is the terminal? Which command in which folder is the black hole file?

Terminal /dev/tty

Black hole file /dev/null

What is a black hole file? Any write to /dev/null will succeed, but the data will disappear without a trace without any feedback.

11. Which command is used to move files?

You can use the mv command

12. Which command is used to copy files? What if you need to copy together with the folder?

cp cp -r ????

13. Which command is used to delete files? What if you need to delete the directory and the files in the directory together? What command is used to delete an empty folder?

They are: rm and rm -r and rmdir

14. What kinds of wildcards can be used for commands under Linux? What do they mean?

"?" means to replace a single character.

"*" means to replace any number of characters.

The square brackets "[charset]" can replace any single character in the charset set, such as [az], [abABC], which is equivalent to a regular expression

15. What command is used to count the contents of a file? (Line number, number of words, number of bytes)

wc command-c count bytes-l count rows-w count words.

16. What is the use of the Grep command? How to ignore case? How to find the rows that do not contain the string?

Is a powerful text search tool, it can use regular expressions to search for text and print out the matching lines.

grep [stringSTRING] filename grep [^string] filename

17. What are the statuses of processes in Linux? In the information displayed by ps, what symbols are used to represent them?

(1) Uninterruptible state: The process is in a sleep state, but the process is uninterruptible at the moment. Uninterruptible means that the process does not respond to asynchronous signals.

(2) Paused state/tracking state: Send a SIGSTOP signal to the process, and it will enter the TASK_STOPPED state in response to the signal; when the process is being tracked, it is in the special state of TASK_TRACED. "Being tracked" refers to the process being paused and waiting for the process tracking it to operate on it.

(3) Ready state: the state in the run_queue queue

(4) Running status: the status in the run_queue queue

(5) Interruptible sleep state: the process in this state is suspended because it is waiting for the occurrence of a certain event (such as waiting for socket connection, waiting for semaphore)

(6) Zombie state (zombie): If the father does not pass the wait series of system calls, the corpse of the child process (task_struct) will also be released by the way

(7) Exit status

D Uninterruptible (usually IO)

R is running, or a process in the queue

S is dormant

T stopped or tracked

Z zombie process

W enters memory swap (invalid starting from kernel 2.6)

X dead process

18. How to make a command run in the background?

Usually use & at the end of the command to let the program run automatically.

19. How to use ps to display all processes? How to use ps to view the information of a specified process?

ps -ef (system v output)
ps -aux bsd format output
ps -ef | grep pid


20. Which command is specifically used to view background tasks?

jobs

21. What command is used to transfer the background task to the foreground to execute? What command is used to execute the stopped background task in the background?

Transfer background tasks to the foreground to execute fg

Execute stopped background tasks in the background bg

22. What command is used to terminate the process? What parameters?

kill [-s <message name or number>][program] or kill [-l <message number>]

kill-9 pid

23. What command is used to search for files? What is the format?

find <specified directory> <specified condition> <specified action>

whereis add parameters and file name

locate only adds the file name

find searches the disk directly, which is slower.

find / -name "string*"

24. What command is used to check who is currently using the host? What command is used to find the terminal information where you are located?

Find your terminal information: who am i

Check who is currently using the host: who

25. What command is used to view the list of used commands?

history

26. What command can I use to check the disk usage space? What about free space?

df -hl
file system capacity used available used% mount point

Filesystem Size Used Avail Use% Mounted on /dev/hda2 45G 19G 24G
44% /
/dev/hda1 494M 19M 450M 4% /boot


27. What command is used to check whether the network is connected?

netstat

28. What command is used to view the ip address and interface information?


ifconfig

29. What command is used to view various environment variables?

View all env

View one, such as home: env $HOME

30. What command is used to specify the command prompt?

\u: Display the current user account

\h: Display the current host name

\W: Only display the last directory of the current path

\w: Display the current absolute path (the current user directory will be replaced by ~)

$PWD: Display the current full path

$: display the command line'$' or'#' symbol

#: The first few orders issued

\d: represents the date, the format is week day month date, for example: "MonAug1"

\t: The display time is in 24-hour format, such as: HH: MM: SS

\T: Display time in 12-hour format

\A: The display time is in 24-hour format: HH: MM

\v: BASH version information such as export PS1='[\u@\h\w#]$'

31. Where do you find the executable file of the search command? 

whereis [-bfmsu][-B <directory>...][-M <directory>...][-S <directory>...][file...]

Supplementary note: The whereis command will search for eligible files in a specific directory. The strength of these files should belong to the original code, binary files, or help files.

-b Only find binary files.

-B <directory> Only search for binary files in the set directory. -f Do not display the path name before the file name.

-m Only find documentation.

-M <directory> Only find the description file in the set directory. -s only find the original code file.

-S <directory> Only search for original code files in the set directory. -u Find files that do not contain the specified type.

The w -h ich command will search for the location of a system command in the path specified by the PATH variable and return the first search result.

-n specifies the length of the file name. The specified length must be greater than or equal to the longest file name in all files.

The -p parameter is the same as the -n parameter, but the file path is included here. -w specifies the width of the field during output.

-V display version information

32. What command is used to find and execute the command?

which can only check executable files

whereis can only check binary files, documentation, source files, etc.

33. How to alias a command?

 

alias la = 'ls -a'


34. What are the definitions and differences between du and df?

du displays the size of a directory or file

df displays the information of the file system where each <file> is located. The default is to display all file systems. (The file system allocates some of the disk blocks to record some of its own data, such as i-nodes, disk distribution maps, indirect blocks, super blocks, etc. These data are invisible to most user-level programs, usually Called Meta Data.) The du command is a user-level program that does not consider Meta Data, while the df command looks at the disk allocation map of the file system and considers Meta Data.

The df command obtains the real file system data, while the du command only looks at part of the file system.

 

35. How do I know the list of all commands supported by the current system?

Use the command compgen -c to print out a list of all supported commands.


36. How to output all current directory stacks?

Use the Linux command dirs to print out the current directory stack.

[root@localhost ~]# dirs
/usr/share/X11
 

37. There are many running tasks in the current system. Is there any way to remove all running processes without restarting the machine?


Use the linux command'disown -r' to remove all running processes.

38. What is the function of the hash command in the bash shell?
 

The linux command'hash' manages a built-in hash table, which records the complete path of the executed commands. With this command you can print out the commands you have used and the number of executions.

[root@localhost ~]# hash
hits command
2 /bin/ls
2 /bin/su
 

Guess you like

Origin blog.csdn.net/sxeric/article/details/114633300