[英]Add a file in a folder with bash
I have figured out how to remove bad files in my folders but I am wanting to know how to add certain named files to that folder. 我已经想出如何删除文件夹中的坏文件,但我想知道如何将某些命名文件添加到该文件夹。
I want to add something like address.xml 我想添加像address.xml这样的东西
I have this and can remove the bad files. 我有这个,可以删除坏文件。
for addxml in $(find $DIRECTORY/$directoryname -name address.xml); do
rm -v $addxml
done
I am trying to learn how later down the code I can add a file from another folder no where near the folders that are being edited. 我正在尝试学习以后如何在代码中添加一个文件来自另一个文件夹,而不是在正在编辑的文件夹附近。
vim address.xml ...? vim address.xml ......?
:wq :WQ
Are you creating a bash scrip to make files or you are in a command prompt and need to make a file? 您是在创建bash脚本来制作文件还是在命令提示符下并且需要创建文件?
how later down the code I can add a file from another folder
以后我可以在另一个文件夹中添加文件
OTHER_DIRECTORY=/home/CuriousGeorge/some/other/directory
for addxml in $(find $DIRECTORY/$directoryname -name address.xml); do
mv $addxml $OTHER_DIRECTORY
done
the question and the script does not match in the sense the script is looking for an existing file and the request states how to put a file (ie non existant file in to the location) 问题和脚本在脚本查找现有文件的意义上不匹配,请求说明如何放置文件(即不存在的文件到该位置)
#!/bin/sh
FILECONTENT="something";
FILECONTENT=$FILECONTENT"something2";
for addxml in $(find . -name address.xml); do
if [ $? = 0 ]; then
echo found
echo rm -v $addxml
else
echo "putting content in $addxml"
echo $FILECONTENT > $addxml
fi
done
# OR CHANGE IT TO
#FILECONTENT="/tmp/filecontent"
#cat $FILECONTENT > $addxml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.