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

时间:2023-01-18 07:44:05

I would like to sort two different file name patterns into two different folders.

我想将两个不同的文件名模式分成两个不同的文件夹。

The two file name patterns are:

两个文件名模式是:

  • name contains: s00 or e00 or s00e00 or s0e000 or 0x00 - where 0 = digits [0-9]
  • name包含:s00或e00或s00e00或s0e000或0x00 - 其中0 =数字[0-9]

and

  • name contains a valid 4 digit year
  • name包含有效的4位数年份

  • name does not contain: s00 or e00 or s00e00 or s0e000 or 0x00 - where 0 = digits [0-9]
  • name不包含:s00或e00或s00e00或s0e000或0x00 - 其中0 =数字[0-9]

2 个解决方案

#1


1  

This will move the first group to folder1:

这会将第一个组移动到folder1:

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

With those files out of the way, this will move the ones with something that looks like a valid year to folder2:

有了这些文件,这将把那些看起来像有效年份的文件移到folder2:

mv *19[0-9][0-9]* *20[0-9][0-9]* folder2

Here, I assumed that a "valid year" was going to be between 1900 and 2099.

在这里,我假设“有效年份”将在1900年到2099年之间。

#2


0  

Thanks to John1024.

感谢John1024。

Here is a script for recognizing and separating movies & tv shows. Just make sure to edit /path/to/tv-shows/ directory at the end of the first line, and also /path/to/movies/ directory at the end of the second line.

这是一个用于识别和分离电影和电视节目的脚本。只需确保在第一行末尾编辑/ path / to / tv-shows /目录,并在第二行末尾编辑/ path / to / movies /目录。

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/ \;

Then you can add this to the bottom of the script which removes and deletes torrents that have finished seeding. You will need to replace username and password in both spots.

然后,您可以将其添加到脚本的底部,以删除和删除已完成种子设定的种子。您需要在两个位置替换用户名和密码。

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

#1


1  

This will move the first group to folder1:

这会将第一个组移动到folder1:

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

With those files out of the way, this will move the ones with something that looks like a valid year to folder2:

有了这些文件,这将把那些看起来像有效年份的文件移到folder2:

mv *19[0-9][0-9]* *20[0-9][0-9]* folder2

Here, I assumed that a "valid year" was going to be between 1900 and 2099.

在这里,我假设“有效年份”将在1900年到2099年之间。

#2


0  

Thanks to John1024.

感谢John1024。

Here is a script for recognizing and separating movies & tv shows. Just make sure to edit /path/to/tv-shows/ directory at the end of the first line, and also /path/to/movies/ directory at the end of the second line.

这是一个用于识别和分离电影和电视节目的脚本。只需确保在第一行末尾编辑/ path / to / tv-shows /目录,并在第二行末尾编辑/ path / to / movies /目录。

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/ \;

Then you can add this to the bottom of the script which removes and deletes torrents that have finished seeding. You will need to replace username and password in both spots.

然后,您可以将其添加到脚本的底部,以删除和删除已完成种子设定的种子。您需要在两个位置替换用户名和密码。

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