赞
踩
注意: WARN hdfs.DFSClient: DFSInputStream has been closed already 忽略这个问题就行
cd /usr/local/hadoop
./sbin/start-dfs.sh #启动hadoop
./bin/hdfs dfs -test -e text.txt
echo $?
touch local.txt
./bin/hdfs dfs -appendToFile local.txt text.txt
注意:
检查文件是否存在: hdfs dfs -test -e text.txt
(执行完这一句不会输出结果,需要继续输入命令 " echo $? ")
追加命令: ./bin/hdfs dfs -appendToFile local.txt text.txt
覆盖命令1: ./bin/hdfs dfs -copyFromLocal -f local.txt text.txt
覆盖命令2: ./bin/hdfs dfs -cp -f file:///home/hadoop/local.txt text.txt
也可以使用如下命令实现:
(如下代码可视为一行代码,在终端中输入第一行代码后,直到输入 fi 才会真正执行):
if $(./bin/hdfs dfs -test -e text.txt);
then $(./bin/hdfs dfs -appendToFile local.txt text.txt);
else $(./bin/hdfs dfs -copyFromLocal -f local.txt text.txt);
fi
if $(./bin/hdfs dfs -test -e file:///home/hadoop/text.txt);
then $(./bin/hdfs dfs -copyToLocal text.txt ./text2.txt);
else $(./bin/hdfs dfs -copyToLocal text.txt ./text.txt);
fi
./bin/hdfs dfs -cat text.txt
./bin/hdfs dfs -ls -h text.txt
./bin/hdfs dfs -ls -R -h /user/hadoop
if $(./bin/hdfs dfs -test -d dir1/dir2);
then $(./bin/hdfs dfs -touchz dir1/dir2/filename);
else $(./bin/hdfs dfs -mkdir -p dir1/dir2 && ./bin/hdfs dfs -touchz dir1/dir2/filename);
fi
创建目录:./bin/hdfs dfs -mkdir -p dir1/dir2
删除目录:./bin/hdfs dfs -rmdir dir1/dir2
(如果目录非空则会提示not empty,不执行删除)
强制删除目录:./bin/hdfs dfs -rm -R dir1/dir2
`追加到文件末尾`
./bin/hdfs dfs -appendToFile local.txt text.txt
`追加到文件开头: (由于没有直接的命令可以操作,方法之一是先移动到本地进行操作,再进行上传覆盖)`
./bin/hdfs dfs -get text.txt
cat text.txt >> local.txt
./bin/hdfs dfs -copyFromLocal -f text.txt text.txt
./bin/hdfs dfs -rm text.txt
`删除目录(如果目录非空则会提示not empty,不执行删除):`
./bin/hdfs dfs -rmdir dir1/dir2
`强制删除目录:`
./bin/hdfs dfs -rm -R dir1/dir2
./bin/hdfs dfs -mv text.txt text2.txt
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。