For example, to rename
file.bak where file is from the stdin:
xargs mv $file $file.bak
One solution is to write a small script like move.sh
file=$1 mv $file $file.bak
and invoke move.sh by xargs
However, it is very inconvenient that the move.sh should already there.
Are there other better methods?
You can use this trick:
xargs -I@ bash -c "mv @ @.bak"'
xargs to replace ‘@’ in the command with the argument:
Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate
input items; instead the separator is the newline character. Implies
-x and -L 1.
The command for
xargs here is actually
bash with arguments ‘-c “mv @ @.bak”‘ where ‘@’ will be replaced by