TranslateProject/sources/talk/20141223 20 Linux Commands Interview Questions & Answers.md

144 lines
6.1 KiB
Markdown
Raw Normal View History

2015-01-13 12:50:55 +08:00
20条Linux命令面试问答
2014-12-23 16:47:50 +08:00
================================================================================
2015-01-13 15:01:19 +08:00
**问:1 如何查看当前的Linux服务器的运行级别**
2014-12-23 16:47:50 +08:00
2015-01-13 15:01:19 +08:00
答: who -rrunlevel 命令可以用来查看当前的Linux服务器的运行级别。
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:2 如何查看Linux的默认网关**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: 用 “route -n” 和 “netstat -nr” 命令,我们可以查看默认网关。除了默认的网关信息,这两个命令还可以显示当前的路由表。
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:3 如何在Linux上重建初始化内存盘影响文件**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: 在CentOS 5.X / RHEL 5.X中可以用mkinitrd命令来创建初始化内存盘文件举例如下
2014-12-23 16:47:50 +08:00
# mkinitrd -f -v /boot/initrd-$(uname -r).img $(uname -r)
2015-01-14 11:19:47 +08:00
如果你想要给特定的内核版本创建初始化内存盘,你就用所需的内核名替换掉 uname -r
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
在CentOS 6.X / RHEL 6.X中则用dracut命令来创建初始化内存盘文件举例如下
2014-12-23 16:47:50 +08:00
# dracut -f
2015-01-14 11:19:47 +08:00
以上命令能给当前的系统版本创建初始化内存盘,给特定的内核版本重建初始化内存盘文件则使用以下命令:
2014-12-23 16:47:50 +08:00
# dracut -f initramfs-2.x.xx-xx.el6.x86_64.img 2.x.xx-xx.el6.x86_64
2015-01-14 11:19:47 +08:00
**问:4 cpio命令是什么**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: cpio就是复制入和复制出的意思。cpio可以向一个归档文件或单个文件复制文件、列表还可以从中提取文件。
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:5 patch命令是什么如何使用**
2014-12-23 16:47:50 +08:00
2015-01-16 16:58:03 +08:00
答: 顾名思义patch命令就是用来将修改或补丁写进文本文件里。Patch命令通常是接收diff的输出并把文件的旧版本转换为新版本。举个例子Linux内核源代码由百万行代码文件构成所以无论何时任何代码贡献者贡献出代码只需发送改动的部分而不是整个源代码然后接收者用patch命令将改动写进原始的源代码里。
2014-12-23 16:47:50 +08:00
2015-01-16 16:58:03 +08:00
创建一个diff文件给patch使用
2014-12-23 16:47:50 +08:00
# diff -Naur old_file new_file > diff_file
2015-01-16 16:58:03 +08:00
旧文件和新文件要么都是单个的文件要么都是包含文件的目录r选项支持目录树递归。
2014-12-23 16:47:50 +08:00
2015-01-16 16:58:03 +08:00
一旦diff文件创建好我们就能在旧的文件上打上补丁把它变成新文件
2014-12-23 16:47:50 +08:00
# patch < diff_file
2015-01-16 16:58:03 +08:00
**问:6 aspell有什么用 ?**
2014-12-23 16:47:50 +08:00
2015-01-18 16:25:33 +08:00
答: 顾名思义aspell就是Linux操作系统上的一款交互式拼写检查器。aspell命令继任了更早的一个名为ispell的程序并且作为一款嵌入式替代品最重要的是它非常好用。While the aspell program is mostly used by other programs that require spell-checking capability, it can also be used very effectively as a stand-alone tool from the command line.
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:7 How to check the SPF record of domain from command line ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: We can check SPF record of a domain using dig command. Example is shown below :
2014-12-23 16:47:50 +08:00
linuxtechi@localhost:~$ dig -t TXT google.com
2015-01-14 11:19:47 +08:00
**问:8 How to identify which package the specified file (/etc/fstab) is associated with in linux ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: # rpm -qf /etc/fstab
2014-12-23 16:47:50 +08:00
Above command will list the package which provides file “/etc/fstab”
2015-01-14 11:19:47 +08:00
**问:9 Which command is used to check the status of bond0 ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: cat /proc/net/bonding/bond0
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:10 What is the use of /proc file system in linux ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: The /proc file system is a RAM based file system which maintains information about the current state of the running kernel including details on CPU, memory, partitioning, interrupts, I/O addresses, DMA channels, and running processes. This file system is represented by various files which do not actually store the information, they point to the information in the memory. The /proc file system is maintained automatically by the system.
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:11 How to find files larger than 10MB in size in /usr directory ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: # find /usr -size +10M
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:12 How to find files in the /home directory that were modified more than 120 days ago ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: # find /home -mtime +l20
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:13 How to find files in the /var directory that have not been accessed in the last 90 days ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: # find /var -atime -90
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:14 Search for core files in the entire directory tree and delete them as found without prompting for confirmation**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: # find / -name core -exec rm {} \;
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:15 What is the purpose of strings command ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: The strings command is used to extract and display the legible contents of a non-text file.
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:16 What is the use tee filter ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: The tee filter is used to send an output to more than one destination. It can send one copy of the output to a file and another to the screen (or some other program) if used with pipe.
2014-12-23 16:47:50 +08:00
linuxtechi@localhost:~$ ll /etc | nl | tee /tmp/ll.out
In the above example, the output from ll is numbered and captured in /tmp/ll.out file. The output is also displayed on the screen.
2015-01-14 11:19:47 +08:00
**问:17 What would the command export PS1 = ”$LOGNAME@`hostname`:\$PWD: do ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: The export command provided will change the login prompt to display username, hostname, and the current working directory.
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:18 What would the command ll | awk {print $3,”owns”,$9} do ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: The ll command provided will display file names and their owners.
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:19 What is the use of at command in linux ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: The at command is used to schedule a one-time execution of a program in the future. All submitted jobs are spooled in the /var/spool/at directory and executed by the atd daemon when the scheduled time arrives.
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
**问:20 What is the role of lspci command in linux ?**
2014-12-23 16:47:50 +08:00
2015-01-14 11:19:47 +08:00
答: The lspci command displays information about PCI buses and the devices attached to your system. Specify -v, -vv, or -vvv for detailed output. With the -m option, the command produces more legible output.
2014-12-23 16:47:50 +08:00
--------------------------------------------------------------------------------
via: http://www.linuxtechi.com/20-linux-commands-interview-questions-answers/
作者:[Pradeep Kumar][a]
2015-01-13 12:50:55 +08:00
译者:[ZTinoZ](https://github.com/ZTinoZ)
2014-12-23 16:47:50 +08:00
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.linuxtechi.com/author/pradeep/
[1]:
[2]:
[3]:
[4]:
[5]:
[6]:
[7]:
[8]:
[9]:
[10]:
[11]:
[12]:
[13]:
[14]:
[15]:
[16]:
[17]:
[18]:
[19]:
2015-01-12 10:37:45 +08:00
[20]: