复制 hadoop 目录中除 1 以外的所有文件
Copy all files in hadoop directory except 1
我正在编写一个 shell 脚本来将我所有的文件放在 hadoop 目录中。
我使用了命令:
hadoop dfs -put /opt/nikoo28/resources/conf ./
现在这会复制我的 hadoop 主目录中的文件夹 conf 并覆盖所有内容。
但是,有一个文件,"doNotCopy.txt",我不想复制。有什么方法可以跳过特定文件吗?
在您的 shell 脚本中添加这些行:
mkdir /opt/copy
mv /opt/nikoo28/doNotCopy.txt /opt/copy/doNotCopy.txt
hadoop dfs -put /opt/nikoo28/resources/conf ./ && mv /opt/copy/doNotCopy.txt /opt/nikoo28/doNotCopy.txt
只需将您不想复制的文件移动到其他文件夹即可。执行 hadoop fs -put 命令。现在,将文件移回原来的位置。
如果要保留文件权限,请执行以下操作:
mkdir /opt/copy
cp -p /opt/nikoo28/doNotCopy.txt /opt/copy/doNotCopy.txt
rm /opt/nikoo28/doNotCopy.txt
hadoop dfs -put /opt/nikoo28/resources/conf ./ && cp -p /opt/copy/doNotCopy.txt /opt/nikoo28/doNotCopy.txt
NOTE: Add sudo if you get permission errors while creating directory, moving the file or copying the file.
我在 Apache Hadoop docs #put 中看到:
Usage: hadoop fs -put ...
Copy single src, or multiple srcs from local file system to the
destination file system. Also reads input from stdin and writes to
destination file system.
然后是一个有用的例子
hadoop fs -put - hdfs://nn.example.com/hadoop/hadoopfile Reads the
input from stdin.
所以也许您可以使用 find
表达式将此文件 grep 出来,然后通过管道传输到 hadoop
:
find /opt/nikoo28/resources/conf ! -name "doNotCopy.txt" | hadoop dfs -put - ./
这有点奇怪,但应该可行:
file=./conf/doNotCopy.txt
[[ -f $file ]] && mv $file $file.old
hadoop dfs -put /opt/nikoo28/resources/conf ./
rm $file
[[ -f $file ]] && mv $file.old $file
我正在编写一个 shell 脚本来将我所有的文件放在 hadoop 目录中。
我使用了命令:
hadoop dfs -put /opt/nikoo28/resources/conf ./
现在这会复制我的 hadoop 主目录中的文件夹 conf 并覆盖所有内容。
但是,有一个文件,"doNotCopy.txt",我不想复制。有什么方法可以跳过特定文件吗?
在您的 shell 脚本中添加这些行:
mkdir /opt/copy
mv /opt/nikoo28/doNotCopy.txt /opt/copy/doNotCopy.txt
hadoop dfs -put /opt/nikoo28/resources/conf ./ && mv /opt/copy/doNotCopy.txt /opt/nikoo28/doNotCopy.txt
只需将您不想复制的文件移动到其他文件夹即可。执行 hadoop fs -put 命令。现在,将文件移回原来的位置。
如果要保留文件权限,请执行以下操作:
mkdir /opt/copy
cp -p /opt/nikoo28/doNotCopy.txt /opt/copy/doNotCopy.txt
rm /opt/nikoo28/doNotCopy.txt
hadoop dfs -put /opt/nikoo28/resources/conf ./ && cp -p /opt/copy/doNotCopy.txt /opt/nikoo28/doNotCopy.txt
NOTE: Add sudo if you get permission errors while creating directory, moving the file or copying the file.
我在 Apache Hadoop docs #put 中看到:
Usage: hadoop fs -put ...
Copy single src, or multiple srcs from local file system to the destination file system. Also reads input from stdin and writes to destination file system.
然后是一个有用的例子
hadoop fs -put - hdfs://nn.example.com/hadoop/hadoopfile Reads the input from stdin.
所以也许您可以使用 find
表达式将此文件 grep 出来,然后通过管道传输到 hadoop
:
find /opt/nikoo28/resources/conf ! -name "doNotCopy.txt" | hadoop dfs -put - ./
这有点奇怪,但应该可行:
file=./conf/doNotCopy.txt
[[ -f $file ]] && mv $file $file.old
hadoop dfs -put /opt/nikoo28/resources/conf ./
rm $file
[[ -f $file ]] && mv $file.old $file