Introduction to the CP and MV Collocation in Linux {,} in the shell of the use of _linux shell

Source: Internet
Author: User
Tags extend

Often see commands like the following in blogs or forums the curly braces extend brace expansion {} Shell functions

  Cp/etc/httpd/httpd. {,. Bakup}

Or is

  MV Resume{z,}.doc

So what does it mean in the uinx/linux shell command?

{} has no practical meaning, but can be used as a brace expansion (curly braces extension or curly braces extension) to produce various groups. Here's what's translated from the Gnu/bash man page:

Brace expansion (curly brace extension or curly braces extension) is a mechanism for randomly generating string combinations. This mechanism is similar to the file extension, but does not require a response file. The brace expansion (curly brace extension or curly brace extension) pattern is an optional preamble (leading character) followed by a series of comma-delimited strings, enclosed in a pair of curly braces, followed by an optional PostScript (print programming language).  Preamble (leading characters) are added before each string in curly braces, and PostScript (the Print programming language) is appended to each result string, extending from left to right. Curly brace extensions can be nested. The results of the extended string are not sorted; instead, the left to right order is preserved.

1. For example, enter the following command in the terminal:

  Echo Foo{1,2,3}.txt

The output is as follows:

Foo1.txt Foo2.txt Foo3.txt

2. You can also use the attached example below to "create" a parameter in the command to save time for input and increase productivity:
Echo File.txt{,.bak}

  Echo File-{a. D}.txt

  echo mkdir-p/apache-jail/{usr,bin,lib64,dev}

  echo CP httpd.conf{,.backup}

  echo MV delta.{ Txt,doc}

3. You can use the brace expansion (curly braces extension or curly braces extension) to copy, rename, or back up files, or create a directory. In the following habitual use example, the File1.txt is backed up as File2.txt.bak and entered:

CP-  v file1.txt file1.txt.bak

If you use brace expansion to save time, enter:

CP-  v  File1.txt{,.bak}

The output is as follows:

File1.txt-> File1.txt.bak

More curly braces extension examples are as follows:

4. If we implement:

$ cp/etc/apt/sources.list     /etc/apt/sources.list.bak

These two/etc/apt/sources parts are the same, in order to enter two times less/etc/apt/sources, brace extension parameters. It is also possible to use curly braces to extend the parameters of the normal renaming, backing up files, and creating links to improve efficiency.

Curly braces extend, which is surrounded by braces, and arguments separated by commas extend to multiple independent arguments.

$ cp/etc/apt/sources. {List,list.bak}

The Shell, when interpreted, automatically expands the following arguments to two, and becomes the complete command as above.

Of course, it can be simpler to take the list into account and write nothing before the comma, as follows:

$ Cp/etc/apt/sources.list{,.bak}

So there is nothing in front of the comma, then the parameters will remain the same, the comma after the extension.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.