一、hdfs基本命令:
hadoop fs -cmd <args>
選項:
cmd: 具體的操作,基本上與UNIX的命令行相同
args: 參數
二、hdfs資源uri格式:
用法:scheme://authority/path
選項:
scheme–>協議名,file或hdfs
authority–>namenode主機名
path–>路徑
范例:hdfs://localhost:54310/user/hadoop/test.txt
假設已經在/home/hadoop/hadoop-1.1.1/conf/core-site.xml里配置了fs.default.name=hdfs://localhost:54310,則僅使用/user/hadoop/test.txt即可。hdfs默認工作目錄為/user/$USER,$USER是當前的登錄用戶名。
三、hdfs命令范例
hadoop fs -mkdir /user/hadoop
hadoop fs -ls /user
hadoop fs -lsr /user(遞歸的)
hadoop fs -put test.txt /user/hadoop(復制到hdfs://localhost:54310/user/hadoop目錄下,首先要創建當前目錄)
hadoop fs -get /user/hadoop/test.txt .(復制test.txt文件到本地當前目錄下)
hadoop fs -cat /user/hadoop/test.txt
hadoop fs -tail /user/hadoop/test.txt(查看最后1000字節)
hadoop fs -rm /user/hadoop/test.txt
hadoop fs -help ls(查看ls命令的幫助文檔)
四、在put時遇到的問題
異常信息: org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create file/user/hadoopadmin. Name node is in safe mode.
解決辦法:hadoop dfsadmin -safemode leave