symlinks -delete all invalid soft links in Linux/Fedora

2012-06-12 1 min read Bash Fedora Linux

First of all, install symlinks if it is not installed :

sudo yum install symlinks

and here is the description:

Description : The symlinks utility performs maintenance on symbolic links.
Symlinks checks for symlink problems, including dangling symlinks
which point to nonexistent files.  Symlinks can also automatically
convert absolute symlinks to relative symlinks.
Install the symlinks package if you need a program for maintaining
symlinks on your system.

and the help for the same:

Continue reading

Find all the missing paths in the PATH variable in bash script

2011-01-20 1 min read Bash Fedora Learning

Here is a simple script that will list out all the paths in the PATH variable that do not exist.

  <td>
    <div class="text codecolorer">
      #!/bin/bash -<br /> #===============================================================================<br /> #<br /> #          FILE:  wrong_path.sh<br /> #<br /> #         USAGE:  ./wrong_path.sh<br /> #<br /> #   DESCRIPTION:  Show Directories in the PATH Which does NOT Exist<br /> #<br /> #       OPTIONS:  ---<br /> #  REQUIREMENTS:  ---<br /> #          BUGS:  ---<br /> #         NOTES:  ---<br /> #        AUTHOR:  Amit Agarwal (AKA), amit.agarwal@amit-agarwal.co.in<br /> #       COMPANY:  Individual<br /> #       VERSION:  1.0<br /> #       CREATED:  09/20/2009 09:15:48 AM IST<br /> #      REVISION:  ---<br /> #===============================================================================<br /> <br /> set -o nounset                              # Treat unset variables as an error<br /> <br /> (IFS=:;for p in $PATH; do test -d $p || echo $p; done)
    </div>
  </td>
</tr>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

Find out why a program can't seem to access to a file

2010-05-05 2 min read Fedora Linux

$ strace php tias.php -e open,access 2>&1 | <a class="zem_slink freebase/en/grep" href="http://en.wikipedia.org/wiki/Grep" title="Grep" rel="wikipedia">grep foo.txt Sometimes a program refuses to read a file and you&#8217;re not sure why. You may have display_errors turned off for <a class="zem_slink freebase/en/php" href="http://www.php.net/" title="PHP" rel="homepage">PHP or something. In this example, fopen(&#8217;/var/www/test/foo.txt&#8217;) was called but doesn&#8217;t have read access to foo.txt.

Strace can tell you what went wrong. E.g., if php doesn&#8217;t have read access to the file, strace will say &#8221;EACCESS (Permission denied)&#8221;. Or, if the <a class="zem_slink freebase/guid/9202a8c04000641f8000000000220ffa" href="http://en.wikipedia.org/wiki/Path_%28computing%29" title="Path (computing)" rel="wikipedia">file path you gave doesn&#8217;t exist, strace will say &#8221;ENOENT (No such file or directory)&#8221;, etc.

Continue reading

Search & replace with find & ed

2010-03-28 0 min read Bash Learning Linux
\"Computer
Image via Wikipedia

function sr() {

declare pattern replacement name usage
declare -i pvar=0 rvar=0 tvar=0

usage='usage: sr [-t ] [-n name] [-p pattern] [-r replacement] [– ] [dir1 dir2 …]'

# cf. <a href="http://bsdpants.blogspot.com/2007/02/option-ize-your-shell-scripts.html">http://bsdpants.blogspot.com/2007/02/option-ize-your-shell-scripts.html

while [[ "${1:0:1}" == '-' ]] ; do

[[ "${1}" == '–' ]] && { shift; break; } # – marks end of options

Continue reading