0

So I have a digital copy of this anime series whose filenames are in Japanese. The original files need to keep the same name, but I needed the names in a different format so I decided to symlink them. Rather than go through the trouble of manually symlinking each one, I decided to just do a for loop to make my links.

The directory has many files in it that I'm not trying to hit with my loop, so I run through a few tests until I get a loop that returns just the files in the directory that I want to work with:

[user@zodiac [Yurichan] Shigofumi]$ for i in *{01..13}*1920x1080*chi*mkv;do ll "$i";done
-rw-rw-r--. 1 user group 1209545287 Oct 19  2016 '[アニメ BD] シゴフミ 第01話「コクハク」(1920x1080 AVC 10bit FLACx4 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1205850517 Oct 19  2016 '[アニメ BD] シゴフミ 第02話「ロケット」(1920x1080 AVC 10bit FLACx4 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 973957827 Oct 19  2016 '[アニメ BD] シゴフミ 第03話「トモダチ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1057721148 Oct 19  2016 '[アニメ BD] シゴフミ 第04話「ナミダ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1024831965 Oct 19  2016 '[アニメ BD] シゴフミ 第05話「タダイマ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 976803502 Oct 19  2016 '[アニメ BD] シゴフミ 第06話「サケビ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1018146704 Oct 19  2016 '[アニメ BD] シゴフミ 第07話「キラメキ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1503810507 Oct 19  2016 '[アニメ BD] シゴフミ 第08話「ハジマリ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1100451426 Oct 19  2016 '[アニメ BD] シゴフミ 第09話「サイカイ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1234181825 Oct 19  2016 '[アニメ BD] シゴフミ 第10話「デアイ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1136201000 Oct 19  2016 '[アニメ BD] シゴフミ 第11話「メザメ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1092508733 Oct 19  2016 '[アニメ BD] シゴフミ 第12話「シゴフミ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1218814179 Oct 19  2016 '[アニメ BD] シゴフミ 第13話(終)「ソレカラ」(1920x1080 AVC 10bit FLACx4 softSub(chi+eng) chap).mkv'

All the files I don't care about are excluded from this list, so I'm good to write my link loop now. I run the following, and get the displayed output:

[user@zodiac [Yurichan] Shigofumi]$ for i in {01..13};do ln -s /path/to/directory/\[Yurichan\]\ Shigofumi/*$i*chi*eng*mkv /path/to/directory/\[Yurichan\]\ Shigofumi/Shigofumi_s01e$i.mkv;done
ln: target '/path/to/directory/[Yurichan] Shigofumi/Shigofumi_s01e08.mkv' is not a directory
ln: target '/path/to/directory/[Yurichan] Shigofumi/Shigofumi_s01e10.mkv' is not a directory

I then check the contents of my directory (I've cropped out all the irrelevant files for this example):

[user@zodiac [Yurichan] Shigofumi]$ ll
lrwxrwxrwx. 1 user      user        150 Dec 25 14:19  Shigofumi_s01e01.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第01話「コクハク」(1920x1080 AVC 10bit FLACx4 softSub(chi+eng) chap).mkv'
lrwxrwxrwx. 1 user      user        150 Dec 25 14:19  Shigofumi_s01e02.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第02話「ロケット」(1920x1080 AVC 10bit FLACx4 softSub(chi+eng) chap).mkv'
lrwxrwxrwx. 1 user      user        150 Dec 25 14:19  Shigofumi_s01e03.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第03話「トモダチ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
lrwxrwxrwx. 1 user      user        147 Dec 25 14:19  Shigofumi_s01e04.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第04話「ナミダ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
lrwxrwxrwx. 1 user      user        150 Dec 25 14:19  Shigofumi_s01e05.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第05話「タダイマ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
lrwxrwxrwx. 1 user      user        147 Dec 25 14:19  Shigofumi_s01e06.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第06話「サケビ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
lrwxrwxrwx. 1 user      user        150 Dec 25 14:19  Shigofumi_s01e07.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第07話「キラメキ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
lrwxrwxrwx. 1 user      user        150 Dec 25 14:19  Shigofumi_s01e09.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第09話「サイカイ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
lrwxrwxrwx. 1 user      user        147 Dec 25 14:19  Shigofumi_s01e11.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第11話「メザメ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
lrwxrwxrwx. 1 user      user        150 Dec 25 14:19  Shigofumi_s01e12.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第12話「シゴフミ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
lrwxrwxrwx. 1 user      user        155 Dec 25 14:19  Shigofumi_s01e13.mkv -> '/path/to/directory/[Yurichan] Shigofumi/[アニメ BD] シゴフミ 第13話(終)「ソレカラ」(1920x1080 AVC 10bit FLACx4 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1209545287 Oct 19  2016 '[アニメ BD] シゴフミ 第01話「コクハク」(1920x1080 AVC 10bit FLACx4 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1205850517 Oct 19  2016 '[アニメ BD] シゴフミ 第02話「ロケット」(1920x1080 AVC 10bit FLACx4 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group  973957827 Oct 19  2016 '[アニメ BD] シゴフミ 第03話「トモダチ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1057721148 Oct 19  2016 '[アニメ BD] シゴフミ 第04話「ナミダ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1024831965 Oct 19  2016 '[アニメ BD] シゴフミ 第05話「タダイマ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group  976803502 Oct 19  2016 '[アニメ BD] シゴフミ 第06話「サケビ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1018146704 Oct 19  2016 '[アニメ BD] シゴフミ 第07話「キラメキ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1503810507 Oct 19  2016 '[アニメ BD] シゴフミ 第08話「ハジマリ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1100451426 Oct 19  2016 '[アニメ BD] シゴフミ 第09話「サイカイ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1234181825 Oct 19  2016 '[アニメ BD] シゴフミ 第10話「デアイ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1136201000 Oct 19  2016 '[アニメ BD] シゴフミ 第11話「メザメ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1092508733 Oct 19  2016 '[アニメ BD] シゴフミ 第12話「シゴフミ」(1920x1080 AVC 10bit FLACx2 softSub(chi+eng) chap).mkv'
-rw-rw-r--. 1 user group 1218814179 Oct 19  2016 '[アニメ BD] シゴフミ 第13話(終)「ソレカラ」(1920x1080 AVC 10bit FLACx4 softSub(chi+eng) chap).mkv'

I don't understand why it failed with that error on those two files. I googled around for it but all I could find was stuff about copy and pasting commands transforms the - in the command, but that isn't the case here because 1) I wrote all the commands myself, and 2) if that was the problem they all should have failed, not just 08 and 10.

I was able to successfully create the symlink for the two failures by manually linking with the whole filename with no * substitution, so I'm guessing the problem lies in there somewhere. But I don't understand why those two failed but all the others succeeded.

1

The reason is that more than one file corresponds to

/path/to/directory/\[Yurichan\]\ Shigofumi/*08*chi*eng*mkv

and

/path/to/directory/\[Yurichan\]\ Shigofumi/*10*chi*eng*mkv

check it out, run

ls /path/to/directory/\[Yurichan\]\ Shigofumi/*10*chi*eng*mkv

Use

/path/to/directory/\[Yurichan\]\ Shigofumi/*$i*1920x1080*chi*eng*mkv

as a mask, or incorporate 第$i話

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.