Ubuntu – How to display $PATH as one directory per line

bashpaths

I cannot figure out how to list the various paths in $PATH separately so that they look like this:

/bin
/usr/bin
/usr/local/bin

How can this be done?

Best Answer

You can do this with any one of the following commands, which substitutes all occurrences of : with new lines \n.

sed:

$ sed 's/:/\n/g' <<< "$PATH"

tr:

$ tr ':' '\n' <<< "$PATH"

python:

$ python -c 'import sys;print(sys.argv[1].replace(":","\n"))' "$PATH"
Related Question