我正在尝试编写一个脚本来检查是否在任何位置的名称中都没有具有参数的特定文件,并且在语句为真(没有这样的文件)之后,函数应该创建与以下名称相同的目录参数 $1,将文件从符号链接(symbolic link) Current 移动到新创建的目录,然后查找并删除所有不在/current/中且包含在 name @tp 或 numbers 中的文件。我写过这样的东西,但不知道为什么,它不起作用,我能得到任何帮助吗? :)
if[-ne $1]; then mkdir $1 && mv /current/* data/data2/data3/$1
find /home/ -not -path /current/ -and -not -newer /current/ -and -name *@tmp" -exec rm -r {} \; -name "*[0-9]*" -exec rm -r {} \;
else
echo "There is this tag already "
fi
最佳答案
如果你想检查不存在的目录,你可以使用这个:
if [ ! -d $1 ]
代替
if [ -ne $1 ]
更新:之前的命令只会查找匹配的文件夹名称。如果你想搜索包含你的参数的文件夹,你可以使用这样的东西:
if [[ `find -maxdepth 1 -type d -name "*${1}*"` = "" ]]; then
# ... commands when your param is not part of any dir ...
fi
关于Linux 多个 FIND 语句和 IF 条件//bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47154252/