Linux interview topics*48

Article Directory

1. What symbol is used to represent the absolute path? What is the current directory and upper directory? What is the main directory? What command is used to switch directories?

Answer:
Absolute path: For example, /etc/init.d
current directory and upper directory: ./ …/
Main directory: ~/
Switch directory: cd

2. How to check the current process? How to perform exit? How to check the current path?

Answer:
View the current process: ps
execution exit: exit
View the current path: pwd

3. How to clear the screen? How to exit the current command? How to perform sleep? How to check when

Former user id? What command is used to view the specified help? Answer:
Clear the screen: clear
Exit the current command: ctrl+c Completely exit and
perform sleep: ctrl+z Suspend the current process fg Resume the background View the current user id: "id": View and display the uid and gid of the currently logged-in account and their group and Username
View the specified help: For example, man adduser is very comprehensive and has examples; adduser --help tells you some common parameters; info adduesr;

4. What function does the Ls command perform? What parameters can be taken and what is the difference?

Answer:
The function performed by ls: List the directories in the specified directory, as well as the file parameters and differences: a All files l detailed information, including the size of bytes, read, write, and executable permissions, etc.

5. What commands are available for viewing files

vi file name# edit mode to view, you can modify
cat file name# show all file content
more file name# show file content in pages
less file name# is similar to more, and even better, you can page forward
tail file name# only view 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

6. List a few commonly used Linux commands

List the file list: ls [parameter -a -l]
Create directory and remove directory: mkdir rmdir is
used to display the last few lines of the file: tail, for example: tail -n 1000: display the last 1000 lines of packaging: tar -xvf
packaging And compress: tar -zcvf
search string: grep
shows the current directory: pwd creates an empty file: touch editor: vim vi

7. How do you check the logs?

There are many commands for viewing logs in Linux: tail, cat, tac, head, echo, etc. This article only introduces a few commonly used methods.
1. One of the
most commonly used viewing methods for
tail Command format: tail[Required parameter][Select parameter][File]
-f cyclic reading
-q do not display processing information
-v display detailed processing information
-c<number> displayed Number of bytes
-n<number of lines> Display the number of lines
-q, --quiet, --silent Never output the first part of the file name
-s, --sleep-interval=S and -f are used together, which means that every time Sleep for S seconds at repeated intervals.
For example:

tail -n 10 test.log 查询日志尾部最后10行的日志; 
tail -n +10 test.log 查询10行之后的所有日志;
tail -fn 10 test.log 循环实时查看最后1000行记录(最常用的)

It is usually used with grep search, for example:

tail -fn 1000 test.log | grep '关键字'

If the amount of data to be queried at one time is too large, you can turn the page to view, for example:

tail -n 4700 aa.log |more -1000 可以进行多屏显示(ctrl + f 或者 空格键可以快捷键)

2, head and
tail are opposite

head -n 10 test.log 查询日志文件中的头10行日志;
head -n -10 test.log 查询日志文件除了最后10行的其他所有日志;

For other parameters of head
, please refer to tail 3. cat
cat is continuously displayed on the screen from the first line to the last line to display the entire file at once:

 $ cat filename

Create a file from the keyboard:

$cat > filename

Combine several files into one file:

$cat file1 file2 > file 只能创建新文件,不能编辑已有文件

Append the contents of one log file to another:

$cat -n textfile1 > textfile2

Clear a log file:

$cat : >textfile2

Note:> means create, and >> means append. Don't get confused.
For other parameters of cat, refer to tail
5. The sed
command can search for a specific section of the log file, query according to a range of time, and query according to line number and time range according to line number

sed -n '5,10p' filename 这样你就可以只查看文件的第5行到第10行。

By time period

sed -n '/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p' test.log

6. When the less
less command queries the log, the general process is like this

less log.log
shift + G 命令到文件尾部 然后输入 ?加上你要搜索的关键字例如 ?1213 按 n 向上查找关键字
shift+n                                                     
反 向 查 找 关 键 字less与more类似,使用less可以随意浏览文件,而more仅能向前移动,不能向后移动,而且 less 在查看之前不会加载整个文件。
less log2013.log 查看文件
ps -ef | less ps查看进程信息并通过less分页显示
history | less 查看命令历史使用记录并通过less分页显示
less log2013.log log2014.log 浏览多个文件

Common command parameters:

less与more类似,使用less可以随意浏览文件,而more仅能向前移动,不能向后移动,而且 less 在查看之前不会加载整个文件。
less log2013.log 查看文件
ps -ef | less ps查看进程信息并通过less分页显示
history | less 查看命令历史使用记录并通过less分页显示
less log2013.log log2014.log 浏览多个文件

常用命令参数:
-b <缓冲区大小> 设置缓冲区的大小
-g 只标志最后搜索的关键词
-i 忽略搜索时的大小写
-m 显示类似more命令的百分比
-N 显示每行的行号
-o <文件名> 将less 输出的内容在指定文件中保存起来
-Q 不使用警告音
-s 显示连续空行为一行
/字符串:向下搜索"字符串"的功能
?字符串:向上搜索"字符串"的功能      
n:重复前一个搜索(与 / 或 ? 有关)
N:反向重复前一个搜索(与 / 或 ? 有关)
b   向后翻一页h 显示帮助界面q 退出less 命令

Generally I check the log and cooperate with other commands of the application

history // 所有的历史记录
history | grep XXX // 历史记录中包含某些指令的记录
history | more // 分页查看记录
history -c // 清空所有的历史记录
!! 重复执行上一个命令
查询出来记录后选中 : !323

8. Establish soft link (shortcut) and hard link commands

软链接: ln -s slink source
硬链接: ln link source

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

Create directory: mkdir
creates files: typically touch, vi can also create files, in fact, as long as output to a non-existent file, it will create a file.
Copy file: cp 7. What command is used to modify file permissions? What is the format? File permission modification: chmod

The format is as follows:

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, assign read, execute (5) permissions to the group of file, and assign other users Permission to execute (1)
chmodu=rwx,g=rx,o=xfile Another form of the above example chmod =r file Assign read permissions to all users
chmod444file Same as above example chmod a-wx,a+r file Same as above example
$ chmod -R u+r directory Recursively assign read permissions to the owners of all files and subdirectories under the directory directory

10. What commands can be used to view file contents?

vi file name# edit mode to view, you can modify
cat file name# show all file content
more file name# show file content in pages
less file name# is similar to more, it is better to page forward
tail file name# only view 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

11. Write file commands at will? How to output a string with spaces, such as "hello world" to the screen?

Write file command: vi
outputs a string with spaces to the screen: echo hello world

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

Terminal /dev/tty
black hole file /dev/null

13. Which command is used to move files? Which command is used to change the name?

mv mv

14. Which command is used to copy files? What if you need to copy together with the folder? What if you need a reminder function?

cp cp -r ?? ??

15. 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?

rm rm -r rmdir

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

? "Can replace a single character.
"*" can replace any number of characters. The
square brackets "[charset]" can replace any single character in the charset set, such as [az], [abABC]

17. 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.

18. What is the use of Grep command? How to ignore case? How to find the rows without the string?

Is a powerful text search tool, it can use regular expressions to search for text and print out matching lines.
grep [stringSTRING] filename grep [^string] filename

19. What are the statuses of processes in Linux? What symbols are used in the information displayed by ps?

  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 certain events (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 body 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 is stopped or tracked Z zombie process
    • W enters memory swap (invalid starting from kernel 2.6)
    • X dead process

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

Usually use & at the end of the command to let the program run automatically. (No space can be added after the command)

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

ps -ef (system v 输出) 
ps -aux bsd 格式输出
ps -ef | grep pid

22. Which command is used to view background tasks?

job -l

23. 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 the background task to the foreground to execute fg and execute
the stopped background task in the background bg

24. 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

25. How to check all the signals supported by the system?

kill -l

26. 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 add file name
find directly search the disk, slower.
find / -name “string*”

27. 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 the terminal information you are in: who am i to
see who is currently using the host: who

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

history

29. What command can I use to view the disk usage space? What about free space?

df -h

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

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

netstat

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

ifconfig

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

View all env to
view one, such as home: env $HOME

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

  • \u: Display 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 command line': Display command line' : Significant shows command command line ' ' or '#' symbol
  • #: The first order issued
  • \d: represents the date, the format is week day month date, for example: "MonAug1"
  • \t: Display time in 24-hour format, such as: HH: MM: SS
  • \T: Display time in 12-hour format
  • \A: Display time in 24 hours format: HH: MM
  • \v: BASH version information such as export PS1='[\u@\h\w#]$'

34. Where do you find the executable file of the search command? How to set and add it?

whereis [-bfmsu][-B <directory>…][-M <directory>…][-S <directory>…][file…]
Supplementary explanation: The whereis command will search for files that meet the conditions 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.
-p is the same as -n, but here includes the path of the file. -w specifies the width of the field during output.
-V display version information

35. 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.

36. How to alias a command?

alias la = 'ls -a

37. The definition and difference of du and df?

du displays the size of the 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.

38, awk detailed explanation.

awk '{pattern + action}' {filenames}
#cat /etc/passwd |awk -F ':' '{print 1"\t"7}' //-F 的意思是以':'分隔 root
/bin/bash
daemon /bin/sh 搜索/etc/passwd 有 root 关键字的所有行
#awk -F: '/root/' /etc/passwd root:x:0:0:root:/root:/bin/bash

39. What should you do when you need to bind a macro or button to a command?

You can use the bind command, and bind can easily implement macro or key binding in the shell. When performing key binding, we need to obtain the character sequence corresponding to the bound key first.
For example, the method of obtaining the character sequence of F12 is as follows: first press Ctrl+V, then press F12. We can get the character sequence of F12 ^[[24~.
Then use bind to bind

[root@localhost ~]# bind ‘”\e[24~":"date"'

Note: The same key may produce different character sequences in different terminals or terminal emulators.
[Attachment] You can also use the showkey -a command to view the character sequence corresponding to the key.

40. If a Linux novice wants to know the list of all the commands supported by the current system, what should he do?

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

[root@localhost ~]$ compgen -c 
l.ll 
ls
which 
if 
then 
else 
elif 
fi

case 
esac 
for 
select 
while 
until 
do 
done
…

41. If your assistant wants to print out the current directory stack, what would you recommend him to do?

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

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

42. Your system currently has many running tasks. Is there any way to remove all running processes without restarting the machine?

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

43. 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

44. Which bash built-in command can perform mathematical operations.

The built-in command let of the bash shell can perform mathematical operations on integer numbers

#! /bin/bash
… … le t c=a+b
… …

45. How to view the contents of a large file page by page?

This need can be achieved by connecting the command "cat file_name.txt" and'more' through a pipeline

[root@localhost ~]# cat file_name.txt | more

46. ​​Which user does the data dictionary belong to?

The data dictionary belongs to the'SYS' user, and the users'SYS' and'SYSEM' are automatically created by the system by default

47. How to view the summary and usage of a linux command? Suppose you accidentally see a command in the /bin directory that you have never seen before, how can you know its function and usage?

Use the command whatis to show the brief usage of this command first. For example, you can use whatis zcat to view the introduction and brief usage of'zcat'.


[root@localhost ~]# whatis zcat
zcat [gzip] (1) – compress or expand files

48. Which command can I use to check the disk space quota of my file system?

Use the command repquota to display the quota information of a file system
[Attachment] Only the root user can view the quotas of other users.

Extended connection: click here for more bold styles

The blogger's public account programmer Xiaoyang only posts interview-related tweets
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44395707/article/details/106418693