查看hdfs文件系统指定路径的文件:
[root@zwt1 ~]# hdfs dfs -ls /
Found 4 items
drwxr-xr-x - root supergroup 02015-11-05 03:31 /data
drwxr-xr-x - root supergroup 02015-11-05 03:32 /output
drwxrwx--- - root supergroup 02015-11-05 07:51 /tmp
drwxr-xr-x - root supergroup 02015-11-06 23:59 /usr
在hdfs文件系统中创建文件夹
[root@zwt1 ~]# hdfs dfs -mkdir /data/mydata
[root@zwt1 ~]# gedit test.txt
[root@zwt1 ~]# hdfs dfs -put test.txt/data/mydata //将本地文件上传到hdfs文件系统中
[root@zwt1 ~]# hdfs dfs -dus/data/mydata/test.txt //查看文件大小
dus: DEPRECATED: Please use 'du -s'instead.
73 /data/mydata/test.txt
[root@zwt1 ~]# hdfs dfs -du /data/mydata //查看文件夹中文件大小
73 /data/mydata/test.txt
[root@zwt1 ~]# hdfs dfs -cp/data/mydata/test.txt /usr/ //从源位置复制到指定位置
[root@zwt1 ~]# hdfs dfs -copyFromLocaltest.txt /tmp //将本地文件上传到hdfs文件系统,相当于put
[root@zwt1 ~]# mkdir data
[root@zwt1 ~]# cd data
[root@zwt1 data]# hdfs dfs -copyToLocal/tmp/test.txt //将hdfs文件系统的文件复制到本地,相当于get
[root@zwt1 data]# ls
test.txt
[root@zwt1 data]# rm test.txt
rm: remove regular file `test.txt'? y
[root@zwt1 data]# ls
[root@zwt1 data]# hdfs dfs -get/tmp/test.txt //将hdfs文件系统的文件复制到本地
[root@zwt1 data]# ls
test.txt
[root@zwt1 data]# cat test.txt
hello world
hello hadoop
spark scala
centos linux
hello linux
bye hadoop
[root@zwt1 data]# ls
test.txt
[root@zwt1 data]# hdfs dfs -put test.txt/output
[root@zwt1 data]# hdfs dfs -ls /output
Found 1 items
-rw-r--r-- 2 root supergroup 732015-11-09 04:37 /output/test.txt
[root@zwt1 data]# hdfs dfs -touchz/tmp/mydata.txt //创建一个空文件
[root@zwt1 data]# hdfs dfs -ls /tmp
Found 4 items
drwxrwx--- - root supergroup 02015-11-05 03:26 /tmp/hadoop-yarn
drwx-wx-wx - root supergroup 02015-11-05 07:51 /tmp/hive
-rw-r--r-- 2 root supergroup 02015-11-09 04:38 /tmp/mydata.txt
-rw-r--r-- 2 root supergroup 732015-11-09 04:34 /tmp/test.txt
[root@zwt1 data]# hdfs dfs -tail/tmp/test.txt //返回文件系统中指定文件1kb大小的内容
hello world
hello hadoop
spark scala
centos linux
hello linux
bye hadoop
[root@zwt1 data]# hdfs dfs -ls /output
Found 1 items
-rw-r--r-- 2 root supergroup 732015-11-09 04:37 /output/test.txt
[root@zwt1 data]# hdfs dfs -rm/output/test.txt //删除文件
15/11/09 04:48:06 INFOfs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0minutes, Emptier interval = 0 minutes.
Deleted /output/test.txt
[root@zwt1 data]# hdfs dfs -mv/tmp/test.txt /output/ //在hsdfs文件系统中移动文件
[root@zwt1 data]# hdfs dfs -ls /tmp
Found 3 items
drwxrwx--- - root supergroup 02015-11-05 03:26 /tmp/hadoop-yarn
drwx-wx-wx - root supergroup 02015-11-05 07:51 /tmp/hive
-rw-r--r-- 2 root supergroup 02015-11-09 04:38 /tmp/mydata.txt
[root@zwt1 data]# hdfs dfs -ls /output
Found 1 items
-rw-r--r-- 2 root supergroup 732015-11-09 04:34 /output/test.txt
[root@zwt1 data]# hdfs dfs -cat/output/test.txt //查看文本文件内容
hello world
hello hadoop
spark scala
centos linux
hello linux
bye hadoop
[root@zwt1 data]# ls
test.txt
[root@zwt1 data]# rm test.txt
rm: remove regular file `test.txt'? y
[root@zwt1 data]# ls
[root@zwt1 data]# vim data.txt
[root@zwt1 data]# hdfs dfs -text/output/data.txt //查看文本文件内容
hadoop
linux
spark
scala
hive
hbase
zookeeper
sqoop
[root@zwt1 data]# hdfs dfs -moveFromLocaldata.txt /output //从本地剪切到hdfs文件系统中
[root@zwt1 data]# hdfs dfs -ls /output
Found 2 items
-rw-r--r-- 2 root supergroup 52 2015-11-09 04:53 /output/data.txt
-rw-r--r-- 2 root supergroup 732015-11-09 04:34 /output/test.txt
[root@zwt1 data]#