LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-29-2007, 05:19 PM   #1
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,436

Rep: Reputation: 83
How to find symlink?


Hya,

What is the easiest and fastest way to find symlink(s)?

I know that
Code:
find / -lname linktarget
works. But it takes longer than usual search, especially when file system is huge.

Is there any better way?

Happy Penguins!
 
Old 06-29-2007, 05:44 PM   #2
Electro
Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
If using ext3, enable its b-tree feature. It should speed up searching. Another way is contribute to slocate to include an option to search by file and directory types. The find utility is the normal search tool. slocate is a database search tool that needs to be updated when files or directories are created or moved.
 
Old 06-29-2007, 05:49 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
ls -lR <dirname>|grep "^l"

I can't immediately figure out how to make this show the directory in which it finds each match.
 
Old 06-30-2007, 02:15 AM   #4
dr34m3r
LQ Newbie
 
Registered: Jun 2007
Distribution: Fedora
Posts: 7

Rep: Reputation: 0
ls -lR <dirname> |grep "^l\|:$"

prints the directory name first and then symlinks in the directory

Last edited by dr34m3r; 06-30-2007 at 02:18 AM.
 
Old 06-30-2007, 09:07 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by dr34m3r
ls -lR <dirname> |grep "^l\|:$"

prints the directory name first and then symlinks in the directory
I have never seen syntax like this before---I assume that "|" is escaped so it won't act as a pipe, but then what does it mean? (Alternation operator?)

backreference!!--a little bell is ringing---is this a backreference?

Note that this prints ALL the directories in the search path, plus the links it find in each one. I guess you could then write more code to strip out the one's which contain no links......
 
Old 06-30-2007, 07:14 PM   #6
dr34m3r
LQ Newbie
 
Registered: Jun 2007
Distribution: Fedora
Posts: 7

Rep: Reputation: 0
Quote:
Originally Posted by pixellany
I have never seen syntax like this before---I assume that "|" is escaped so it won't act as a pipe, but then what does it mean? (Alternation operator?)

backreference!!--a little bell is ringing---is this a backreference?
I dont think this is not a backreference. It just a simple OR in bash (although I may be wrong!!)

Quote:
Originally Posted by pixellany
Note that this prints ALL the directories in the search path, plus the links it find in each one. I guess you could then write more code to strip out the one's which contain no links......
this bash script should do the job perfectly. the script takes the search directory as agrument. Tell me what you think. I know this can be made better, but this is what I could think off top of my head.

Code:
#!/bin/bash
IFS=$'\n'
prevLine=
printDir=

for line in `ls -lR $1 |grep "^l\|:$" ` ; do
        if [ -z $prevLine ] ; then
                prevLine=$line
        else
                if [ "${prevLine:$((1-2))}" == ":" ] && [ "${line:0:1}" == "l" ]; then
                        if [ -z $printDir ]; then
                                echo $prevLine
                                printDir=printed
                        fi
                        echo $line
                else
                        prevLine=$line
                        printDir=
                fi

        fi
done
 
Old 07-02-2007, 06:40 AM   #7
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,436

Original Poster
Rep: Reputation: 83
Hya,

Um... I guess life is not easy.

Quote:
I dont think this is not a backreference. It just a simple OR in bash (although I may be wrong!!)
I guess is is OR in gnu grep, (although I may be wrong!)

Happy Penguins!
 
Old 07-02-2007, 07:46 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by kaz2100
Hya,

Um... I guess life is not easy.

I guess is is OR in gnu grep, (although I may be wrong!)

Happy Penguins!
You guess right---they actually call it the "alternation operator". I was being dense in that post....the code was obvious once I thought about it. (":$" means ":" at the end of the line. "|" is escaped because it is parentheses to keep bash from seeing it as a pipe--except that the quotes mean "read literally"--hence the escape to give special meaning to "|" (but a different special meaning than if it had be left unquoted...) )
Whew!!!---just one example of why shell scripting takes a few days to learn....
 
Old 07-02-2007, 12:57 PM   #9
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,436

Original Poster
Rep: Reputation: 83
Quote:
Originally Posted by pixellany
Raise your hand if you: A) had a vacuum tube collection in HS, B) know what IS a vacuum tube, C) know what is (was) magnetic core memory, D) know what is(was) an IBM keypunch, or E) know how to build radios with acid-core solder
I do not know how to raise hand here, however
A) No.
B) No.
C) Yes, it used to be state-of-art, space occupying heavy industry product. Several KB (kilo bit??) range.
D) Yes, it was Important Bunch of Machine for key-puncher. One card (boarding pass size) per one line. No backspace, delete keys.
E) Yes. Some of these radios work without external battery. Coil, variable condenser, antenna, ear piece and crystal. (http://en.wikipedia.org/wiki/Crystal_radio)

Happy Penguins!
 
Old 07-02-2007, 01:07 PM   #10
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,436

Original Poster
Rep: Reputation: 83
By the way,

Such a radio does not use any "semi-conductor" at all. Only conductor, inductor, capacitor and reactor. Not even resistor.

Happy Penguins!
 
  


Reply

Tags
bash, grep, link, search, symbolic, symlink


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
How to find symlink target name in script germanyzulu Linux - Software 3 08-09-2006 03:14 PM
Symlink Fredde87 Linux - General 14 09-30-2005 08:06 PM
symlink mikedelo Linux - Software 2 03-28-2004 12:32 PM
symlink evannextel Linux - Newbie 1 09-17-2003 03:54 PM
Symlink Mestax Linux - Newbie 3 09-04-2003 12:07 PM


All times are GMT -5. The time now is 04:07 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration