简体   繁体   English

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

[英]Linux multiple FIND statements and IF condition / /bash

I'm trying to write a script that checks if there in no specific Files that has parameter in the name on any position, and after statement is true (there is no such file), function should create directory with same name as Parameter $1, move files from symlink Current to newly created directory, and after that find and remove all files that are not in /current/ and contains in name @tp or numbers. 我正在尝试编写一个脚本,以检查是否没有在任何位置的名称中都有参数的特定文件,并且在语句为true(没有此类文件)之后,函数应该创建与参数$ 1同名的目录,将文件从symlink Current移到新创建的目录,然后查找并删除所有不在/ current /中且名称为@tp或数字的文件。 I've wrote something like this, but don't know why, it's not working, can I get any help? 我已经写过这样的东西,但是不知道为什么,它不起作用,我能得到任何帮助吗? :) :)

   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 you want to check for non-existing directory, you can use this: 如果要检查不存在的目录,可以使用以下命令:

if [ ! -d $1 ] 

instead of 代替

if [ -ne $1 ] 

Update : the previous command will only look for matching folder name. 更新 :前面的命令将仅查找匹配的文件夹名称。 If you want to search for folders containing your parameter, you could use something like this: 如果要搜索包含参数的文件夹,则可以使用如下所示的内容:

if [[ `find -maxdepth 1 -type d -name "*${1}*"` = "" ]]; then
       # ... commands when your param is not part of any dir ...
fi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM