熟悉常用的HDFS操作

编程实现以下指定功能,并利用Hadoop提供的Shell命令完成相同任务:

  1. 在本地Linux文件系统的“/home/hadoop/”目录下创建一个文件txt,里面可以随意输入一些单词.
cd /home/hadoop

touch test.txt

          2. 在本地查看文件位置(ls)

./bin/hdfs dfs -ls

          3. 在本地显示文件内容

cat test.txt

./bin/hdfs dfs -cat test.txt

          4. 使用命令把本地文件系统中的“txt”上传到HDFS中的当前用户目录的input目录下。

 ./sbin/start-dfs.sh
 ./bin/hdfs dfs -mkdir -p /user/hadoop
 ./bin/hdfs dfs -mkdir input
 ./bin/hdfs dfs -put ./test.txt input

          5. 查看hdfs中的文件(-ls)

./bin/hdfs dfs -ls

./bin/hdfs dfs -ls input

          6. 显示hdfs中该的文件内容

./bin/hdfs dfs -cat input/test.txt

          7. 删除本地的txt文件并查看目录

cd /home/hadoop

rm test.txt

ls /home/hadoop

          8. 从hdfs中将txt下载地本地原来的位置。

./bin/hdfs dfs -get test.txt /home/hadoop

          9. 从hdfs中删除txt并查看目录

./bin/hdfs dfs -rm -ls input/test.txt

 

posted @ 2018-04-25 19:34  188吴梅英  阅读(158)  评论(0编辑  收藏  举报