I was following this article to update my bash. I really want to update my version of bash so that I can use the --group-directories-first
option for the ls
command.
So far I have accomplished the following from the linked article:
I successfully executed the brew install bash
command and downloaded the new bash. Per the article I can verify that the the /usr/local/bin/bash --version
on my machine shows the following:
GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin18.6.0) Copyright (C) 2019 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
sudo vim /etc/shells
command, editing the file to include the new downloaded bash. This is what it looks like: chsh -s /usr/local/bin/bash
to set the new bash as default. However, even after I close the terminal and relaunch it, I am not sure if I am using the new terminal. This is because:
when I execute bash --version
I get the following:
GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin18.6.0) Copyright (C) 2019 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
But when I run echo $BASH_VERSION
I get something to the contrary (3.2.57(1)-release
). Isn't that the old verison?
ls --group-directories-first
: ls: illegal option -- - usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
Any help or pointers would be greatly appreciated.
Thanks!
Homebrew can be used to install the GNU versions of tools onto your Mac, but they are all prefixed with "g" by default. All commands have been installed with the prefix "g". If you need to use these commands with their normal names, you can add a "gnubin" directory to your PATH from your bashrc.
Ever want to have the ll command to view file permissions, ownership and other details in a terminal session. MacOS does not come with this command by default. It can be easily added though through an alias. sudo nano .bash_profile. Add this line and then save your .bash_profile: alias ll='ls -lG'
To do that you use the ls (or list) command. Type ls and press the Return key, and you'll see the folders (and/or files) in the current directory.
This has nothing to do with bash
. Command ls
is not a builtin of bash
.
macOS is based on the Unix operating system. Some of its basic commands are BSD flavored. The --group-directories-first
option you want is available in GNU ls
only. All you need is a GNU flavored ls
.
Solution: install coreutils
, in which GNU ls
is included.
brew install coreutils
Add the following code into ~/.bash_profile
, to prioritize the ls
command and other GNU flavored commands over the builtin BSD flavored command in macOS.
# Make all GNU flavor commands available, may override same-name BSD flavor commands
# For x86 Mac
export PATH="/usr/local/opt/coreutils/libexec/gnubin:${PATH}"
export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:${MANPATH}"
# For M1 Mac
export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:${PATH}"
export MANPATH="/opt/homebrew/opt/coreutils/libexec/gnuman:${MANPATH}"
If you only want the GNU ls
but not other GNU flavored commands. Don't add the above content, but create an alias in ~/.bash_profile
.
# For x86 Mac
alias ls="/usr/local/opt/coreutils/libexec/gnubin/ls"
# For M1 Mac
alias ls="/opt/homebrew/opt/coreutils/libexec/gnubin/ls"
Here's all commands brought by coreutils
.
❯ ls /usr/local/opt/coreutils/libexec/gnubin
'[' cat cksum dd echo fmt install ls mv od printf rmdir sha384sum split tac tr unexpand wc
b2sum chcon comm df env fold join md5sum nice paste ptx runcon sha512sum stat tail true uniq who
base32 chgrp cp dir expand groups kill mkdir nl pathchk pwd seq shred stdbuf tee truncate unlink whoami
base64 chmod csplit dircolors expr head link mkfifo nohup pinky readlink sha1sum shuf stty test tsort uptime yes
basename chown cut dirname factor hostid ln mknod nproc pr realpath sha224sum sleep sum timeout tty users
basenc chroot date du false id logname mktemp numfmt printenv rm sha256sum sort sync touch uname vdir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With