| Author |
Message |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: 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
|
|
 |
Ibidem
Joined: 25 May 2010 Posts: 262
|
Posted: Fri 13 Apr 2012, 02:00 Post subject:
|
|
Use the options insead of -type f.
I found this around line 630 on the man page.
|
|
Back to top
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: Fri 13 Apr 2012, 02:39 Post subject:
|
|
| Ibidem wrote: | Use the options insead of -type f.
I found this around line 630 on the man page. |
-P gives error message: unknown predicate `-P`
finds the symbolic link
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.
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
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4016 Location: Arizona, U.S.A.
|
Posted: 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
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10824 Location: The Peoples Republic of California
|
Posted: 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
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3845
|
Posted: 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
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 2737 Location: Kiel,Germany
|
Posted: Sat 21 Apr 2012, 15:42 Post subject:
|
|
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
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10824 Location: The Peoples Republic of California
|
Posted: 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
|
|
 |
|