• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mv last directory mentioned in the command line

 
Ranch Hand
Posts: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/

 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


mv /directoryToMove /destination| cd



 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


 
Tim Cooke
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 606
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find other similar useful commands if you search for bash history expansions
 
Tim Cooke
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic