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