Conserving commands to a file utilizing Ctrl-x-e

Uncategorized

One extremely interesting technique that you might not know is that you can type a line of text (presumably a command) on the Linux command line and right away save it to a file by pushing just 3 secrets. The editor that will open will depend upon your $EDITOR setting that you can view utilizing the command revealed listed below:

$ echo $EDITOR nano

If you choose to use a different editor, utilize a command like this before typing or returning to the command that you want to conserve:

$ export EDITOR=vi

And don’t forget to save this modification to your.bashrc (or other start-up file) if you wish to make this modification irreversible. For instance:

$ echo “EDITOR=vi” >> ~/. bashrc

As an example, say you have actually simply made up a particularly complex command, verified that it works as you anticipated, and now wish to wait in a file so that you can use it any time you desire without having to reinvent it. Is that difficult? No, it’s easy! Press the up-arrow key as if you plan to run the command again, however, instead, hold the Ctrl key and press both the “X” and “E” secrets. This is often referred to as the Ctrl-x-e sequence. When you do this, the command should open in the editor.In the example revealed listed below, the text is shown in nano. The commands at the bottom of the screen show nano’s command options. If you pick ^ O, you will be prompted to save the command in/ tmp with a random file name. Back over the suggested file name and you can wait to your house or current area in the file system. It will ask you to confirm the”different”file name. After that, you can exit the editor and your command will be sitting in a declare your later usage. You will, as you most likely suspect, need to make the file executable considering that Linux doesn’t do this without a chmod command. It will look something like this when you use nano: echo This is a command that I want to save in a file ^ G Aid ^ O Write Out ^ W Where Is ^ K Cut ^ T Carry Out ^ X Exit ^ R Read File ^ Replace ^ U Paste ^ J Justify Here’s a simple example. Say you used a command like the one revealed below to show the days of the week as they are output by the cal command:$ cal|head -2|tail -1 Su Mo Tu We Th Fr Sa To conserve the command in a file after running, push

the up arrow secret without pressing the enter essential to get back to it.$cal|head -2 |

tail -1 Next, get in the Ctrl-x-e sequence while you

‘re still placed at the end of the line. Doing this will open the command in the editor. You can enter ^ O to save it, however if you back over the recommended file name( e.g.,/ tmp/bash-fc.9 RfMEe”) and type in something like”days_of_week” or “~/ days_of_week “if you’re not in your house directory site, you can wait to your existing place instead of to/ tmp. Then type ^ X to exit. In truth, you can utilize this method for any command that is still in your command history. Use the up arrow to get back to the command and then deploy the Ctrl-x-e trick.Wrap-up There are lots of methods to …

Source

Leave a Reply

Your email address will not be published. Required fields are marked *