LoginSignup
0
0

More than 5 years have passed since last update.

ひとつのファイルを参照するシンボリックリンクを複数作成する

Posted at

はじめに

  • 「index01.html」というものがあったとする
  • 「index02~20.html」というものがあり、これらの内容は全て「index01.html」と同一である
  • 全部コピーして作ってもいいが、今回はこれらをシンボリックリンクで作成することにした

何が問題か

シンボリックリンクが一つしかないなら、次のコマンドで簡単に作れますが…

ln -s /var/www/html/hoge/index01.html /var/www/html/hoge/index02.html

こんな風に連番に対して一度にシンボリックリンクを貼ることはできません!

ln -s /var/www/html/hoge/index01.html /var/www/html/hoge/index{02 .. 20}.html

結果

上のようなことを実現できる方法が、以下になります。

cd /var/www/html/hoge/

for i in $(seq 2 20); do i=`printf %02d $i`; ln -s $(pwd)/index01.html ./index$i.html; done

もし単なる連番(index2~20.html)にしたい場合はこちら

cd /var/www/html/hoge/

for i in $(seq 2 20); do ln -s $(pwd)/index1.html ./index$i.html; done

for文とかseqとかpwdとか、見慣れてる言葉が並んでるので多分解説いらないですよね。おわり。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0