Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

mv last directory mentioned in the command line  RSS feed

 
Giovanni Montano
Ranch Hand
Posts: 388
6
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: 3746
208
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: 388
6
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: 388
6
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: 23260
124
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: 3746
208
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: 388
6
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: 3746
208
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
Junilu Lacar
Sheriff
Posts: 10929
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac 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
 
Tim Cooke
Sheriff
Posts: 3746
208
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know, before this thread started I didn't know how to do this and it took me a little research to figure it out in order to provide an answer for Giovanni. Since then I use it all the time, I mean really most days I use it.

So in the process of helping someone else learn something, I learned something genuinely useful myself. How wonderful is that!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!