basename

Remove leading directory portions from a path. More information: <https://www.gnu.org/software/coreutils/basename>.

Install

All systems
curl cmd.cat/basename.sh
Debian Debian
apt-get install coreutils
Ubuntu
apt-get install coreutils
Alpine
apk add coreutils
Arch Arch Linux
pacman -S coreutils
image/svg+xml Kali Linux
apt-get install coreutils
CentOS
yum install coreutils
Fedora
dnf install coreutils
Windows (WSL2)
sudo apt-get update sudo apt-get install coreutils
OS X
brew install coreutils
Raspbian
apt-get install coreutils
Docker
docker run cmd.cat/basename basename powered by Commando

Remove leading directory portions from a path. More information: <https://www.gnu.org/software/coreutils/basename>.

  • Show only the file name from a path:
    basename path/to/file
  • Show only the rightmost directory name from a path:
    basename path/to/directory/
  • Show only the file name from a path, with a suffix removed:
    basename path/to/file suffix

© tl;dr; authors and contributors