如何根据特定字符长度范围移动文件?

时间:2014-11-11 19:54:45

标签: regex linux mv

我在目录中有以下文件:

f.txt
fi.txt
fil.txt
file.txt
filen.txt
filena.txt
filenam.txt
filename.txt
filenametoolong.txt

除了最后一个,我想移动所有。以下正则表达式适用于我的需求:^。{1,13} .txt

但是,使用带有“mv”的正则表达式

mv ^.{1,13}\.txt trashdir

结果

mv: cannot stat `^.1.txt': No such file or directory
mv: cannot stat `^.24.txt': No such file or directory

我检查并仔细检查了正则表达式语法,它似乎是有效的。我错过了什么?

1 个答案:

答案 0 :(得分:2)

mv命令不支持正则表达式。您可以将find-regex选项一起使用:

find . -maxdepth 1 -type f -regex '\./.\{1,13\}' -exec mv {} /trashdir +