【问题标题】:sh Script with copy and removing a part from filenamesh 脚本,从文件名中复制和删除部分
【发布时间】:2020-05-02 09:21:12
【问题描述】:

所以我使用一个脚本,根据那里的文件名将特​​定文件复制到特定文件夹。我想扩展脚本,以便在复制进度后删除文件名中的一部分。这是一个示例文件名看起来像这个 Image_000058_19_12_2019_1920x1080.jpg 我喜欢从中删除分辨率(_1920x1080)部分。有没有办法将它添加到我的脚本中(见下文)感谢@fedxc 的脚本。


cd "$HOME/Downloads"
# for filename in *; do
find . -type f | while IFS= read filename; do # Look for files in all ~/Download sub-dirs
  case "${filename,,*}" in  # this syntax emits the value in lowercase: ${var,,*}  (bash version 4)
     *.part) : ;; # Excludes *.part files from being moved
     move.sh) : ;;
#    *test*)            mv "$filename" "$HOME/TVshows/Glee/" ;; # Using move there is no need to {&& rm "$filename"}
     *test*)           scp "$filename" "imac@imac.local:/users/imac/Desktop/" && rm "$filename" ;;
     *american*dad*)   scp "$filename" "imac@imac.local:/users/imac/Movies/Series/American\ Dad/" && rm "$filename" ;;
     *) echo "Don't know where to put $filename" ;;
  esac
done```


【问题讨论】:

    标签: copy rename filenames


    【解决方案1】:

    我对 bash 使用变量操作。示例:

    export filename='Image_000058_19_12_2019_1920x1080.jpg' <----Setting name of filename
    echo ${filename/_1920x1080/}                            <--Operation with bash variable.
          Image_000058_19_12_2019.jpg                       <--Result of echo
    

    更多信息请访问此页面:Bash Guide

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 2017-04-08
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      • 1970-01-01
      相关资源
      最近更新 更多