我的 Ubuntu (18.04) 驱动器与 Windows 驱动器同步。Ubuntu 中的某些文件夹和文件名包含 Windows 中不允许的字符,这会导致同步过程中出现问题。我想找到这些字符,然后从文件/文件夹名称中删除它们,或者用“x”替换这些字符。这需要在文件夹/目录树中递归完成。
我怎样才能快速完成此操作?
以下是 Windows 中禁止使用的字符 (修改自 Christopher Oezbek 的回答):
< (less than)
> (greater than)
: (colon - sometimes works, but is actually NTFS Alternate Data Streams)
" (double quote)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)
答案1
尝试rename
,您需要先安装它。
sudo apt-get install rename
下面是一个示例,您可以更改*
为文件/文件夹所在的位置。
~$ ls
'1<.txt' 3:.txt '5\.txt' '7??.txt'
'2>.txt' '4"d".txt' '6|.txt' '8*.txt'
~$ rename -v 's/[?<>\\:*|\"]/x/g' *
1<.txt renamed as 1x.txt
2>.txt renamed as 2x.txt
3:.txt renamed as 3x.txt
4"d".txt renamed as 4xdx.txt
5\.txt renamed as 5x.txt
6|.txt renamed as 6x.txt
7??.txt renamed as 7xx.txt
8*.txt renamed as 8x.txt
~$ ls
1x.txt 2x.txt 3x.txt 4xdx.txt '5x.txt' 6x.txt 7xx.txt 8x.txt