You are not logged in.

#1 2008-12-28 17:19:59

patogen
Member
Registered: 2008-05-11
Posts: 86

Reuse command

I'm wondering if there is a simple way to re-use commands when using the terminal. Consider the following:

$ mkdir /mnt/photo/2008
$ mv *.jpg /mnt/photo/2008

Doing this I used /mnt/photo/2008 twice, is there some simple way I can re-use what I issued to mkdir, in this case /mnt/photo/2008. The shell is zsh, I know I can assign a variable but this does not save time when just doing that ...


We met up with the aliens and guess what? They have no word for fluffy!

Offline

#2 2008-12-28 17:21:39

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Reuse command

Use the up arrow to get the previous command, C-a to move to the beginning of the line, delete the first word and type the new command?

Oh, there's also some fancy things you can do with the history command and '!' keyword. I never learned those though.

Last edited by peets (2008-12-28 17:22:23)

Offline

#3 2008-12-28 17:29:51

tdy
Member
From: Sacremende
Registered: 2008-12-14
Posts: 440

Re: Reuse command

$ mkdir /mnt/photo/2008
$ mv *.jpg !$

Offline

#4 2008-12-28 17:30:27

patogen
Member
Registered: 2008-05-11
Posts: 86

Re: Reuse command

peets wrote:

Use the up arrow to get the previous command, C-a to move to the beginning of the line, delete the first word and type the new command?

Oh, there's also some fancy things you can do with the history command and '!' keyword. I never learned those though.

The fancy stuff is what I want. I've tried to google, but I guess I use the wrong search words


We met up with the aliens and guess what? They have no word for fluffy!

Offline

#5 2008-12-28 17:36:23

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: Reuse command

patogen wrote:

I've tried to google, but I guess I use the wrong search words

man history

Offline

#6 2008-12-28 17:47:35

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Reuse command

Also Alt+. (dot) by default to fill it in in the prompt.

Offline

#7 2008-12-28 17:52:15

finferflu
Forum Fellow
From: Manchester, UK
Registered: 2007-06-21
Posts: 1,899
Website

Re: Reuse command

tdy wrote:
$ mkdir /mnt/photo/2008
$ mv *.jpg !$

That's the right answer, but it got ignored, why? tongue


Have you Syued today?
Free music for free people! | Earthlings

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery

Offline

#8 2008-12-28 18:06:05

patogen
Member
Registered: 2008-05-11
Posts: 86

Re: Reuse command

finferflu wrote:
tdy wrote:
$ mkdir /mnt/photo/2008
$ mv *.jpg !$

That's the right answer, but it got ignored, why? tongue

Sorry, must have been posted while I wrote the earlier msg. Thank you very much tdy and the rest of you smile


We met up with the aliens and guess what? They have no word for fluffy!

Offline

#9 2008-12-28 18:17:45

tdy
Member
From: Sacremende
Registered: 2008-12-14
Posts: 440

Re: Reuse command

Procyon wrote:

Also Alt+. (dot) by default to fill it in in the prompt.

Didn't know about this one.. quite handy.  Thanks!

Last edited by tdy (2008-12-28 18:19:07)

Offline

#10 2008-12-28 18:34:57

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Reuse command

@tdy: there's a full list in man readline

Offline

#11 2008-12-28 23:00:06

Shaika-Dzari
Member
From: Québec, Canada
Registered: 2006-04-14
Posts: 436
Website

Re: Reuse command

tdy wrote:
$ mkdir /mnt/photo/2008
$ mv *.jpg !$

Wow!

Great! Thank you tdy smile

Offline

#12 2008-12-28 23:52:13

kludge
Member
Registered: 2008-08-03
Posts: 294

Re: Reuse command

another trick that i use quite frequently is the ^ for substitution.  for instance:

myprompt > ls /etc/foobar.conf
myprompt > ^ls^nano

it's also really handy for correctly spelling mistakes in the previous command.  i think it respects normal bash quoting, so ^mkdir^'mv *.jpg' might work for you.


[23:00:16]    dr_kludge | i want to invent an olfactory human-computer interface, integrate it into the web standards, then produce my own forked browser.
[23:00:32]    dr_kludge | can you guess what i'd call it?
[23:01:16]    dr_kludge | nosilla.
[23:01:32]    dr_kludge | i really should be going to bed.  i'm giggling madly about that.

Offline

Board footer

Powered by FluxBB