赞
踩
$ cd /usr/local/hadoop
$ ./bin/hdfs dfs -test -e text.txt
然后输入$ echo $?检查,1表示文件不存在,0表示文件存在
$ if $(hdfs dfs -test -e text.txt);
$ then $(hdfs dfs -appendToFile local.txt text.txt);
$ else $(hdfs dfs -copyFromLocal -f local.txt text.txt);
$ fi
1.输入hadoop fs -put ./test.txt /,使用put将test.txt文件上传
2.使用如下命令操作:
$ if $(hdfs dfs -test -e file:///home/hadoop/text.txt);
$ then $(hdfs dfs -copyToLocal text.txt ./text2.txt);
$ else $(hdfs dfs -copyToLocal text.txt ./text.txt);
$ fi
1.通过上述实验将指定文件上传至HDFS,并且通过hadoop fs -ls /log1显示。
运行后显示如下,此时列出了HDFS上/log目录下所有文件,及其文件的各种信息
1.在命令行输入hadoop fs -ls -h /dir/test.txt查看文件读写权限、大小、路径等信息
在终端使用命令行查看test.txt文件,发现相同的内容已经追加至文件末尾
以上是今天要讲的内容,学到了HDFS操作。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。