2

Let say my current directory in terminal is ~/Users/Desktop. On my desktop, there's a folder called "sample_dir". How can I cd in this "sample_dir" folder with typing: "cd ~/Users/Desktop/sample_dir"? There's gotta be a shorter way that looks at your current directory and appends that path to the directory you pass in to make things faster.

Thanks

7 Answers 7

10

There is. Type:

cd sample_dir

It checks for you. If for some strange reason that doesn't work, type:

cd ./sample_dir
7

I usually type cd, then drag the folder (from Finder) that I want to open in Terminal, and drop it in Terminal. This will add the full directory path, then press enter to change to the dropped directory.

7

The path you are using cd ~/Users/Desktop/sample_dir is wrong.

If you have a folder named sample_dir in you user's Desktop directory then the full path to the directory is:

cd /Users/YourUserName/Desktop/sample_dir

Where YourUserName is the the short account username. Using the tilde ~ shortcut to your home directory this can be shortened to

cd ~/Desktop/sample_dir

When you open a new terminal session you start in your home directory, so:

cd Desktop/sample_dir
2

Typing cd sample_dir should work... check "pwd" to make sure the current path is what you expect.

0
0

Found an even easier way with MacOS Ventura 13.0.1.

  • open Finder and navigate to the folder you want to cd to
  • ensure you can see the Path Bar (Finder > View > Show Path Bar)
  • right click the folder you want to cd to in the Path Bar
  • select 'Open in Terminal'

Et Voilà!

1
  • This does not answer the original question which is about navigating to a certain directory when someone is already in Terminal.
    – Alper
    Jan 23 at 11:18
-3

cd Desktop/sample_dir

should work :)

-3

Dude you should do a simple step if you are using mac type cd and then use space and then drag the file you wants to open in terminal(most probably for git hub purpose).

1

You must log in to answer this question.