LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 04-05-2014, 05:14 PM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 543

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?


Code:
[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
file1
[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, 05:20 PM   #2
BenCollver
Rogue Class
 
Registered: Sep 2006
Location: OR, USA
Distribution: Slackware 14.1
Posts: 201
Blog Entries: 3

Rep: Reputation: 78
Code:
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, 11:37 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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:

http://web.mit.edu/tytso/www/linux/ext2intro.html

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

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


Reply


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 08:03 AM
Symbolic links? TongueTied Linux - Newbie 3 08-27-2003 07:00 AM
Symbolic links pdstatha Programming 1 04-08-2002 10:50 PM
symbolic links winger Linux - General 5 04-06-2002 06:16 PM
Symbolic links Valerie Linux - Newbie 12 03-31-2002 02:49 AM


All times are GMT -5. The time now is 06:31 AM.

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