Brief introduction of CP and MV Collocation in Linux {,} usage in shell

Source: Internet
Author: User
Tags extend

This article mainly introduced the introduction of Linux in the CP and MV Collocation {,} in the use of the shell, the author cited four such braces to expand the example, the need for friends can refer to the

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

?

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

Or is

?

1 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:

?

1 Echo Foo{1,2,3}.txt

The output is as follows:

?

1 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}

?

1 2 3 4 5 6 7 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:

?

1 Cp-v file1.txt File1.txt.bak

If you use brace expansion to save time, enter:

?

1 Cp-v File1.txt{,.bak}

The output is as follows:

?

1 File1.txt-> File1.txt.bak

More curly braces extension examples are as follows:

4. If we implement:

?

1 $ 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.

?

1 $ 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:

?

1 $ 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.