N equivalent way to remember directories on mounted volumes like DOS

cd-commandcommand linedirectoryfilesystems

A while ago, I moved from a purely Windows environment to using Windows and a Mac.

Whilst I am slowly getting used to my Mac and loving it, there are a few things that frustrate me.

One of them is the fact that there is only 1 working directory on the filesystem.

That may seem odd to those only ever run Unix, but follow this as my experience on Windows.

I have C: (programs), D: (data), E: (CD/DVD) and F: & G: (USB keys).

If I type …

CD /D F:\Dir1\Dir2
CD /D D:\Dir3\Dir4
F:
CD
D:
CD

assuming that those are all valid paths, the output will be …

F:\Dir1\Dir2
D:\Dir3\Dir4

This shows I can swap between "drives" and I get the last working directory per drive.

This is really useful when you want to copy content from one drive to another, without having to type the entire path.

You can go to the directory, verify its contents, switch to the destination drive/directory and then initiate the copy …

COPY F:*.* D:.

for example.

When it comes to my Mac, whilst I could use the UI with 2 Finder tabs, I would still like to be able to to use the command line.

Is there an equivalent way of having a mounted filesystem remember and expose the last working directory on that filesystem?

At the moment it is the "type the entire command out completely" approach.

Best Answer

Your question is about the features of bash, which is probably the shell you are using as command line.

For the switching part you can use cd - to switch back to the previous directory.

If you want to reference that previous directory in a command you can use $OLDPWD like this:

 cp $OLDPWD/* .

Also have a look at help pushd, help popd and generally man bash.