How to reuse commands with different arguments on a Bash command line
If you'd like to rerun a command on a Bash command line with a different set of arguments without retyping the entire command or manually replacing the arguments one-by-one, you can do so using the "!!:gs" syntax demonstrated below.
Some Unix commands can be lengthy to type and tedious to manually modify, for example:
find . -type f -name "*Mac*" > ~/Desktop/Mac-list.txt
The above command would search the current directory and its subdirectories for files with "Mac" anywhere in their names and write the results to a text file named "Mac-list.txt" on the user's Desktop.
If you wanted to change this command to find all files containing "Ubuntu" anywhere in their names and write the results to a text file named "Ubuntu-list.txt" on the user's Desktop, you could press the "Up Arrow" key to display the last command, use the arrow keys to move the cursor to each instance of the term "Mac", delete it, and replace it with "Ubuntu".
Alternatively, you could use a simple replace statement like the one below:
!!:gs/Mac/Ubuntu/
... to rerun the last command ("!!") after replacing all instances of "Mac" with "Ubuntu".