- If your AI-generated code becomes faulty, who faces the most liability exposure?
- These discoutned earbuds deliver audio so high quality, you'll forget they're mid-range
- This Galaxy Watch is one of my top smartwatches for 2024 and it's received a huge discount
- One of my favorite Android smartwatches isn't from Google or OnePlus (and it's on sale)
- The Urgent Need for Data Minimization Standards
8 easy ways to reuse commands on Linux
You can move to the beginning of the command using ^a or to the end using ^e. In the example below, I forgot to use the echo command and then went back to the beginning of the command with ^a and inserted the command.
$ Have a happy and very profitable day!
bash: Have: command not found...
$ echo Have a happy and very profitable day!
You can also use the left and right arrow keys to move left and right. Move back to the command with the up arrow key, and move left and right as needed. Once you’ve made your changes, press the return key to run the command you’ve just modified.
^a moves cursor to the beginning of the command, and ^e moves the cursor to the end of the command.
5. Use only the last string in the previous command
If you want to reuse the final argument from the previous command, you can refer to it as !$ in the next command. Here is an example:
$ echo this is not a test
this is not a test
$ echo !$
echo test
test
6. Use a reverse search to find a command you’ve run previously
To find a command in your command history that you want to rerun, you can hold the Ctrl key and press r. You will then be prompted to enter the search text. The most recent command containing that string will be run. The string can include more than a single word. The text of the original command will appear to the right as you type.
(reverse-i-search)`happy': echo Have a happy and very profitable day!
(reverse-i-search)`very profitable': alias byebye="echo "Have a happy and very profitable day!""
7. Turn complex commands into aliases
When you run a command that you’re likely to use frequently, you might consider turning it into an alias. You can create an alias with a command like the one below, but this will only keep it working until you log out. Add it to your .bashrc file to make it available every time you log in. Here are some examples: