大数据Linux面试题

面试大数据时遇到的一些关于Linux的问题

  1. Linux下创建目录/tmp/etc,然后递归删除目录/tmp/etc?

创建多级目录:mkdir -p /tmp/etc

[root@node01 ~]# cd /tmp/etc/
-bash: cd: /tmp/etc/: No such file or directory
[root@node01 ~]# mkdir -p /tmp/etc/
[root@node01 ~]# cd /tmp/etc/      
[root@node01 etc]# 

递归删除目录:rm -rf /tmp/etc

[root@node01 etc]# rm -rf /tmp/etc/
[root@node01 etc]# ls
[root@node01 etc]# cd ..
[root@node01 tmp]# cd /tmp/etc/
-bash: cd: /tmp/etc/: No such file or directory
  1. 在Unix/Linux中,查看最近执行的3条命令?

使用history的命令,包含history本身这条命令的话是history 3,不包含是history 4

[root@node01 tmp]# history 3
 1005  cd /tmp/etc/
 1006  history -3
 1007  history 3

一般来说,回答history 4,然后解释一下说,不包含history这条命令本身显得专业一点。

[root@node01 tmp]# history 4
 1005  cd /tmp/etc/
 1006  history -3
 1007  history 3
 1008  history 4
  1. 在Unix/Linux当前目录下,查找文件A.sh中包含关键字"what"(不区分大小写)的行?

考察grep命令的用法,很简单的 grep "what" -i -n

参数 -i 忽略大小写

参数 -n 显示行号

在网上找了篇英文文章当做案例的文本

There are moments in life when you miss someone so much that you just want to pick 
them from your dreams and hug them for real! Dream what you want to dream;go where you 
ant to go;be WHAT you want to be,because you have only one life and one chance to do 
all the things you want to do.

查找文件A.sh中包含关键字"what"(不区分大小写)的行

[root@node01 tmp]# grep "what" A.sh -i -n    
2:them from your dreams and hug them for real! Dream what you want to dream;go where you 
3:ant to go;be WHAT you want to be,because you have only one life and one chance to do 

也可以看看不加-i参数的效果,不能忽略大小写

[root@node01 tmp]# grep "what" A.sh  -n  
2:them from your dreams and hug them for real! Dream what you want to dream;go where you 

不加参数-n的效果,不显示行号

[root@node01 tmp]# grep "what" A.sh
them from your dreams and hug them for real! Dream what you want to dream;go where you 
  1. 在Unix/Linux中,访问目录/tmp,并列出目录/tmp下所有文件(包含隐藏文件)?

    cd tmp目录,然后ls -a列出所有文件,如果要列出详情可以使用ls -al

很简单的题目,对于这样简单的题目,当然要说的精确而且快速,如果是面试,还可以补充一下linux的文件类型,隐藏的是以.开头等等

实际效果

[root@node01 tmp]# ls
A.sh  hsperfdata_impala  hsperfdata_root
[root@node01 tmp]# ls -a
.  ..  A.sh  hsperfdata_impala  hsperfdata_root  .ICE-unix
[root@node01 tmp]# ls -al
total 24
drwxrwxrwt.  5 root   root   4096 Oct 31 08:48 .
dr-xr-xr-x. 26 root   root   4096 Oct  7 09:01 ..
-rw-r--r--   1 root   root    289 Oct 31 08:48 A.sh
drwxr-xr-x   2 impala impala 4096 Oct 17 13:35 hsperfdata_impala
drwxr-xr-x   2 root   root   4096 Oct 31 03:58 hsperfdata_root
drwxrwxrwt   2 root   root   4096 Oct  7 09:01 .ICE-unix

你可能感兴趣的:(Linux)