使用linux脚本根据文件名模式查找和移动文件

使用linux脚本根据文件名模式查找和移动文件,linux,bash,Linux,Bash,我想将两个不同的文件名模式排序到两个不同的文件夹中 这两种文件名模式是: 名称包含:s00或e00或s00e00或s0e000或0x00-其中0= 数字[0-9] 及 名称包含有效的4位数年份 名称不包含:s00或e00或s00e00或s0e000或0x00-其中 0=数字[0-9] 这将第一组移动到文件夹1: mv *s[0-9][0-9]* *e[0-9][0-9]* *s[0-9]e[0-9][0-9][0-9]* *[0-9]x[0-9][0-9]* folder1 将这些文件移

我想将两个不同的文件名模式排序到两个不同的文件夹中

这两种文件名模式是:

  • 名称包含:s00或e00或s00e00或s0e000或0x00-其中0= 数字[0-9]

  • 名称包含有效的4位数年份
  • 名称不包含:s00或e00或s00e00或s0e000或0x00-其中 0=数字[0-9]

这将第一组移动到文件夹1:

mv *s[0-9][0-9]* *e[0-9][0-9]* *s[0-9]e[0-9][0-9][0-9]* *[0-9]x[0-9][0-9]* folder1
将这些文件移开后,这会将具有有效年份的文件移到文件夹2:

mv *19[0-9][0-9]* *20[0-9][0-9]* folder2
在这里,我假设“有效年”将在1900年到2099年之间。

多亏了约翰1024

下面是一个用于识别和分离电影和电视节目的脚本。只需确保编辑第一行末尾的/path/to/tv shows/directory,以及第二行末尾的/path/to/movies/directory即可

find "$TR_TORRENT_DIR/$TR_TORRENT_NAME" -type f -a -not -size -100M -a -not -size +2G -a -not -iname "*sample*" -a -iname "*s[0-9]*" -o -type f -a -not -size -100M -a -not -size +2G -a -not -iname "*sample*" -a -iname "*e[0-9]*" -o -type f -a -not -size -100M -a -not -size +2G -a -not -iname "*sample*" -a -iname "*s[0-9]e[0-9]*" -o -type f -a -not -size -100M -a -not -size +2G -a -not -iname "*sample*" -a -iname "*s[0-9]e[0-9][0-9][0-9]*" -o -type f -a -not -size -100M -a -not -size +2G -a -not -iname "*sample*" -a -iname "*[0-9]x[0-9][0-9]*" -exec cp {} /path/to/tv-shows/ \;

find "$TR_TORRENT_DIR/$TR_TORRENT_NAME" -type f -a -size +500M -a -not -iname "*sample*" -a -not -iname "*s[0-9]*" -a -iname "*19[0-9][0-9]*" -o -type f -a -size +500M -a -not -iname "*sample*" -a -not -iname "*e[0-9]*" -a -iname "*19[0-9][0-9]*" -o -type f -a -size +500M -a -not -iname "*sample*" -a -not -iname "*s[0-9]e[0-9]*" -a -iname "*19[0-9][0-9]*" -o -type f -a -size +500M -a -not -iname "*sample*" -a -not -iname "*s[0-9]e[0-9][0-9][0-9]*" -a -iname "*19[0-9][0-9]*" -o -type f -a -size +500M -a -not -iname "*sample*" -a -not -iname "*[0-9]x[0-9][0-9]*" -a -iname "*19[0-9][0-9]*" -o -type f -a -size +500M -a -not -iname "*sample*" -a -not -iname "*s[0-9]*" -a -iname "*20[0-9][0-9]*" -o -type f -a -size +500M -a -not -iname "*sample*" -a -not -iname "*e[0-9]*" -a -iname "*20[0-9][0-9]*" -o -type f -a -size +500M -a -not -iname "*sample*" -a -not -iname "*s[0-9]e[0-9]*" -a -iname "*20[0-9][0-9]*" -o -type f -a -size +500M -a -not -iname "*sample*" -a -not -iname "*s[0-9]e[0-9][0-9][0-9]*" -a -iname "*20[0-9][0-9]*" -o -type f -a -size +500M -a -not -iname "*sample*" -a -not -iname "*[0-9]x[0-9][0-9]*" -a -iname "*20[0-9][0-9]*" -exec cp {} /path/to/movies/ \;
然后,您可以将其添加到脚本的底部,该脚本将删除已完成种子设定的种子。您需要在这两个位置替换用户名和密码

transmission-remote --auth=username:password -l | grep Finished | \
awk '{print $1}' | xargs -n 1 -I % transmission-remote --auth=username:password -t % --remove-and-delete

听起来您想要一个shell脚本解决方案,我建议添加标记bash。@d'Nabre谢谢!完成!你还包括了10xx年和29xx年。@tripleee很好。我更新了一些更严格的答案。年度要求的规格有点松散。例如,我上面的解决方案将20141103确定为有效年份。这是否正确由OP决定。如果您的
find
支持
-exec+
,您可以将尾部更改为
-exec cp-t/path/to/copies+
,以显著提高性能。@triplee我不太熟悉您的说法。你能给我举个例子吗?请非常感谢。重复的参数可以通过使用括号进行显著重构。不经意间,
find/path/to/files-type-f-not-size-100M-not-size+2G-not-iname“sample”\(-iname“s[0-9]”-o-iname“e[0-9]”-o-iname“s[0-9]e[0-9]”-o-iname“s[0-9][0-9][0-9]”-o-iname“[0-9]x[0-9]”)
但我不确定我是否能够捕捉到您复杂表达式的所有复杂之处。
-exec thing{}
将为
find
返回的每个
arg
生成一个单独的
thing arg
。相比之下,
-exec thing+
将一次运行
thing arg1 arg2 arg3 arg4
以获得尽可能多的参数。@triplee Your Awesome!