hdfs dfs -Linux 常用命令练习
Posted 小小程序员呀~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdfs dfs -Linux 常用命令练习相关的知识,希望对你有一定的参考价值。
1.先查看环境:
[hadoop@hadoop001 ~]$ jps
22673 SecondaryNameNode
22502 DataNode
22396 NameNode
24397 Jps
2.命令练习:
2.1 查看目录
[hadoop@hadoop001 ~]$ hdfs dfs -ls /
Found 5 items
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:16 /input
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:31 /output1
drwxr-xr-x - hadoop supergroup 0 2021-12-04 01:09 /system
drwx------ - hadoop supergroup 0 2021-12-01 23:29 /tmp
drwx------ - hadoop supergroup 0 2021-12-04 02:05 /user
2.2 创建文件夹
[hadoop@hadoop001 ~]$ hdfs dfs -mkdir /1
[hadoop@hadoop001 ~]$ hdfs dfs -ls /
Found 6 items
drwxr-xr-x - hadoop supergroup 0 2021-12-04 14:10 /1
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:16 /input
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:31 /output1
drwxr-xr-x - hadoop supergroup 0 2021-12-04 01:09 /system
drwx------ - hadoop supergroup 0 2021-12-01 23:29 /tmp
drwx------ - hadoop supergroup 0 2021-12-04 02:05 /user
2.3 修改用户用组
[hadoop@hadoop001 ~]$ hdfs dfs -chown root /1
[hadoop@hadoop001 ~]$ hdfs dfs -ls /
Found 6 items
drwxr-xr-x - root supergroup 0 2021-12-04 14:10 /1
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:16 /input
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:31 /output1
drwxr-xr-x - hadoop supergroup 0 2021-12-04 01:09 /system
drwx------ - hadoop supergroup 0 2021-12-01 23:29 /tmp
drwx------ - hadoop supergroup 0 2021-12-04 02:05 /user
2.4 修改文件文件夹权限
[hadoop@hadoop001 ~]$ hdfs dfs -ls /
Found 7 items
drwxr-xr-x - root supergroup 0 2021-12-04 14:15 /1
-rw-r--r-- 1 hadoop supergroup 0 2021-12-04 14:19 /2.log
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:16 /input
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:31 /output1
drwxr-xr-x - hadoop supergroup 0 2021-12-04 01:09 /system
drwx------ - hadoop supergroup 0 2021-12-01 23:29 /tmp
drwx------ - hadoop supergroup 0 2021-12-04 02:05 /user
[hadoop@hadoop001 ~]$ hdfs dfs -chmod 777 /1
[hadoop@hadoop001 ~]$ hdfs dfs -ls /
Found 6 items
drwxrwxrwx - root supergroup 0 2021-12-04 14:15 /1
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:16 /input
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:31 /output1
drwxr-xr-x - hadoop supergroup 0 2021-12-04 01:09 /system
drwx------ - hadoop supergroup 0 2021-12-01 23:29 /tmp
drwx------ - hadoop supergroup 0 2021-12-04 02:05 /user
2.5 上传到hdfs
[hadoop@hadoop001 ~]$ ll
total 4
-rw-rw-r--. 1 hadoop hadoop 71 Dec 1 23:15 1.log
drwxrwxr-x. 6 hadoop hadoop 143 Nov 27 22:12 app
drwxrwxr-x. 3 hadoop hadoop 19 Oct 30 10:17 data
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Desktop
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Documents
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Downloads
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 lib
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 log
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Music
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Pictures
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Public
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 shell
drwxrwxr-x. 2 hadoop hadoop 132 Nov 25 23:04 software
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 sourcecode
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Templates
drwxrwxr-x. 5 hadoop hadoop 196 Dec 4 02:04 tmp
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Videos
[hadoop@hadoop001 ~]$ hdfs dfs -put 1.log /
[hadoop@hadoop001 ~]$ hdfs dfs -ls /
Found 7 items
drwxr-xr-x - root supergroup 0 2021-12-04 14:10 /1
-rw-r--r-- 1 hadoop supergroup 71 2021-12-04 14:12 /1.log
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:16 /input
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:31 /output1
drwxr-xr-x - hadoop supergroup 0 2021-12-04 01:09 /system
drwx------ - hadoop supergroup 0 2021-12-01 23:29 /tmp
drwx------ - hadoop supergroup 0 2021-12-04 02:05 /user
2.6 hdfs下载到本地
[hadoop@hadoop001 ~]$ ll
total 4
-rw-rw-r--. 1 hadoop hadoop 71 Dec 1 23:15 1.log
drwxrwxr-x. 6 hadoop hadoop 143 Nov 27 22:12 app
drwxrwxr-x. 3 hadoop hadoop 19 Oct 30 10:17 data
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Desktop
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Documents
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Downloads
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 lib
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 log
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Music
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Pictures
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Public
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 shell
drwxrwxr-x. 2 hadoop hadoop 132 Nov 25 23:04 software
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 sourcecode
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Templates
drwxrwxr-x. 5 hadoop hadoop 196 Dec 4 02:04 tmp
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Videos
[hadoop@hadoop001 ~]$ hdfs dfs -get /1 /home/hadoop/
[hadoop@hadoop001 ~]$ ll
total 4
drwxr-xr-x. 2 hadoop hadoop 6 Dec 4 14:14 1
-rw-rw-r--. 1 hadoop hadoop 71 Dec 1 23:15 1.log
drwxrwxr-x. 6 hadoop hadoop 143 Nov 27 22:12 app
drwxrwxr-x. 3 hadoop hadoop 19 Oct 30 10:17 data
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Desktop
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Documents
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Downloads
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 lib
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 log
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Music
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Pictures
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Public
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 shell
drwxrwxr-x. 2 hadoop hadoop 132 Nov 25 23:04 software
drwxrwxr-x. 2 hadoop hadoop 6 Oct 27 08:36 sourcecode
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Templates
drwxrwxr-x. 5 hadoop hadoop 196 Dec 4 02:04 tmp
drwxr-xr-x. 2 hadoop hadoop 6 Nov 1 12:08 Videos
2.7 移动文件文件夹
[hadoop@hadoop001 ~]$ hdfs dfs -ls /
Found 7 items
drwxr-xr-x - root supergroup 0 2021-12-04 14:10 /1
-rw-r--r-- 1 hadoop supergroup 71 2021-12-04 14:12 /1.log
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:16 /input
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:31 /output1
drwxr-xr-x - hadoop supergroup 0 2021-12-04 01:09 /system
drwx------ - hadoop supergroup 0 2021-12-01 23:29 /tmp
drwx------ - hadoop supergroup 0 2021-12-04 02:05 /user
[hadoop@hadoop001 ~]$ hdfs dfs -mv /1.log /1
[hadoop@hadoop001 ~]$ hdfs dfs -ls /
Found 6 items
drwxr-xr-x - root supergroup 0 2021-12-04 14:15 /1
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:16 /input
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:31 /output1
drwxr-xr-x - hadoop supergroup 0 2021-12-04 01:09 /system
drwx------ - hadoop supergroup 0 2021-12-01 23:29 /tmp
drwx------ - hadoop supergroup 0 2021-12-04 02:05 /user
[hadoop@hadoop001 ~]$ hdfs dfs -ls /1/
Found 1 items
-rw-r--r-- 1 hadoop supergroup 71 2021-12-04 14:12 /1/1.log
2.8 查看文件内容
[hadoop@hadoop001 ~]$ hdfs dfs -cat /1/1.log
jepson
ruoze
xingxing
a b c
b a c
jepson
www.ruozedata.com ruoze a b c
2.9 创建文件
[hadoop@hadoop001 ~]$ hdfs dfs -ls /
Found 6 items
drwxr-xr-x - root supergroup 0 2021-12-04 14:15 /1
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:16 /input
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:31 /output1
drwxr-xr-x - hadoop supergroup 0 2021-12-04 01:09 /system
drwx------ - hadoop supergroup 0 2021-12-01 23:29 /tmp
drwx------ - hadoop supergroup 0 2021-12-04 02:05 /user
[hadoop@hadoop001 ~]$ hdfs dfs -touch /2.log
[hadoop@hadoop001 ~]$ hdfs dfs -ls /
Found 7 items
drwxr-xr-x - root supergroup 0 2021-12-04 14:15 /1
-rw-r--r-- 1 hadoop supergroup 0 2021-12-04 14:19 /2.log
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:16 /input
drwxr-xr-x - hadoop supergroup 0 2021-12-01 23:31 /output1
drwxr-xr-x - hadoop supergroup 0 2021-12-04 01:09 /system
drwx------ - hadoop supergroup 0 2021-12-01 23:29 /tmp
drwx------ - hadoop supergroup 0 2021-12-04 02:05 /user
2.10 删除文件文件夹
[hadoop@hadoop001 ~]$ hdfs dfs -rm /2.log
2021-12-04 14:22:04,360 INFO fs.TrashPolicyDefault: Moved: 'hdfs://hadoop001:9000/2.log' to trash at: hdfs://hadoop001:9000/user/hadoop/.Trash/Current/2.log
以上是关于hdfs dfs -Linux 常用命令练习的主要内容,如果未能解决你的问题,请参考以下文章