I was working on an article a couple days ago with a friend and he had sent over some commands for me to reference in the article which included the “sort -R” command. The sort -R switch will randomly sort the contents of a file which is very useful in certain situations. The problem is that the sort command which is installed by the coreutils RPM package on CentOS does not include the -R switch because it is to old. Below I describe the issue in more detail and provide references on how you could upgrade sort on CentOS Linux.
CentOS Linux: sort: invalid option — R
- [root@dev src]# sort -R test.txt
- sort: invalid option -- R
- Try `sort --help' for more information.
- [root@dev src]#
As you can see above the sort command installed with CentOS Linux does not have the -R switch. This version of sort is installed with coreutils 5.9 on CentOS and the -R switch was made available in the version installed with coreutils 6.4.1. Upgrading coreutils on CentOS is not very easy so the technique that can be used to simply upgrade sort from the coreutils package is located in this article. The article describes how to download, configure, compile, and then install a single package from the coreutils source.