11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cd でシンボリックリンク先の実体のパスに移動する

Last updated at Posted at 2016-10-16

概要

bash で cd コマンドでディレクトリ移動する際、移動先がシンボリックリンクだった場合、シンボリックリンク先のディレクトリパスに移動する方法。

一言で言うと -P オプションでシンボリックリンク先のディレクトリに移動できます。

# こういう状態
[vagrant@vagrant-centos65 test]$ ls -la /tmp/test
total 12
drwxrwxr-x  3 vagrant vagrant 4096 Oct 14 02:15 .
drwxrwxrwt. 5 root    root    4096 Oct 14 02:15 ..
drwxrwxr-x  2 vagrant vagrant 4096 Oct 14 02:15 real-dir
lrwxrwxrwx  1 vagrant vagrant   18 Oct 14 02:15 virtual-dir -> /tmp/test/real-dir

#通常の cd
[vagrant@vagrant-centos65 test]$ cd /tmp/test/virtual-dir 
[vagrant@vagrant-centos65 virtual-dir]$ pwd
/tmp/test/virtual-dir

# -P 付きの cd
# /tmp/test/real-dir へ移動している
[vagrant@vagrant-centos65 virtual-dir]$ cd -P /tmp/test/virtual-dir 
[vagrant@vagrant-centos65 real-dir]$ pwd
/tmp/test/real-dir
11
9
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
11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?