LinuxQuestions.org
Help answer threads with 0 replies.
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 07-12-2007, 05:50 AM   #1
x_terminat_or_3
Member
 
Registered: Mar 2007
Location: Plymouth, UK
Distribution: Fedora Core, RHEL, Arch
Posts: 342

Rep: Reputation: 38
Find files linked to file


Hi there

I would like to do a search to find all files that link to a certain file. Either soft-linked or hard-linked.

Basically we have folders that contain previous versions. The version currently in use is softlinked.

Example

myfile-1.0.1.ext
myfile-1.1.9.ext

myfile.ext -> myfile-1.1.9.ext


Now I want to go through all the folders and move the previous versions to a different folder.

Any ideas?
 
Old 07-12-2007, 06:14 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
The current version (softlinked) is not the one you want to find. You want to find previous versions.... these are not linked to.

There is no way of looking at a file and knowing what links to it. Tough. You need to write a script that looks (grep?) through all likely directories for the filename-glob you want to move (myfile-*.ext) and then do the bulk move.

Better management is to keep the previous versions in one place, then the cleanup script is simpler.
 
Old 07-12-2007, 06:18 AM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Ls can show you existing links, if the correct options are used. Here's an article: http://www.linuxclues.com/articles/17.htm.

Previous versions though, you would have to search for the basename (filename without version number) of each file that turns up in the ls listing.

ls [options] the contents of a directory;
pipe through an awk script to strip the basename;
pipe through find [some top level directory] to recursively search down through the tree;
pipe through grep to select the basename;
pipe though tee to write the list to a file.

Wiser heads probably know a better way.

Last edited by bigrigdriver; 07-12-2007 at 06:29 AM.
 
Old 07-12-2007, 06:56 AM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
For reasons listed by SimonBridge it is easier to find the current version and move them. Something like this might work.
Code:
find  / -mount -type l -printf "%h/%f %l\n" -exec cp {} /destination/dir \;
This needs some work. If more than one link points to one target file then the target of the links will be written more than once. Also, this solution could be a problem if a link points to a directory.

The format string for the printf action is a little bit funny because I had actually misunderstood your question so I was answering a question that you didn't ask. When I realized my mistake I didn't change the format string when I reworked my solution. You probably don't need the newline at the end of the format string.

Last edited by stress_junkie; 07-12-2007 at 07:08 AM.
 
Old 07-12-2007, 07:18 AM   #5
x_terminat_or_3
Member
 
Registered: Mar 2007
Location: Plymouth, UK
Distribution: Fedora Core, RHEL, Arch
Posts: 342

Original Poster
Rep: Reputation: 38
Thanks all for your input. Looks like I'll probably be better of writing something in php that compares inode numbers to find hard links and readlink for soft links.
 
  


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
How Do I List All Files Linked To inode? freedomics Linux - Software 1 04-24-2007 06:18 PM
Searching for symlinks and hard linked files mikemrh9 Linux - Software 2 04-06-2005 11:14 AM
find files older than another file bmeckle Linux - Software 2 10-21-2004 10:50 AM
how to find a specific file over several *.tgz files eeyoree Slackware 6 08-09-2004 12:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

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
Open Source Consulting | Domain Registration