-1

I am doing an assignment that requires me to change in to my home directory from my current directory which is ~/sample_dir1/sample_dir/cambridge.

It asks me to change to my home directory using a relative pathname and not using cd by itself, with no arguments.

I have tried numerous combinations of cd ~/ and cd .. etc., but nothing seems to work.

3
  • 1
    One of your classmates asked a very similar question 10 days ago... Feb 23, 2016 at 22:39
  • and there was no answer?
    – user157961
    Feb 23, 2016 at 22:42
  • Tell us what you have tried (you did this), and what the result was. I suspect that if you were to add this to you question, then you would not press submit, as you could figure it out. Feb 23, 2016 at 23:14

3 Answers 3

5

in your directory, if you do ls -a it will list all subdirectories, including the two special directories: . and ..

. refers to the current directory.

.. refers to the parent of the current directory.

Therefore cd .. brings you up one level.

cd ../../.. brings you up 3 levels, which should take you to home.

1

To figure out the relative path from the current directory to some other directory, you may use the GNU tool realpath with its --relative-to option.

For example, I'm currently in /home/myself/Work/Development/project01/scripts and I want to find the relative path to my home directory, /home/myself:

$ realpath --relative-to=. ~
../../../..

The command I used here calculates the relative path from ., the current directory, to ~, my home directory.

I would then be able to use cd ../../../.. to end up in my home directory.

0

below two will point to home directory only.

cd ~

OR

 cd

Relative path movement can be done using

cd ../../..

you can move to previous directory using

cd -
4
  • Ive tried both "cd ~" and "cd" is not allowed
    – user157961
    Feb 23, 2016 at 22:41
  • if it is relative path, you can use cd ../../.. etc
    – Raju
    Feb 23, 2016 at 22:47
  • @user157961, I suggest you to select Liam answer.
    – Raju
    Feb 23, 2016 at 22:50
  • @Liam, you beat me bro
    – Raju
    Feb 23, 2016 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy