您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“hadoop中fs常用命令有哪些”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“hadoop中fs常用命令有哪些”這篇文章吧。
1 介紹
Hadoop文件系統(tǒng)(FS)默認提供了各種shell命令,可用于與Hadoop分布式文件系統(tǒng)(HDFS)或任何其他使用Hadoop Shell的支持文件系統(tǒng)進行交互。 一些最常用的命令是用于諸如創(chuàng)建目錄,復(fù)制文件,查看文件內(nèi)容,更改文件的所有權(quán)或權(quán)限等操作。
hadoop fs等同于 hdfs dfs
[hadoop@hadoop002 hadoop]$ hdfs dfs
Usage: hadoop fs [generic options]
2 公用命令
2.1 創(chuàng)建目錄命令: hdfs dfs -mkdir <paths>
[hadoop@hadoop002 hadoop]$ hdfs dfs -mkdir /20180523
[hadoop@hadoop002 hadoop]$
2.2.列出目錄的內(nèi)容命令: 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 查看文件內(nèi)容:hdfs dfs -cat <paths>
[hadoop@hadoop002 ~]$ hdfs dfs -cat /gw_test.log4
1111
2222
3333
4444
5555
[hadoop@hadoop002 ~]$
2.6 復(fù)制文件命令: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 計數(shù)目錄和文件命令: hdfs dfs -count <path>
[hadoop@hadoop002 ~]$ hdfs dfs -count /gw_test.log3
0 1 25 /gw_test.log3
2.12 文件系統(tǒng)中的空間的詳細信息命名: 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常用命令有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。