For files in directory, only echo filename (no path)
If you want a native bash
solution
for file in /home/user/*; do
echo "${file##*/}"
done
The above uses Parameter Expansion which is native to the shell and does not require a call to an external binary such as basename
However, might I suggest just using find
find /home/user -type f -printf "%f\n"
Just use basename
:
echo `basename "$filename"`
The quotes are needed in case $filename contains e.g. spaces.