目的:
学会HDFS CLI 常用操作
环境:
Hadoop 2.6.4 伪分布式版
环境搭建参考本博客前篇文章:
帮助:
hadoop@ssmaster:~$ hadoop fs Usage: hadoop fs [generic options] [-appendToFile <localsrc> ... <dst>] [-cat [-ignoreCrc] <src> ...] [-checksum <src> ...] [-chgrp [-R] GROUP PATH...] [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...] [-chown [-R] [OWNER][:[GROUP]] PATH...] [-copyFromLocal [-f] [-p] [-l] <localsrc> ... <dst>] [-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] [-count [-q] [-h] <path> ...] [-cp [-f] [-p | -p[topax]] <src> ... <dst>] [-createSnapshot <snapshotDir> [<snapshotName>]] [-deleteSnapshot <snapshotDir> <snapshotName>] [-df [-h] [<path> ...]]
.........
.........
任务:
1 创建目录
hadoop@ssmaster:~$ hadoop fs -mkdir data hadoop@ssmaster:~$ hadoop fs -ls / Found 1 items drwxr-xr-x - hadoop supergroup 0 2016-10-22 22:33 /data
2 Linux 本地准备文件,内容任意英文
hadoop@ssmaster:~$ vi paper.txt hadoop@ssmaster:~$ ls Desktop Documents Downloads examples.desktop hadoop-2.6.4.tar.gz Music paper.txt Pictures Public Templates Videos hadoop@ssmaster:~$ more paper.txt
There are moments in life when you miss someone so much that you just want to pick them from your dreams and hug them for real! Dream
what you want to dream;go where you want to go;be what you want to be,because you have only one life and one chance to do all the th
ings you want to do
.....
3 上传文件 Linux 本地到 HDFS
hadoop@ssmaster:~$ hadoop fs -put paper.txt /data DEPRECATED: Use of this script to execute hdfs command is deprecated. Instead use the hdfs command for it. hadoop@ssmaster:~$ hadoop fs -ls /data Found 1 items -rw-r--r-- 1 hadoop supergroup 1762 2016-10-22 22:44 /data/paper.txt
4 查看HDFS 文件内容
hadoop@ssmaster:~$ hadoop fs -cat /data/paper.txt There are moments in life when you miss someone so much that you just want to pick them from your dreams and hug them for real! Dream what you want to dream;go where you want to go;be what you want to be,because you have only one life and one chance to do all the things you want to do.
5 下载到linux本地
hadoop@ssmaster:~$ rm paper.txt hadoop@ssmaster:~$ ls Desktop Documents Downloads examples.desktop hadoop-2.6.4.tar.gz Music Pictures Public Templates Videos hadoop@ssmaster:~$ hadoop fs -get /data/paper.txt hadoop@ssmaster:~$ ls Desktop Documents Downloads examples.desktop hadoop-2.6.4.tar.gz Music paper.txt Pictures Public Templates Videos
6 删除HDFS 文件
hadoop@ssmaster:~$ hadoop fs -rm /data/paper.txt 16/10/22 22:47:28 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0 minutes, Emptier interval = 0 minutes. Deleted /data/paper.tx
7 删除目录
hadoop@ssmaster:~$ hadoop fs -ls / Found 4 items drwxr-xr-x - hadoop supergroup 0 2016-10-22 22:48 /data drwxr-xr-x - hadoop supergroup 0 2016-10-23 00:01 /input drwxr-xr-x - hadoop supergroup 0 2016-10-23 00:08 /output drwx------ - hadoop supergroup 0 2016-10-23 00:05 /tmp hadoop@ssmaster:~$ hadoop fs -rm -r /input 16/10/23 00:37:03 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0 minutes, Emptier interval = 0 minutes. Deleted /input hadoop@ssmaster:~$ hadoop fs -ls / Found 3 items drwxr-xr-x - hadoop supergroup 0 2016-10-22 22:48 /data drwxr-xr-x - hadoop supergroup 0 2016-10-23 00:08 /output drwx------ - hadoop supergroup 0 2016-10-23 00:05 /tmp