【问题标题】:Script that takes a search string, searches for folders containing the string and moves them to a folder with the same name as the string接受搜索字符串的脚本,搜索包含该字符串的文件夹并将它们移动到与该字符串同名的文件夹中
【发布时间】:2014-01-30 14:56:59
【问题描述】:

基本上我想做的就是紧凑

mkdir STRING
mv 00/*[sS][tT][rR][iI][nN][gG]* STRING

到像 do-this STRING 这样的单个命令中,结果相同。该字符串可能包含一些特殊字符,如空格。

我意识到省略第一行通常会做同样的事情,但它似乎并没有始终如一地这样做。

【问题讨论】:

    标签: linux bash ubuntu command-line


    【解决方案1】:

    您可以编写一个bash 函数来做到这一点:

    function doThis {
        mkdir "$1"
        find 00 -maxdepth 1 -iname "*$1*" -exec mv {} "$1" \;
    }
    

    然后这样称呼它:

    doThis STRING
    

    【讨论】:

    • 或者-exec mv -t "$1" \+,如果你的find支持这个扩展。
    猜你喜欢
    • 2017-11-17
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多