[b0002] Hadoop HDFS cmd常用命令练手

目的:

学会HDFS CLI 常用操作

环境:

Hadoop 2.6.4 伪分布式版

环境搭建参考本博客前篇文章:

伪分布式 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 items
drwxr-xr-x - hadoop supergroup -- : /data

2  Linux 本地准备文件,内容任意英文

hadoop@ssmaster:~$ vi paper.txt
hadoop@ssmaster:~$ ls
Desktop Documents Downloads examples.desktop hadoop-2.6..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 items
-rw-r--r-- hadoop supergroup -- : /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..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..tar.gz Music paper.txt Pictures Public Templates Videos

6  删除HDFS 文件

hadoop@ssmaster:~$ hadoop fs -rm /data/paper.txt
// :: INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = minutes, Emptier interval = minutes.
Deleted /data/paper.tx

7 删除目录

hadoop@ssmaster:~$ hadoop fs -ls /
Found items
drwxr-xr-x - hadoop supergroup -- : /data
drwxr-xr-x - hadoop supergroup -- : /input
drwxr-xr-x - hadoop supergroup -- : /output
drwx------ - hadoop supergroup -- : /tmp hadoop@ssmaster:~$ hadoop fs -rm -r /input
// :: INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = minutes, Emptier interval = minutes.
Deleted /input
hadoop@ssmaster:~$ hadoop fs -ls /
Found items
drwxr-xr-x - hadoop supergroup -- : /data
drwxr-xr-x - hadoop supergroup -- : /output
drwx------ - hadoop supergroup -- : /tmp
上一篇:windows下MySQL 忘记初始密码


下一篇:APK签名说明