您好,登录后才能下订单哦!
这篇文章主要为大家展示了“hadoop中fs常用命令有哪些”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“hadoop中fs常用命令有哪些”这篇文章吧。
1 介绍
Hadoop文件系统(FS)默认提供了各种shell命令,可用于与Hadoop分布式文件系统(HDFS)或任何其他使用Hadoop Shell的支持文件系统进行交互。 一些最常用的命令是用于诸如创建目录,复制文件,查看文件内容,更改文件的所有权或权限等操作。
hadoop fs等同于 hdfs dfs
[hadoop@hadoop002 hadoop]$ hdfs dfs
Usage: hadoop fs [generic options]
2 公用命令
2.1 创建目录命令: hdfs dfs -mkdir <paths>
[hadoop@hadoop002 hadoop]$ hdfs dfs -mkdir /20180523
[hadoop@hadoop002 hadoop]$
2.2.列出目录的内容命令: hdfs dfs -ls <paths>
[hadoop@hadoop002 hadoop]$ hdfs dfs -ls /
Found 5 items
drwxr-xr-x - hadoop supergroup 0 2018-05-23 14:48 /20180523
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 13:04 /gw_test.log3
drwxr-xr-x - root root 0 2018-05-23 13:16 /root
drwx------ - hadoop supergroup 0 2018-05-22 11:23 /tmp
drwxr-xr-x - hadoop supergroup 0 2018-05-22 11:22 /user
[hadoop@hadoop002 hadoop]$
2.3 在HDFS中上传文件: hdfs dfs -put <local_files> ... <hdfs_path>
[hadoop@hadoop002 hadoop]$ cd ~
[hadoop@hadoop002 ~]$ ll
total 4
-rw-rw-r--. 1 hadoop hadoop 0 May 21 17:09 authorized_key
-rw-r--r--. 1 hadoop hadoop 25 May 23 12:17 gw_test.log3
[hadoop@hadoop002 ~]$ hdfs dfs -put gw_test.log3 /gw_test.log4
[hadoop@hadoop002 ~]$ hdfs dfs -ls /
Found 6 items
drwxr-xr-x - hadoop supergroup 0 2018-05-23 14:48 /20180523
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 13:04 /gw_test.log3
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 14:50 /gw_test.log4
drwxr-xr-x - root root 0 2018-05-23 13:16 /root
drwx------ - hadoop supergroup 0 2018-05-22 11:23 /tmp
drwxr-xr-x - hadoop supergroup 0 2018-05-22 11:22 /user
2.4 从HDFS下载文件:hdfs dfs -get <hdfs_paths> <local_path>
[hadoop@hadoop002 ~]$ ll
total 4
-rw-rw-r--. 1 hadoop hadoop 0 May 21 17:09 authorized_key
-rw-r--r--. 1 hadoop hadoop 25 May 23 12:17 gw_test.log3
[hadoop@hadoop002 ~]$ hdfs dfs -get /gw_test.log4
[hadoop@hadoop002 ~]$ ll
total 8
-rw-rw-r--. 1 hadoop hadoop 0 May 21 17:09 authorized_key
-rw-r--r--. 1 hadoop hadoop 25 May 23 12:17 gw_test.log3
-rw-r--r--. 1 hadoop hadoop 25 May 23 14:52 gw_test.log4
2.5 查看文件内容:hdfs dfs -cat <paths>
[hadoop@hadoop002 ~]$ hdfs dfs -cat /gw_test.log4
1111
2222
3333
4444
5555
[hadoop@hadoop002 ~]$
2.6 复制文件命令:hdfs dfs -cp <source_path> ... <destination_path>
[hadoop@hadoop002 ~]$ hdfs dfs -cp /gw_test.log3 /20180523
[hadoop@hadoop002 ~]$ hdfs dfs -ls /20180523
Found 1 items
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 14:55 /20180523/gw_test.log3
[hadoop@hadoop002 ~]$
2.7 将文件从源移动到目标命令: hdfs dfs -mv <source_path> <destination_path>
[hadoop@hadoop002 ~]$ hdfs dfs -ls /
Found 6 items
drwxr-xr-x - hadoop supergroup 0 2018-05-23 14:55 /20180523
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 13:04 /gw_test.log3
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 14:50 /gw_test.log4
drwxr-xr-x - root root 0 2018-05-23 13:16 /root
drwx------ - hadoop supergroup 0 2018-05-22 11:23 /tmp
drwxr-xr-x - hadoop supergroup 0 2018-05-22 11:22 /user
[hadoop@hadoop002 ~]$ hdfs dfs -mv /gw_test.log4 /20180523
[hadoop@hadoop002 ~]$ hdfs dfs -ls /
Found 5 items
drwxr-xr-x - hadoop supergroup 0 2018-05-23 14:57 /20180523
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 13:04 /gw_test.log3
drwxr-xr-x - root root 0 2018-05-23 13:16 /root
drwx------ - hadoop supergroup 0 2018-05-22 11:23 /tmp
drwxr-xr-x - hadoop supergroup 0 2018-05-22 11:22 /user
[hadoop@hadoop002 ~]$ hdfs dfs -ls /20180523
Found 2 items
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 14:55 /20180523/gw_test.log3
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 14:50 /20180523/gw_test.log4
[hadoop@hadoop002 ~]$
[hadoop@hadoop002 ~]$ hdfs dfs -rm -r /20180523
Deleted /20180523
[hadoop@hadoop002 ~]$ hdfs dfs -ls /
Found 4 items
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 13:04 /gw_test.log3
drwxr-xr-x - root root 0 2018-05-23 13:16 /root
drwx------ - hadoop supergroup 0 2018-05-22 11:23 /tmp
drwxr-xr-x - hadoop supergroup 0 2018-05-22 11:22 /user
[hadoop@hadoop002 ~]$
2.8 从HDFS中删除文件或目录命令:
hdfs dfs -rm <path> -- 删除文件
hdfs dfs -rm -r <path> -- 删除目录
[hadoop@hadoop002 ~]$ hdfs dfs -ls /20180523
Found 2 items
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 14:55 /20180523/gw_test.log3
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 14:50 /20180523/gw_test.log4
[hadoop@hadoop002 ~]$ hdfs dfs -rm /20180523/gw_test.log3
Deleted /20180523/gw_test.log3
[hadoop@hadoop002 ~]$ hdfs dfs -ls /20180523
Found 1 items
-rw-r--r-- 1 hadoop supergroup 25 2018-05-23 14:50 /20180523/gw_test.log4
[hadoop@hadoop002 ~]$
2.9 显示文件的尾部命令:hdfs dfs -tail <path>
[hadoop@hadoop002 ~]$ hdfs dfs -tail /gw_test.log3
1111
2222
3333
4444
5555
[hadoop@hadoop002 ~]$
2.10 显示特定文件的总长度命令: hdfs dfs -du <path>
[hadoop@hadoop002 ~]$ hdfs dfs -du /gw_test.log3
25 /gw_test.log3
[hadoop@hadoop002 ~]$
2.11 计数目录和文件命令: hdfs dfs -count <path>
[hadoop@hadoop002 ~]$ hdfs dfs -count /gw_test.log3
0 1 25 /gw_test.log3
2.12 文件系统中的空间的详细信息命名: hdfs dfs -df <path>
[hadoop@hadoop002 ~]$ hdfs dfs -df /
Filesystem Size Used Available Use%
hdfs://hadoop002:9000 40028807168 704512 30802395136 0%
[hadoop@hadoop002 ~]$
以上是“hadoop中fs常用命令有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。