标签:append 相关 系统 test file hadoop oop 原来 rmdir
一、Hadoop提供的Shell命令完成相同任务:
cd /usr/local/hadoop touch hello.txt cat hello.txt
./sbin/start-dfs.sh ./bin/hdfs dfs -mkdir -p /user/hadoop ./bin/hdfs dfs -mkdir input ./bin/hdfs dfs -put ./hello.txt input
./bin/hdfs dfs -ls /input
./bin/hdfs dfs -cat input/hello.txt
./bin/hdfs dfs -rm -ls input/hello.txt
./bin/hdfs dfs -get input/test.txt ~/hello.txt
。
./bin/hdfs dfs -rm -ls input/hello.txt
二、
if $(hdfs dfs -test -e hello.txt); then $(hdfs dfs -appendToFile local.txt hello.txt); else $(hdfs dfs -copyFromLocal -f local.txt hello.txt); fi
if $(hdfs dfs -test -e file: then $(hdfs dfs -copyToLocal hello.txt ./hello2.txt); else $(hdfs dfs -copyToLocal hello.txt ./hello.txt); fi
hdfs dfs -cat hello.txt
hdfs dfs -ls -h hello.txt
hdfs dfs -ls -R -h /user/hadoop
if $(hdfs dfs -hello -d dir1/dir2); then $(hdfs dfs -touchz dir1/dir2/filename); else $(hdfs dfs -mkdir -p dir1/dir2 && hdfs dfs -touchz dir1/dir2/filename); fi
if $(hdfs dfs -hello -d dir1/dir2); then $(hdfs dfs -touchz dir1/dir2/filename); else $(hdfs dfs -mkdir -p dir1/dir2); fi if$(hdfs dfs -rmdir dir1/dir2); then $(hdfs dfs -rmdir dir1/dir2) fi
追加到文件末尾:hdfs dfs -appendToFile local.txt hello.txt 追加到文件开头: (由于没有直接的命令可以操作,方法之一是先移动到本地进行操作,再进行上传覆盖): hdfs dfs -get hello.txt cat text.txt >> local.txt hdfs dfs -copyFromLocal -f hello.txt hello.txt
hdfs dfs -rm hello.txt
删除目录(如果目录非空则会提示not empty,不执行删除):hdfs dfs -rmdir dir1/dir2
强制删除目录:hdfs dfs -rm -R dir1/dir2
hdfs dfs -mv hello.txt hello2.txt
标签:append 相关 系统 test file hadoop oop 原来 rmdir
原文地址:https://www.cnblogs.com/1940370572QQ/p/8964168.html