43

I want to take the path of the local directory and put each directory on the path in a different line. I've tried to do it using cut:

pwd | cut -f 1- -d\/ --output-delimiter=\n

but it doesn't change the '/'s into EOL, but puts n's instead. What am I doing wrong?

Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
SIMEL
  • 8,745
  • 28
  • 84
  • 130

3 Answers3

70

This should do the trick

pwd | tr '/' '\n'

If you don't want an empty line in the beginning (due to the initial /) you could do

pwd | cut -b2- | tr '/' '\n'

Example:

#aioobe@r60:~/tmp/files$ pwd
/home/aioobe/tmp/files
#aioobe@r60:~/tmp/files$ pwd | cut -b2- | tr '/' '\n'
home
aioobe
tmp
files
aioobe
  • 413,195
  • 112
  • 811
  • 826
9

You can try:

pwd | tr '/' '\n'
codaddict
  • 445,704
  • 82
  • 492
  • 529
6

This is how you would accomplish what you set out to do (using ANSI-C quoting):

pwd | cut -f 1- -d\/ --output-delimiter=$'\n'
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439