Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative path to the home directory (linux)

Tags:

linux

bash

When I use pwd it returns:

/home/ahmad/multifit-pretrain-lm/multifit/datasets

I look for a command so that I get the path relative to the home directory

multifit-pretrain-lm/multifit/datasets
like image 870
Ahmad Avatar asked Oct 24 '25 13:10

Ahmad


1 Answers

I look for a command so that I get the path relative to the home directory

You can use bash parameter substitution here:

echo "${PWD#"$HOME"/}"
  • $PWD shell variable returns same value as the command pwd
  • ${PWD#"$HOME"/} strips "$HOME"/ at the start from $PWD
like image 50
anubhava Avatar answered Oct 26 '25 02:10

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!