Get Only Filename using find Command in Linux

Get Only Filename using find Command in Linux

In Linux, find command allows to find files and directories in a specified path. By default, this command displays the full path of the file. This tutorial demonstrates how to get only filename using find command in Linux.

The find command provides -printf option that allows to format the output.

find /etc -type f -printf "%f\n"

The %f is a format specifier which means filename. It followed by new line (\n).

Output example:

sitecustomize.py
00-default.cfg
xattr.conf
user-dirs.defaults
snap-userd-autostart.desktop
xdg-user-dirs.desktop
user-dirs.conf
bindresvport.blacklist
services
...

Leave a Comment

Cancel reply

Your email address will not be published.