Linux多个FIND语句和IF条件/ / bash

时间:2017-11-07 09:29:06

标签: linux bash

我正在尝试编写一个脚本来检查是否在任何位置上没有名称中有参数的特定文件,并且在声明为真(没有这样的文件)之后,函数应该创建同名的目录。参数$ 1,将文件从符号链接当前移动到新创建的目录,然后查找并删除不在/ current /中的所有文件,并包含名称@tp或数字。我写过这样的东西,但不知道为什么,它不起作用,我可以得到任何帮助吗? :)

   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

1 个答案:

答案 0 :(得分:0)

如果要检查不存在的目录,可以使用:

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