Extract File Name in Shell

Level 126 keystrokes

basename extracts the filename from a path.

Shell code

# Removes the directory part and prints only the last component: file.txt
# dirname does the opposite and would print /path/to
1basename /path/to/file.txt

Output

file.txt
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Shell code and how often they appear.

  • /× 3
  • .× 1

More Shell examples at level 1

← Shell typing practice