Shell: Strip directory from path

Problem:

In the Linux shell, you have  a file path and you want to strip everything but the filename, for example  you have the path ../images/photo.jpg  and want only photo.jpg

Solution

Assuming the filename is stored in the shell variable $filename, use this snippet:

echo $filename | rev | cut -d/ -f1 | rev