Thursday 20 February 2014

explain-brace-expansion-in-cp-mv-bash-shell-commands


$ touch {1..10}.txt

$ ls
10.txt  1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt

## The following command will rename fileName.txt to fileName.bak

$ for i in {1..10};do mv $i.{txt,bak}; done 

$ ls
10.bak  1.bak  2.bak  3.bak  4.bak  5.bak  6.bak  7.bak  8.bak  9.bak




$ man bash

NOTE:

Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to filename expansion, but the file names generated need not exist. Patterns to be brace expanded take the form of an optional preamble, followed by either a series of comma-separated strings or a seqeunce expression between a pair of braces, followed by an optional postscript. The preamble is prefixed to each string contained within the braces, and the postscript is then appended to each resulting string, expanding left to right.


Ref Link:

http://www.cyberciti.biz/faq/explain-brace-expansion-in-cp-mv-bash-shell-commands/

How to: http://www.cyberciti.biz/faq/

No comments:

Post a Comment