/usr/bin/realpath not found in Centos 6.5

10

2

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?

Daniel YC Lin

Posted 2014-06-20T03:20:38.873

Reputation: 795

Try sudo yum provides -C realpath to see which package it is in; then install it (or try re-installing if it is already installed). – BenjiWiebe – 2014-06-20T03:38:53.653

yum provides -C /usr/bin/realpath

Loaded plugins: fastestmirror, refresh-packagekit, security

No Matches found – Daniel YC Lin – 2014-06-20T04:41:14.940

@DanielYCLin Can't you simply use readlink -e? It is exactly the same thing. – MariusMatutiae – 2014-06-20T06:05:41.693

@MariusMatutiae please write as answer, I'm writing my script, so, it is possible to use readlink if centos 6.5 support it. – Daniel YC Lin – 2014-06-20T16:56:24.327

@DanielYCLin I have done so, as per your request. – MariusMatutiae – 2014-06-20T17:11:47.790

BTW, yum provides -C /usr/bin/realpath isn't the right command...it might be in /bin! So when using yum provides, just use the command name: sudo yum provides -C realpath. – BenjiWiebe – 2014-06-23T12:36:50.843

Answers

10

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.

MariusMatutiae

Posted 2014-06-20T03:20:38.873

Reputation: 41 321

3

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.

user1686

Posted 2014-06-20T03:20:38.873

Reputation: 283 655

So, 'realpath' is not contained in centos official repository. Install 3rd party rpm is the only way? – Daniel YC Lin – 2014-06-20T05:50:29.467

1

@DanielYCLin You could just download it from ftp.gnu.org, run tar -xJf coreutils-8.22.tar.xz; ./configure; make; sudo make install. It will put it in /usr/local/bin which is likely in your PATH (if not, you can add it).

– BenjiWiebe – 2014-06-23T12:35:30.210

3or just echo '/usr/bin/readlink -e "$@"' > /usr/local/bin/realpath ; chmod +x /usr/local/bin/realpath – djsadinoff – 2014-12-30T15:22:42.523

@djsadinoff It's best practice not to call an alias after another command. realpath -s $0, for instance, is a very common idiom not covered there. – Nuno André – 2019-11-12T10:24:05.680

1

Normally realpath is provided by coreutils package, so you should install it via:

yum install coreutils

Alternatively try: readlink or define your own function, such as:

realpath () { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" }

or see some more examples here.

I've tested the command in CentOS 7 VM via Vagrant:

vagrant init bento/centos-7.1 && vagrant up --provider virtualbox && vagrant ssh

it seems realpath is installed by default.

kenorb

Posted 2014-06-20T03:20:38.873

Reputation: 16 795