注意:"# ./hdfs dfs -ls /"命令前的"#"表明當前登陸用戶是root。運行路徑位於hadoop目錄中的bin文件夾下。命令中的"."表明當前目錄。命令中涉及的info文件須要提早建立好。以下圖所示:node
# ./hdfs dfs -ls / drwxr-xr-x - root supergroup 0 2018-07-30 00:09 /hbase drwxr-xr-x - root supergroup 0 2018-06-23 15:22 /output drwx------ - root supergroup 0 2018-07-31 00:32 /tmp drwxr-xr-x - root supergroup 0 2018-07-31 00:41 /user -rw-r--r-- 2 root supergroup 77 2018-04-22 02:34 /wordcount
# ./hdfs dfs -mkdir /wanhe # ./hdfs dfs -ls / drwxr-xr-x - root supergroup 0 2018-07-30 00:09 /hbase drwxr-xr-x - root supergroup 0 2018-06-23 15:22 /output drwx------ - root supergroup 0 2018-07-31 00:32 /tmp drwxr-xr-x - root supergroup 0 2018-07-31 00:41 /user drwxr-xr-x - root supergroup 0 2018-09-12 18:00 /wanhe -rw-r--r-- 2 root supergroup 77 2018-04-22 02:34 /wordcount
# ./hdfs dfs -put info /wanhe # ./hdfs dfs -ls /wanhe -rw-r--r-- 2 root supergroup 38 2018-09-12 18:10 /wanhe/info
# rm -rf info # ls container-executor hadoop hadoop.cmd hdfs hdfs.cmd mapred mapred.cmd rcc test-container-executor yarn yarn.cmd # ./hdfs dfs -get /wanhe/info ./ # ls container-executor hadoop hadoop.cmd hdfs hdfs.cmd info mapred mapred.cmd rcc test-container-executor yarn yarn.cmd
# ./hdfs dfs -rm /wanhe/info # ./hdfs dfs -ls /wanhe 空
# ./hdfs dfs -moveFromLocal info /wanhe # ./hdfs dfs -ls /wanhe -rw-r--r-- 2 root supergroup 38 2018-09-12 22:04 /wanhe/info # ls container-executor hadoop hadoop.cmd hdfs hdfs.cmd mapred mapred.cmd rcc test-container-executor yarn yarn.cmd
# ./hdfs dfs -cat /wanhe/info jiangsuwanhe
# ./hdfs dfs -appendToFile info /wanhe/info # ./hdfs dfs -cat /wanhe/info jiangsuwanhe jiangsuwanhe
# ./hdfs dfs -ls /wanhe -rw-r--r-- 2 root supergroup 51 2018-09-12 22:13 /wanhe/info # ./hdfs dfs -chmod 777 /wanhe/info # ./hdfs dfs -ls /wanhe -rwxrwxrwx 2 root supergroup 51 2018-09-12 22:13 /wanhe/info
將/wanhe/info拷貝到/tmp下: # ./hdfs dfs -cp /wanhe/info /tmp/ # ./hdfs dfs -ls /tmp -rw-r--r-- 2 root supergroup 51 2018-09-12 22:20 /tmp/info
將/wanhe/info移動到 /user下 # ./hdfs dfs -mv /wanhe/info /user/ # ./hdfs dfs -ls /wanhe 空 # ./hdfs dfs -ls /user -rwxrwxrwx 2 root supergroup 51 2018-09-12 22:13 /user/info
# ./hdfs dfs -df -h / Filesystem Size Used Available Use% hdfs://master:9000 17.5 G 352 K 11.4 G 0%
# ./hdfs dfs -du /user 51 /user/info
# ./hdfs dfs -count /user 2 1 51 /user 第一列2表示/user/下文件夾的數量,第二列1表示/user/下文件的個數。51表示/user/目錄下全部文件佔用的磁盤容量(不計算副本個數)。
HDFS中的命令行操做相似於linux命令,熟練使用linux命令即可以熟練的使用命令行操做HDFS。後面咱們將連載大數據系列博客,歡迎關注和交流。linux