Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 19 Jun 2013, 20:17
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Bash on Symbolic Links & Targets of Symbolic Links
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [8 Posts]  
Author Message
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: Fri 13 Apr 2012, 01:00    Post subject:  Bash on Symbolic Links & Targets of Symbolic Links  

Hi,

i want to search/find symbolic links in a directory. The following code finds only files
Code:
Files=`find $TrApps0 -type f`

but i want to find only symbolic links.

What do i have to change?

Then, if symbolic links have been found, i want to get the target of the symbolic link, so i can remove the symbolic link and copy/move the target to previous location of the symbolic link.

How can if get the target of a symbolic link?

All for the use with bash...

Thanks

_________________
Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
Back to top
View user's profile Send private message 
Ibidem

Joined: 25 May 2010
Posts: 262

PostPosted: Fri 13 Apr 2012, 02:00    Post subject:  

Use the options
Code:
-P -type l
insead of -type f.

I found this around line 630 on the man page.
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 1564
Location: Germany

PostPosted: Fri 13 Apr 2012, 02:39    Post subject:  

Ibidem wrote:
Use the options
Code:
-P -type l
insead of -type f.

I found this around line 630 on the man page.


-P gives error message: unknown predicate `-P`

Code:
-type l


finds the symbolic link Cool

I do know -P from cp (do not follow symbolic links), so i can use cp without -P, so it follows the symbolic link and then i can copy the target to /tmp, remove the symbolic link and then move the target from /tmp to the previous location of the (now removed) symbolic link.

Should work - after some work. Laughing

Thanks!

EDIT:

TestScript did work!
Code:
#!/bin/sh

dir=/root/Testdir
dir2=/root/Testdir2

Files=`find $dir -type l`
echo "$Files" |while read F
do
   bn=`basename "$F"`
   echo "$F"
   cp  -P $F $dir2/$bn
   #cp  $F $dir2/$bn
done

_________________
Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4016
Location: Arizona, U.S.A.

PostPosted: Fri 13 Apr 2012, 03:43    Post subject:  

Both these work too.
Code:
ls -l ( File, Dir., or Link ) |grep ^l
[ -L ( File, Dir., or Link ) ]&& echo LINK
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 10824
Location: The Peoples Republic of California

PostPosted: Fri 20 Apr 2012, 21:11    Post subject:  

Here is one I just worked on

Code:
ls -l | grep ^l |  awk '{print $8" "$9" "$10}'


outputs like this:

erasecd -> blankcd
protect -> /sbin/pup_event_backend_modprobe_protect
routines -> /routines.sh

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 3845

PostPosted: Sat 21 Apr 2012, 00:59    Post subject:  

Bruce B wrote:
Code:
ls -l | grep ^l |  awk '{print $8" "$9" "$10}'
or without grep
Code:
ls -l|awk '/^l/{print $8" "$9" "$10}'


for find you can use -type l
(then readlink)

_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 2736
Location: Kiel,Germany

PostPosted: Sat 21 Apr 2012, 15:42    Post subject:  

Code:
ls -1F |grep '@$'

could give something like
include@
spool@
var@
X11@
X11R6@

I tend to use the find command, too,
but to always filter the often unneeded "./" and "." is annoying to me .

*
find has got the

The -H, -L and -P options control the treatment of symbolic links.

OPTIONS

which have to go like "find -H /usr -type l -mmin -60" .
( -mmin -N says to find links modified (ie rm and created new) not older than 60min, -mmin 60 should find oler than 60min ; same for -amin(access time) and -cmin(change time(mod time or chmod time))||-mtime for (N*24)days) )

The manpage of find is really large for the part on -H, -L and -P options .

*
Another binary to look at would be readlink , i think :
Code:
for item in *;do echo -n "$item: " ;S_RL=`readlink $item`;case $item in "")echo;;*)echo "$S_RL";;esac;done

should give something like
bin:
etc:
i486-t2-linux-gnu:
include: include_orig/
include_latest:
include_orig:
info:
lib:
libexec:
link_include_switch.sh:
local:
man:
sbin:
share:
spool: /var/spool
tmp:
var: ../var
X11: X11R6
X11R6: X11R7

X11R7:

*
readlink -e would be used like
Code:
for item in *;do echo -n "$item: " ;readlink -e $item;done

bin: /usr/bin
etc: /usr/etc
i486-t2-linux-gnu: /usr/i486-t2-linux-gnu
include: /usr/include_orig
include_latest: /usr/include_latest
include_orig: /usr/include_orig
info: /usr/info
lib: /usr/lib
libexec: /usr/libexec
link_include_switch.sh: /usr/link_include_switch.sh
local: /usr/local
man: /usr/man
sbin: /usr/sbin
share: /usr/share
spool: /var/spool
tmp: /usr/tmp
var: /var
X11: /usr/X11R7
X11R6: /usr/X11R7

X11R7: /usr/X11R7

NOTE : The links are distinguishable by the difference of the `pwd` or dirname command to obtain the current dir ( /usr/ in this case ) or the difference in the basename (command) .
Back to top
View user's profile Send private message Visit poster's website 
Bruce B


Joined: 18 May 2005
Posts: 10824
Location: The Peoples Republic of California

PostPosted: Sat 21 Apr 2012, 15:45    Post subject:  

technosaurus wrote:
Bruce B wrote:
Code:
ls -l | grep ^l |  awk '{print $8" "$9" "$10}'
or without grep
Code:
ls -l|awk '/^l/{print $8" "$9" "$10}'





Better, thanks.

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0625s ][ Queries: 11 (0.0061s) ][ GZIP on ]