Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-05-2014, 04:14 PM   #1
Registered: Aug 2012
Posts: 709

Rep: Reputation: Disabled
Understanding Symbolic Links

Is it possible to tell if I am in a symbolic link? For instance, take /home/Michael/s_dir1/dir1_1 for example where the "real" folder is /home/Michael/dir1/dir1_1.

Or maybe all directories are symbolic links to another file, and Linux only displays the first one created as a directory for our benefit?

[Michael@michaels ~]$ mkdir dir1
[Michael@michaels ~]$ mkdir dir1/dir1_1
[Michael@michaels ~]$ ln -s dir1 s_dir1
[Michael@michaels ~]$ cd ~/dir1/dir1_1
[Michael@michaels dir1_1]$ touch file1
[Michael@michaels dir1_1]$ ls -l
total 0
-rw-rw-r--. 1 Michael Michael 0 Apr  5 08:14 file1
[Michael@michaels dir1_1]$ ls ~/dir1/dir1_1
[Michael@michaels dir1_1]$ rm ~/dir1 -fR
[Michael@michaels dir1_1]$ ls -l
total 0
[Michael@michaels dir1_1]$ cd ~
[Michael@michaels ~]$ ls -l
total 16
-rw-rw-r--. 1 Michael Michael   34 Apr  4 08:19 decryted.txt
-rw-rw-r--. 1 Michael Michael   34 Apr  4 08:15 file.txt
-rw-rw-r--. 1 Michael Michael  371 Apr  4 08:15 file.txt.gpg
-rw-rw-r--. 1 Michael Michael 1744 Apr  4 08:25 Michael_PUBKEY.txt
lrwxrwxrwx. 1 Michael Michael    4 Apr  5 08:14 s_dir1 -> dir1
[Michael@michaels ~]$ cd s_dir1
-bash: cd: s_dir1: No such file or directory
[Michael@michaels ~]$ rm s_dir1
[Michael@michaels ~]$
Old 04-05-2014, 04:20 PM   #2
Rogue Class
Registered: Sep 2006
Location: OR, USA
Distribution: Slackware 14.1
Posts: 201
Blog Entries: 3

Rep: Reputation: 78
if [ "$(readlink -f $PWD)" == "$PWD" ]; then echo 'not in a link'; else echo 'in a link'; fi
1 members found this post helpful.
Old 04-05-2014, 10:37 PM   #3
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,705

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
A symbolic link is a file identified as a link, and that file contains the path specification to reach another file.

Some good background information (and history) is at:

You can mostly quit reading when you reach the section "Advanced" Ext2fs features...
Old 04-06-2014, 01:13 AM   #4
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 525

Rep: Reputation: 141Reputation: 141
$ pwd -P
If pwd and pwd -P are same, then you are in real path, else not.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Symbolic links Vs Hard links sulekha Linux - General 2 10-02-2008 07:03 AM
Symbolic links? TongueTied Linux - Newbie 3 08-27-2003 06:00 AM
Symbolic links pdstatha Programming 1 04-08-2002 09:50 PM
symbolic links winger Linux - General 5 04-06-2002 05:16 PM
Symbolic links Valerie Linux - Newbie 12 03-31-2002 01:49 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:44 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration