11

I am beginning to learn ruby and was following the instructions of one video to access the desktop through the -ls command in the terminal. Now, I would like to get out of the desktop in the terminal and don't know how. I know, I know I am a total noob... but can someone please help. Thanks. BTW the command I wrote was:

   my-iMac~ me$ cd Desktop/
   my-iMac:Desktop samuel$ ls
4
  • 3
    Do you want to go home? Just type cd
    – James M
    Feb 1, 2012 at 16:42
  • 3
    You can type: cd .. to go up one directory. Feb 1, 2012 at 16:43
  • Got it... thanks a lot. I feel foolish, part of learning I guess
    – SamYoungNY
    Feb 1, 2012 at 16:43
  • Use cd - to go the previous directory Oct 28, 2017 at 2:51

3 Answers 3

27

Where would you like to go?

Go home: cd or cd ~
Go to the previous working directory: cd $OLDPWD
Go to parent of the current directory: cd ..
Go to any directory you want: cd /path/to/directory

3
  • 25
    cd - is fewer keystrokes than cd $OLDPWD
    – Paul R
    Feb 1, 2012 at 16:48
  • 2
    cd - I wish I knew that one years ago (yes, I know this isn't really allowed)
    – janw
    Jun 16, 2015 at 12:06
  • if cd - gives error like "-bash: cd: OLDPWD not set" then just export OLDPWD in your ~/.bash_profile file and source it. May 23, 2016 at 7:10
10

cd .. will take you back up 1 level.

1
  • Scott bestAnswer
    – MIH
    Aug 15, 2020 at 8:07
0

for windows, you can open up the file explorer copy path then in your command prompt type "cd" then paste path. Your command prompt should now default to that path. (you can also type the entire path)

cd C:\Users\username\Documents\Folder

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.