Как да променяте бързо първата дума в баш команда?

Съдържание:

Как да променяте бързо първата дума в баш команда?
Как да променяте бързо първата дума в баш команда?

Видео: Как да променяте бързо първата дума в баш команда?

Видео: Как да променяте бързо първата дума в баш команда?
Видео: Как да Персонализираме YouTube Канал - YouTube 2024, Може
Anonim
Ако вашият работен процес е напълнен с много повтарящи се действия, никога не боли да търсите начини за подобряване и рационализиране на работния процес. Днешната публикация "SuperUser Q &A" има някои полезни предложения за читател, който иска да подобри работния си поток.
Ако вашият работен процес е напълнен с много повтарящи се действия, никога не боли да търсите начини за подобряване и рационализиране на работния процес. Днешната публикация "SuperUser Q &A" има някои полезни предложения за читател, който иска да подобри работния си поток.

Днешната сесия за въпроси и отговори ни идва с любезното съдействие на SuperUser - подразделение на Stack Exchange - обединяване на уеб сайтове с въпроси и отговори.

Скрийншотът е предоставен от Мат Джойс (Flickr).

Въпроса

Монетата за четец SuperUser иска да знае как бързо да променя първата дума в командата bash:

I would like to improve my workflow in bash and realized that I often want to execute the same command to a different executable.

Some Examples

1.) Git

2.) Bash
2.) Bash
Image
Image

I know that I can hit Ctrl+a then Del to remove the first word, but I am wondering if there is a quicker way to do it.

Има ли по-бърз начин монетата да промени първата дума в командите за баш?

Отговорът

Специалистите на SuperUser Spiff, Hastur, jjlin. и Густаво Хиралдес имат отговор за нас. Първо, Spiff:

!$ expands to the last word of your previous command. So you could do:

Or
Or
Your examples happened to only repeat the last word, so !$ worked fine. If you actually had a lot of arguments that you wanted to repeat, and you just wanted to change the first word, you could use !*, which expands to all words of the previous command except the zeroth.
Your examples happened to only repeat the last word, so !$ worked fine. If you actually had a lot of arguments that you wanted to repeat, and you just wanted to change the first word, you could use !*, which expands to all words of the previous command except the zeroth.

See the “HISTORY EXPANSION” section of the bash man page. There is a lot of flexibility there.

Последвано от отговора на Hastur:

I would like to add a warning (see the answer from Spiff above). With !$, you do not have full visual control of the line you are running. The results can be harmful sometimes, especially if you incur a misprint. It takes what it needs from the history to expand on.

So if you write the last command with a blank space at the beginning, then this command will probably not finish from the history. When you execute your new command with !$, the shell will not take the parameters from the last command line typed, but only from the last part of the history.

Here are some more helpful words and commands.

Тогава отговорът от jjlin:

Ctrl+a to go to the beginning of the line, then Alt+d to delete the first word.

И нашият последен отговор от Густаво Хиралдес:

The delete word shortcut is actually Meta+d, and Meta is usually mapped to Alt on Linux machines. On platforms where this is not the case, an alternative to get the Meta modifier is to use Esc as a prefix. You can read more about the Meta Key here.

Имате ли нещо, което да добавите към обяснението? Звучи в коментарите. Искате ли да прочетете повече отговори от други потребители на Stack Exchange? Вижте цялата тема на дискусията тук.

Препоръчано: