9.7 C
New York
Wednesday, October 16, 2024

8 straightforward methods to reuse instructions on Linux



You’ll be able to transfer to the start of the command utilizing ^a or to the top utilizing ^e. Within the instance beneath, I forgot to make use of the echo command after which went again to the start of the command with ^a and inserted the command.

$ Have a cheerful and really worthwhile day!
bash: Have: command not discovered...
$ echo Have a cheerful and really worthwhile day!

You can too use the left and proper arrow keys to maneuver left and proper. Transfer again to the command with the up arrow key, and transfer left and proper as wanted. When you’ve made your adjustments, press the return key to run the command you’ve simply modified.

^a strikes cursor to the start of the command, and ^e strikes the cursor to the top of the command.

5. Use solely the final string within the earlier command

If you wish to reuse the ultimate argument from the earlier command, you possibly can confer with it as !$ within the subsequent command. Right here is an instance:

$ echo this isn't a take a look at
this isn't a take a look at
$ echo !$
echo take a look at
take a look at

6. Use a reverse search to discover a command you’ve run beforehand

To discover a command in your command historical past that you simply wish to rerun, you possibly can maintain the Ctrl key and press r. You’ll then be prompted to enter the search textual content. The newest command containing that string shall be run. The string can embrace greater than a single phrase. The textual content of the unique command will seem to the precise as you kind.

(reverse-i-search)`completely satisfied': echo Have a cheerful and really worthwhile day!
(reverse-i-search)`very worthwhile': alias byebye="echo "Have a cheerful and really worthwhile day!""

7. Flip advanced instructions into aliases

Whenever you run a command that you simply’re doubtless to make use of continuously, you would possibly think about turning it into an alias. You’ll be able to create an alias with a command just like the one beneath, however it will solely preserve it working till you log off. Add it to your .bashrc file to make it out there each time you log in. Listed below are some examples:

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles