linux - /usr/bin/realpath not found in Centos 6.5

07
2014-07
  • Daniel YC Lin

    I'm trying to type 'realpath' in CentOS 6.5. But it seems not installed. I checked it is contained in coreutils (archlinux). I double check the coreutils package which provide by CentOS, it lack the /usr/bin/realpath. I don't want to install 3rd party rpm like 'http://pkgs.org/centos-6/repoforge-x86_64/realpath-1.17-1.el6.rf.x86_64.rpm.html'.

    I've did yum search realpath, can not found it. Is the utility contains in other package? Or just be removed for security reason?

  • Answers
  • MariusMatutiae

    realpath is a very useful tool, however most of its functionalities were already present with readlink. The realpath man page states:

    Please note that mostly the same functionality is provided by the '-e' option of the readlink(1) command.

    And the readlink man page states:

    -e, --canonicalize-existing: canonicalize by following every symlink in every component of the given name recursively, all components must exist.

    The readlink command was added to coreutils, AFAIK, in 2008: it is surely available in Ubuntu Hardy 8.04. So if you do not have realpath, it is possible that you have readlink immediately available.

  • grawity

    The realpath tool was added to GNU coreutils in version 8.15 (commit 77ea441f79aa), released in 2012. Your CentOS release likely has coreutils v8.4. The tool wasn't removed; it was not yet added in the first place.


  • Related Question

    linux - What is /usr/bin/[ and how do I use it?
  • nelaar

    I was looking at coreutils and found this as one of the files included as part of coreutils: /usr/bin/[. What is [ and what does it do?

    It is an executable. I just don't know what it does or how to use it.

    $ file /usr/bin/[
    /usr/bin/[: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

    When I try to run it, I think it is defaulting to the bash built in line expansion. Instead of actually running the file.

    $ "/usr/bin/["
    /usr/bin/[: missing ]' $ /usr/bin/\[
    /usr/bin/[: missing
    ]'


  • Related Answers
  • Rajish

    It's an equivalent of the command test. (See info test.) Generally you use it in scripts in conditional expressions like:

    if [ -n "$1" ]; then
        echo $1
    fi
    

    The closing bracket is required to enclose the conditional. (Well, it looks like its required just to look nicer in the code. Does anybody know any other practical reason for it?)

  • dogbane

    It is equivalent to the test command.

    Instead of

    if /usr/bin/test -z "$VAR"
    then
        echo VAR not set
    fi
    

    You can use:

    if /usr/bin/[ -z "$VAR" ]
    then
        echo VAR not set
    fi
    

    It can be used in loops too:

    i=0
    while [ $i -lt 10 ]
    do
       echo $i
       ((i++))
    done
    

    You can also use them in one-liners like this:

    [ -z "$VAR" ] && echo VAR not set && exit
    
    [ -f foo.txt ] && cat foo.txt