[英]Regex to rename all files recursively removing everything after the character “?” commandline
[英]How to rename all files in a folder removing everything after space character in linux?
你好,我不能很好地使用正常的表達式,這是我在互聯網上搜索的一整天。 我有一個包含許多圖片的文件夾:
我正在使用Mac OS X,但我也可以嘗試使用Ubuntu,我想為bash創建一個腳本,在第一個空格之后刪除所有字符,以獲得這樣的解決方案:
對於文件夾中的所有文件。 任何幫助表示贊賞。 問候
使用純BASH:
f='50912000 Bicchiere.jpg'
mv "$f" "${f/ *./.}"
或者使用find
修復所有文件:
find . -type f -name "* *" -exec bash -c 'f="$1"; s="${f/_ / }"; mv -- "$f" "${s/ *./.}"' _ '{}' \;
使用sed,
sed 's/ .*\./\./g'
注意之前的空間.*
您可以使用find和小腳本的組合。
prompt> find . -name "* *" -exec move_it {} \;
mv "./50912000 Bicchiere.jpg" ./50912000
mv "./50913714 Sottobottiglia Bernini.jpg" ./50913714
prompt> cat move_it
#!/bin/sh
dst=`echo $1 | cut -c 1-10`
# remove the echo in the line below to actually rename the file
echo mv '"'$1'"' $dst
rename 's/.*\s+//' *files
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.