• Post Reply Bookmark Topic Watch Topic
  • New Topic

mv last directory mentioned in the command line  RSS feed

 
Ranch Hand
Posts: 451
7
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/

 
Marshal
Posts: 4355
280
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: 451
7
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: 451
7
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



 
author
Marshal
Posts: 23441
138
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
Marshal
Posts: 4355
280
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: 451
7
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
Marshal
Posts: 4355
280
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
Sheriff
Posts: 11752
191
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
Marshal
Posts: 4355
280
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!