在Ubuntu系統中跳過帶有非法字符的文件移動

[英]Skip moving of files with illegal characters in Ubuntu system


I'm moving some files in the Ubuntu system, which is currently moving all files with or without extension in a folder

我正在移動Ubuntu系統中的一些文件,這些文件當前正在移動文件夾中有或沒有擴展名的所有文件

Following is the command i'm using :

以下是我正在使用的命令:

find /abc/xyz -maxdepth 1 -type f -exec mv {} /mno/pqr

But now I want to move files only after applying some filter :

但現在我想在應用一些過濾器后才移動文件:

  • If file contains an "_" (underscore), I would like to skip that file movement.
  • 如果文件包含“_”(下划線),我想跳過該文件移動。
  • I would like to have a parameter flag, which when 0 or 1, would enable to overrite files with same name at the destination.
  • 我想有一個參數標志,當0或1時,它將允許在目的地覆蓋具有相同名稱的文件。

Can somebody please help me out ?

有人可以幫幫我嗎?

1 个解决方案

#1


1  

  1. If file contains an "_" (underscore), I would like to skip that file movement.

    如果文件包含“_”(下划線),我想跳過該文件移動。

    You could try this

    你可以試試這個

    find /abc/xyz -maxdepth 1 -type f ! -name '*_*' -exec mv {} /mno/pqr
    

    ! -name '*_*' will skip all files which have a '_' in their names. If you have more than one illegal characters to check, you could add one test (such as ! -name '*_*') for each of these characters.

    ! -name'* _ *'將跳過名稱中包含'_'的所有文件。如果要檢查多個非法字符,可以為每個字符添加一個測試(例如!-name'* _ *')。

  2. I would like to have a parameter flag, which when 0 or 1, would enable to overrite files with same name at the destination.

    我想有一個參數標志,當0或1時,它將允許在目的地覆蓋具有相同名稱的文件。

    • mv -n do not overwrite an existing file
    • mv -n不會覆蓋現有文件
    • mv -f do not prompt before overwriting
    • mv -f在覆蓋之前不提示

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/03/03/72a27c44443e35c503539f6526010228.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com