HDFS 常用命令


參考鏈接

  http://segmentfault.com/a/1190000002672666

1.ls

 列出hdfs文件系統根目錄下的目錄和文件

hadoop@Master:~$ hadoop fs -ls  /
Found 3 items
drwxr-xr-x   - hadoop supergroup          0 2015-07-10 13:53 /hbase
drwx-wx-wx   - hadoop supergroup          0 2015-07-11 17:21 /tmp
drwxr-xr-x   - hadoop supergroup          0 2015-07-11 15:55 /user

 列出hdfs文件系統所有的目錄和文件

hadoop@Master:~$ hadoop fs -ls -R /
drwxr-xr-x   - hadoop supergroup          0 2015-07-10 13:53 /hbase
drwxr-xr-x   - hadoop supergroup          0 2015-07-10 13:53 /hbase/.tmp
drwxr-xr-x   - hadoop supergroup          0 2015-07-10 13:53 /hbase/MasterProcWALs
-rw-r--r--   4 hadoop supergroup          0 2015-07-10 13:53 /hbase/MasterProcWALs/state-00000000000000000021.log
drwxr-xr-x   - hadoop supergroup          0 2015-07-10 13:53 /hbase/

 

2.put

hdfs file的父目錄一定要存在,否則命令不會執行,其實只是上傳一個文件,重名了名而已

 

# hadoop fs -put < local file > < hdfs file >
 
         

hadoop@Master:~$ hadoop fs -put 1.txt /tmp/2.txt

# hadoop fs -put  < local file or dir >...< hdfs dir >
hadoop@Master:~$ hadoop fs -put 1.txt /tmp/

從鍵盤讀取輸入到hdfs file中,按Ctrl+D結束輸入,hdfs file不能存在,否則命令不會執行

#hadoop fs -put - < hdsf  file>

hadoop@Master:~$ hadoop fs -put - /tmp/testfile
我老家在要遠的中國農村
hadoop@Master:~$

2.1.moveFromLocal

與put相類似,命令執行后源文件 local src 被刪除,也可以從從鍵盤讀取輸入到hdfs file中

# hadoop fs -moveFromLocal  < local src > ... < hdfs dst >

hadoop@Master:~$ hadoop fs -moveFromLocal 1.txt /tmp/
moveFromLocal: `/tmp/1.txt': File exists
hadoop@Master:~$ hadoop fs -moveFromLocal 1.txt /tmp/3.txt

2.2.copyFromLocal

 這個和前面的moveFromLocal 不同的是復制本地文件到hdfs file,但是本地會保留源文件

# hadoop fs -copyFromLocal  < local src > ... < hdfs dst >

hadoop@Master:~$ hadoop fs -copyFromLocal derby.log /tmp/derby2.log
hadoop@Master:~$ ls
\ derby.log hadoop.tar.gz hbase-1.1.0.1 jdk-7u80-linux-x64.tar.gz jdk-8u45-linux-x64.tar.gz jdk1.8.0_45 metastore_db user wz
hadoop@Master:~$

3.get

local file不能和 hdfs file名字不能相同,否則會提示文件已存在,沒有重名的文件會復制到本地

 

 

hadoop fs -get < hdfs file > < local file or dir>


hadoop fs -get < hdfs file or dir > ... < local dir >

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM