• Post Reply Bookmark Topic Watch Topic
  • New Topic

mv last directory mentioned in the command line

 
Giovanni Montano
Ranch Hand
Posts: 316
4
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i moved a directory like this
$ mv directoryFoo/ /home/me/projects/dudududadada/

then I wanted to go to this second directory without going trough all the
$ cd  /home/me/projects/dudududadada/
 
Tim Cooke
Sheriff
Posts: 3297
153
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this in a script or manually?

If in a script then I'd expect you'll already have the target dir in a variable which can be reused for the 'cd' step.

If manually then good old cut'n'paste may be your friend.

Or did you have something else in mind?
 
Giovanni Montano
Ranch Hand
Posts: 316
4
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:Is this in a script or manually?

If in a script then I'd expect you'll already have the target dir in a variable which can be reused for the 'cd' step.

If manually then good old cut'n'paste may be your friend.

Or did you have something else in mind?


Tim is not a script, but a manual command line.
I think a work around could be using mc.
But I am surprised i should copy and paste in linux, I do not want to touch the mouse, to point to the directory, this is not the bash philosophy
after all should be a daily task doing
mv  /directoryToMove /destinationDirectoryLongAdressDoNotWantToType
cd /destinationDirectoryLongAdressDoNotWantToType



 
Giovanni Montano
Ranch Hand
Posts: 316
4
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I do not have a bash now, maybe could work this?

mv /directoryToMove /destination| cd


 
Henry Wong
author
Sheriff
Posts: 22532
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

$ HW=/destinationAddressThatIsTooLongToTypeTwice/AndIDontWantToUseAScript; mv /sourcedir $HW; cd $HW

 
Tim Cooke
Sheriff
Posts: 3297
153
Clojure IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"!$" gets the last element of the previous command which enables you to do this:

Or as a single command:
 
Giovanni Montano
Ranch Hand
Posts: 316
4
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:"!$" gets the last element of the previous command which enables you to do this:

Or as a single command:

wow this is really Elegant Tim thank you.
smart also the variable assigment made by Henry, I did not think over, although Tim solution spare some typing!
great
 
Tim Cooke
Sheriff
Posts: 3297
153
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
Junilu Lacar
Sheriff
Posts: 10025
120
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find other similar useful commands if you search for bash history expansions
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!