hdfs dfs
- -cat URI : 查看文件内容
-
- hdfs dfs -cat hdfs dfs -cat hdfs://mycluster/user/root/rcc1
- hdfs dfs -cat file:///usr/hdp/2.4.2.0-258/hadoop/bin/rcc
- -ls <args>: 查文件列表
- 返回格式:permissions number_of_replicas userid groupid filesize modification_date modification_time filename
[[email protected] ~]# hdfs dfs -ls Found 4 items drwx------ - root hdfs 0 2016-09-01 21:00 .Trash drwxr-xr-x - root hdfs 0 2016-08-12 12:29 .hiveJars -rw-r--r-- 3 root hdfs 531 2016-09-01 12:53 mapred -rw-r--r-- 3 root hdfs 1857 2016-09-01 12:44 rcc1
- -mkdir <paths> : 创建目录
- The behavior is much like unix mkdir -p creating parent directories along the path
[[email protected] ~]# hdfs dfs -ls Found 4 items drwx------ - root hdfs 0 2016-09-01 21:00 .Trash drwxr-xr-x - root hdfs 0 2016-08-12 12:29 .hiveJars -rw-r--r-- 3 root hdfs 531 2016-09-01 12:53 mapred -rw-r--r-- 3 root hdfs 1857 2016-09-01 12:44 rcc1 [[email protected] ~]# hdfs dfs -mkdir hdfs://mycluster/user/root/zhu [[email protected] ~]# hdfs dfs -ls Found 5 items drwx------ - root hdfs 0 2016-09-01 21:00 .Trash drwxr-xr-x - root hdfs 0 2016-08-12 12:29 .hiveJars -rw-r--r-- 3 root hdfs 531 2016-09-01 12:53 mapred -rw-r--r-- 3 root hdfs 1857 2016-09-01 12:44 rcc1 drwxr-xr-x - root hdfs 0 2016-09-02 04:35 zhu
- -copyFromLocal <localsrc> URI: 上传文件,类似于put
- -put <localsrc> ... <dst>
[[email protected] ~]# hdfs dfs -ls /user/root/zhu [[email protected] ~]# hdfs dfs -put /usr/zhu/a1.png /user/root/zhu [[email protected] ~]# hdfs dfs -copyFormLocal /usr/zhu/a2.png /user/root/zhu -copyFormLocal: Unknown command [[email protected] ~]# hdfs dfs -copyFromLocal /usr/zhu/a2.png /user/root/zhu [[email protected] ~]# hdfs dfs -ls /user/root/zhu Found 2 items -rw-r--r-- 3 root hdfs 86908 2016-09-02 04:48 /user/root/zhu/a1.png -rw-r--r-- 3 root hdfs 55823 2016-09-02 04:49 /user/root/zhu/a2.png [[email protected] ~]#
- -copyToLocal [-ignorecrc] [-crc] URI <localdst> : 下载到本地
- -get [-ignorecrc] [-crc] <src> <localdst>
[[email protected] ~]# clear [[email protected] ~]# hdfs dfs -ls /user/root/zhu Found 2 items -rw-r--r-- 3 root hdfs 86908 2016-09-02 04:48 /user/root/zhu/a1.png -rw-r--r-- 3 root hdfs 55823 2016-09-02 04:49 /user/root/zhu/a2.png [[email protected] ~]# hdfs dfs -copyToLocal hdfs://mycluster/user/root/zhu/a1.png /usr/zhu/tmp [[email protected] ~]# hdfs dfs -get /usr/root/zhu/a2.png /usr/zhu/tmp get: `/usr/root/zhu/a2.png‘: No such file or directory [[email protected] ~]# hdfs dfs -get /user/root/zhu/a2.png /usr/zhu/tmp [[email protected] ~]# cd /usr/zhu/tmp [[email protected] tmp]# ll total 144 -rw-r--r-- 1 root root 86908 Sep 2 04:54 a1.png -rw-r--r-- 1 root root 55823 Sep 2 04:55 a2.png [[email protected] tmp]#
- -count [-q] <paths> :统计
- The output columns with -count are: DIR_COUNT, FILE_COUNT, CONTENT_SIZE FILE_NAME
- The output columns with -q are: QUOTA, REMAINING_QUATA, SPACE_QUOTA, REMAINING_SPACE_QUOTA
[[email protected] tmp]# hdfs dfs -count /user/root/zhu 1 2 142731 /user/root/zhu [[email protected] tmp]# hdfs dfs -count -q /user/root/zhu none inf none inf 1 2 142731 /user/root/zhu [[email protected] tmp]#
- -du [-s] [-h] URI [URI …]: 统计大小
- The -s option will result in an aggregate summary of file lengths being displayed, rather than the individual file
- The -h option will format file sizes in a "human-readable" fashion (e.g 64.0m instead of 67108864)
[[email protected] tmp]# hdfs dfs -du -h /user/root/zhu 84.9 K /user/root/zhu/a1.png 54.5 K /user/root/zhu/a2.png [[email protected] tmp]#
- -rm -r [-skipTrash] URI [URI …]
- -r: Recursive version of delete
[[email protected] tmp]# hdfs dfs -ls /user/root/zhu Found 1 items -rw-r--r-- 3 root hdfs 86908 2016-09-02 05:03 /user/root/zhu/a1.png [[email protected] tmp]# hdfs dfs -rm -r /user/root/zhu 16/09/02 05:04:29 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 360 minutes, Emptier interval = 0 minutes. Moved: ‘hdfs://mycluster/user/root/zhu‘ to trash at: hdfs://mycluster/user/root/.Trash/Current [[email protected] tmp]# hdfs dfs -ls /user/root/zhu ls: `/user/root/zhu‘: No such file or directory [[email protected] tmp]#
- -touchz URI [URI …]
- Create a file of zero length
[[email protected] tmp]# hdfs dfs -ls Found 4 items drwx------ - root hdfs 0 2016-09-02 05:02 .Trash drwxr-xr-x - root hdfs 0 2016-08-12 12:29 .hiveJars -rw-r--r-- 3 root hdfs 531 2016-09-01 12:53 mapred -rw-r--r-- 3 root hdfs 1857 2016-09-01 12:44 rcc1 [[email protected] tmp]# hdfs dfs -touchz a.txt [[email protected] tmp]# hdfs dfs -ls Found 5 items drwx------ - root hdfs 0 2016-09-02 05:02 .Trash drwxr-xr-x - root hdfs 0 2016-08-12 12:29 .hiveJars -rw-r--r-- 3 root hdfs 0 2016-09-02 05:08 a.txt -rw-r--r-- 3 root hdfs 531 2016-09-01 12:53 mapred -rw-r--r-- 3 root hdfs 1857 2016-09-01 12:44 rcc1 [[email protected] tmp]# hdfs dfs -cat /user/root/a.txt [[email protected] tmp]#
时间: 2024-10-11 11:42:05