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

标签 linux bash

我正在尝试编写一个脚本来检查是否在任何位置的名称中都没有具有参数的特定文件,并且在语句为真(没有这样的文件)之后,函数应该创建与以下名称相同的目录参数 $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/

相关文章:

android - Linux:keytool 显示 "Unrecognized command: -exportcert"

linux - 有没有办法找到一个特定的文件,然后一次性切换到包含它的目录?

php - 使用 WGET 运行 cronjob PHP

linux - 如何解决 "FATAL CONFIG FILE ERROR"?

regex - 如何在 bash 中执行简单的正则表达式匹配?

linux - 配置: error: cannot run/bin/sh

regex - Bash 正则表达式非贪婪匹配

linux - Mongodb 使用 debian 包中的安装后脚本创建 root 用户

bash - 错误 : Tar command not found

linux - 如何在 bash 脚本的环境变量中存储 grep 的 --exclude 参数