[ale] Bash (or whatever) question
fletch at phydeaux.org
fletch at phydeaux.org
Tue Feb 15 23:28:27 EST 2005
> I have a directory with softlinks to a number of files that no longer
> exist, along with links to files that _do_ exist.
>
> How can I selectively list those links which are _not_ satisfied, so I can
> remove them at one go, while ignoring those for which the linked files
> still exist?
lemur:~/linktest 712> ls -la
23:14:39
total 16
drwxr-xr-x 5 fletch fletch 170 15 Feb 23:13 ./
drwxr-xr-x 89 fletch fletch 3026 15 Feb 23:12 ../
lrwxr-xr-x 1 fletch fletch 10 15 Feb 23:12 bad@ -> /not/there
lrwxr-xr-x 1 fletch fletch 10 15 Feb 23:12 good@ -> /etc/hosts
-rw-r--r-- 1 fletch fletch 0 15 Feb 23:13 regular_file
lemur:~/linktest 713> perl -le 'for(grep -l, glob("*")){$l=readlink;warn
"broked: $_ => $l\n" unless -e $l}'
broked: bad => /not/there
Or . . .
ruby -le
'Dir.glob("*").select{|f|File.symlink?(f)}.each{|f|l=File.readlink(f);$stderr.print
"broked: #{f} => #{l}" if !File.exist?(l)}'
--
Fletch | "If you find my answers frightening, __`'/|
fletch at phydeaux.org| Vincent, you should cease askin' \ o.O'
| scary questions." -- Jules =(___)=
| U
More information about the Ale
mailing list