簡體   English   中英

搜索、重命名和 mv 目錄和子目錄中的所有文件

[英]search and rename and mv all files from directories and subdirectories

我有很多文件30k directories, 21k files在目錄和同名txt文件的子目錄中

     ├── cases__in_africa
        │   ├── 2020/10/01.txt
        │   ├── 2020/10/02.txt
        │   ├── 2020/10/03.txt
        │   └── 2020/10/04.txt
        ├── death_in_africa
        │   ├── 2020/10/01.txt
        │   ├── 2020/10/02.txt
        │   ├── 2020/10/03.txt
        │   └── 2020/10/04.txt
2926 directories, 21646 files

我想搜索很多子目錄中的所有文件,而不是將它們重命名為其他唯一名稱以將它們移動到其他目錄。

此命令不顯示重復文件

find . -name "*.txt" -exec mv  "{}" ./all \;

如果您正在尋找順序命名,您可以這樣做,假設目標目錄all存在於您的當前目錄中。:

for file in $(find ./ -type f -name "*.txt"); do ((count++)) ; mv $file ./all/${count}.txt; done

我發現這很有幫助https://askubuntu.com/questions/1003554/how-to-rename-all-jpg-files-in-all-subdirs-wich-contains-dash-in-linux

find -name '*.txt' -exec bash -c 'mv  "{}" "$RANDOM.txt"' \;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM