您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。