Print Linux Path Without Duplicates on different lines

 If you want to print the path and seeing so many duplicates or seeing everything nn the same line, you can use this solution.

Normally the solution to print path on different lines is:

echo "$PATH" | tr : "\n"

but only this wouldn't remove the duplicates.

To remove the duplicates, open ~/.bashrc and paste this to the end of file:

PATH="$(perl -e 'print join(":", grep { not $seen{$_}++ } split(/:/, $ENV{PATH}))')"
export PATH
alias listpath='echo "$PATH" | tr : "\n"'

This command makes sure that it will remove the duplicates and keep the correct order.

It also creates an alias so using `listpath` command would easily print as we want.



Paylaş:

Ara