Je mets ça là parce que je m'en rappelle jamais :
This guide explains how to repeat the last command with a substitution under bash shell for command line arguments under Unix like operating systems.
Bash History: Correct / Repeat The Last Command With a Substitution
by Vivek Gite on August 12, 2012 last updated February 23, 2016
in BASH Shell, Linux, UNIX
I often type the wrong command as follows under Linux bash shell:
rsync -av dir1 email@example.com:/path/to/dir1
cp -av file1*.txt file2*.txt /path/to/dest
I need to correct those command as follows:
rsync -av dir5 firstname.lastname@example.org:/path/to/dir1
cp -av delta1*.txt delta2*.txt /path/to/dest
How do I replace dir1 with dir5 or file with delta and repeat the last command under bash shell?
The bash shell supports both history search and replace operations. The bash (and many other modern) shell provides access to the command history, the list of commands previously typed. The bash shell supports a history expansion feature found in other shell such as csh.
Syntax: Bash history search and replace the command args
The syntax is as follows for quick substitution and repeat the last command, replacing word1 with word2:
In this example, I’m trying to copy a file called youtube-demo-andriod-app-part1.avi to /backup directory
$ cp youtube-demo-andriod-app-part-102.avi /backup/
To repeat the last command with a substitution: