发布于:,更新于:

Linux查询操作

  1. whereis用来寻找可执行文件的位置
1
2
3
4
5
6
7
8
[root@master ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
[root@master ~]# ls
aaa  anaconda-ks.cfg  localperl  nohup.out  perl5  ShiSai2022-1.0-SNAPSHOT.jar 
spark-yarn-logs  zookeeper.out
[root@master ~]# cd /usr/bin/
[root@master bin]# ll ls
-rwxr-xr-x. 1 root root 117680 10月 31 2018 ls
  1. whatis用来获取命令的简介
1
2
[root@master bin]# whatis ls
ls (1)               - list directory contents
  1. find用来寻找文件的位置

从根目录下开始,寻找cd这个文件的位置。一共找到了3处。

1
2
3
4
5
6
7
[root@master ~]# find / -name cd
/root/.npm/_cacache/index-v5/cd
/root/.npm/_cacache/content-v2/sha512/f7/cd
/usr/bin/cd
[root@master ~]# cd /usr/bin/
[root@master bin]# ls cd
cd
  1. grep用来查找文件中,包含指定字符串的行

建立./aaa.txt并插入一些内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@master ~]# echo "hello hadoop" > ./aaa.txt
[root@master ~]# echo "hello hdfs" >> ./aaa.txt
[root@master ~]# echo "hello hdfs" >> ./aaa.txt
[root@master ~]# echo "hello yarn" >> ./aaa.txt
[root@master ~]# echo "hello spark" >> ./aaa.txt
[root@master ~]# echo "hello hive" >> ./aaa.txt
[root@master ~]# echo "hello flink" >> ./aaa.txt
[root@master ~]# echo "hello hbase" >> ./aaa.txt
[root@master ~]# cat ./aaa.txt
hello hadoop
hello hdfs
hello hdfs
hello yarn
hello spark
hello hive
hello flink
hello hbase

在./aaa.txt里查找含有字符串hadoop的行

1
2
3
4
5
6
7
[root@master ~]# grep hadoop ./aaa.txt
hello Hadoop
[root@master ~]# grep flink ./aaa.txt
hello flink
[root@master ~]# grep hdfs ./aaa.txt
hello hdfs
hello hdfs
  1. 用数字法修改文件的权限

./aaa.txt原来的权限:对于文件的所有者而言aaa.txt可读可写不可执行,对于同组用户而言aaa.txt可读不可写不可执行,对于其他用户而言aaa.txt可读不可写不可执行

1
2
3
4
5
6
[root@master ~]# ll ./aaa.txt
-rw-r--r--. 1 root root 93 11月 20 08:21 ./aaa.txt
 421421421
  6   4  4
-rwxr--r--
  7  4  4

把./aaa.txt变成:对于文件的所有者而言aaa.txt可读可写可执行,对于同组用户而言aaa.txt可读不可写不可执行,对于其他用户而言aaa.txt可读不可写不可执行

1
2
3
[root@master ~]# chmod 744 ./aaa.txt
[root@master ~]# ll ./aaa.txt
-rwxr--r--. 1 root root 93 11月 20 08:21 ./aaa.txt

把./aaa.txt变成:对于文件的所有者而言aaa.txt可读可写可执行,对于同组用户而言aaa.txt可读可写可执行,对于其他用户而言aaa.txt可读可写可执行

1
2
3
[root@master ~]# chmod 777 ./aaa.txt
[root@master ~]# ll ./aaa.txt
-rwxrwxrwx. 1 root root 93 11月 20 08:21 ./aaa.txt

把./aaa.txt变回到原来状态

1
2
3
[root@master ~]# chmod 644 ./aaa.txt
[root@master ~]# ll ./aaa.txt
-rw-r--r--. 1 root root 93 11月 20 08:21 ./aaa.txt

课堂练习:

把hadoop01镜像转到20230912,并启动hadoop01,用Ubuntu进行联机。完成下面的操作,并把命令和结果截图粘贴到ubuntu桌面下的目录Release的“模块A提交的结果.docx”。要求所有命令均使用绝对路径。

  1. 在/root目录下建立子目录bbb
1
mkdir /root/bbb
  1. 在/root/bbb目录下建立文件b01.txt
1
touch /root/bbb/b01.txt
  1. 在b01.txt中插入以下内容:

    Hello Hadoop Hello hdfs Hello spark Hello flink Hello yarn Hello hbase

1
2
3
4
5
6
7
8
cat >> /root/bbb/b01.txt << EOF
Hello Hadoop
Hello hdfs
Hello spark
Hello flink
Hello yarn
Hello hbase
EOF
  1. 将b01.txt拷贝为b02.txt,并在b02.txt中新增两行内容:

    Hello Redis Hello clickhouse

1
2
3
cp /root/bbb/b01.txt /root/bbb/b02.txt
echo "Hello Redis" >> /root/bbb/b02.txt
echo "Hello clickhouse" >> /root/bbb/b02.txt
  1. 用diff命令比较b01.txt、b02.txt的不同之处
1
diff /root/bbb/b01.txt /root/bbb/b02.txt
  1. 用grep命令查找b01.txt中含有flink的行
1
grep "flink" /root/bbb/b01.txt
  1. 修改/root/bbb/b01.txt的权限:文件所有者可读可写可执行,同组用户可读可写不可执行,其他用户不可读不可写不可执行,并用ls命令查看结果
1
chmod 760 /root/bbb/b01.txt && ls -l /root/bbb/b01.txt
  1. 修改/root/bbb/b02.txt的权限:文件所有者可读不可写可执行,同组用户可读不可写不可执行,其他用户不可读不可写可执行,并用ls命令查看结果
1
chmod 441 /root/bbb/b01.txt && ls -l /root/bbb/b01.txt
  1. 用find命令查找b01.txt文件的位置
1
find / -name b01.txt
  1. 用whereis命令查找grep命令文件的位置
1
whereis grep
  1. 用tar命令将到/opt/hadoop-2.7.7.tar.gz解压到/usr/local/src下面。
1
tar -xvzf /opt/hadoop-2.7.7.tar.gz -C /usr/local/src
  1. 用find命令查找文件stop-all.sh的位置。
1
find / -name stop-all.sh