Right click to find symbolic link

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

Right click to find symbolic link

#1 Post by don570 »

Forum member SFR has a neat and simple method to
discover if icon is a symbolic link to a folder ( or to an
ordinary file).

He used it in Large file finder
http://murga-linux.com/puppy/viewtopic.php?t=77779

I used it in the script create-3mu found HERE

The 'find' command won't work if the location given
is a symbolic link. So getting the real location is important.

Code: Select all

FPATH="$1"
TEST=`stat -c %F "$FPATH"`
if [ "$TEST" = "symbolic link" ]; then
  FPATH=`stat -c %N "$FPATH" | cut -f3 -d '\`'`
  FPATH=${FPATH%?}
fi

Explanation: FPATH is path of the folder(or file).
After execution of the code it will be the path to the real folder(or file)

The variable TEST will contain the text "symbolic link" if
the user has right clicked on a symbolic link.

In the special case of the symbolic link and the real file being
in the same folder -----> just the real name is returned.

___________________________________________

__________________________________________________

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#2 Post by RSH »

Hi.

Code: Select all

FPATH="$1"
TEST=`stat -c %F "$FPATH"`
if [ "$TEST" = "symbolic link" ]; then
  FPATH=`stat -c %N "$FPATH" | cut -f3 -d '\`'`
  FPATH=${FPATH%?}
fi
This is exactly the solution to something i am currently working on. The LazY Puppy Run-Script-GUI (Starter) shows only symbolic links to the Run-Scripts in a different directory. I do use this now to remove these symbolic links and its Run-Scripts (including the directory) from within the Run-Script-GUI.

Code: Select all

FPATH="$Progs$TREEOUTPUT"
TEST=`stat -c %F "$FPATH"`
if [ "$TEST" = "symbolic link" ]; then
	FPATH=`stat -c %N "$FPATH" | cut -f3 -d '\`'`
	FPATH=${FPATH%?}
fi
dbn=`dirname $FPATH`
rm -r $dbn
rm $Progs$TREEOUTPUT
Thanks a lot to don570 and to SFR.

RSH
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#3 Post by seaside »

Another way is to use readlink -

Code: Select all

 [[ `readlink "$1"` ]] && FPATH=`readlink "$1"` || FPATH="$1" 
Cheers,
s
(Or readlink -e if recursion needed)

Post Reply