Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
749 views
in Technique[技术] by (71.8m points)

linux - Is there any shortcut to reference the path of the first argument in a MV command?

I often find myself using mv to rename a file. E.g.

mv app/models/keywords_builder.rb app/models/keywords_generator.rb

Doing so I need to write (ok, tab complete) the path for the second parameter. In this example it isn't too bad but sometimes the path is deeply nested and it seems like quite a bit of extra typing.

Is there a more efficient way to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

And another way: brace expansion.

mv app/models/keywords_{builder,generator}.rb

In general,

before{FIRST,SECOND}after

expands to

beforeFIRSTafter beforeSECONDafter

So it's also useful for other renames, e.g.

mv somefile{,.bak}

expands to

mv somefile somefile.bak

It works in bash and zsh.

More examples:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...