In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the usage of cp and mv collocation {,} in Linux". The explanation in this article is simple, clear and easy to learn and understand. Please follow the editor's train of thought to study and learn the usage of cp and mv collocation {,} in Linux in shell.
You will often see the following command curly braces to extend the function of Brace expansion {} shell in blogs or forums
Cp / etc/httpd/httpd. {, .bakup}
Or
Mv resume {z,}. Doc
So, what does it mean in the uinx / linux shell command? What does it do?
{} has no practical meaning, but it can often be used to generate various groups as a Brace expansion (curly braces extension or curly braces extension). The following is the translation from GNU/BASH man page:
Brace expansion (curly braces extension, or curly braces extension) is a mechanism for randomly generating string combinations. This mechanism is similar to the extension of a file, but does not require a file with a response. The Brace expansion (curly brace extension or curly brace extension) pattern is an optional preamble (leading character) followed by a series of comma-separated strings contained in a pair of curly braces followed by an optional postscript (print programming language). Preamble (leading character) is added before each string in curly braces, and postscript (print programming language) is appended to each result string, extending from left to right. Curly braces extensions can be nested. The results of the extended string are not sorted; instead, the order from left to right 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
two。 You can also use the following additional example to "create" a parameter in the command to save input time and improve 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 Brace expansion (curly braces extension or curly braces extension) to copy, rename files, or back up files, create directories, and so on. In the following example of habitual use, back up file1.txt as file2.txt.bak and type:
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 examples of curly braces extensions are as follows:
4. If we execute:
$cp / etc/apt/sources.list / etc/apt/sources.list.bak
The two / etc/apt/sources parts are the same, and in order to enter / etc/apt/sources twice less, curly braces extend the parameter. In addition, you can use curly braces to expand parameters to improve efficiency when renaming, backing up files, and creating links.
Brace extensions, that is, braces enclosed, parameters separated by commas are extended to independent parameters.
$cp / etc/apt/sources. {list,list.bak}
When Shell interprets, it automatically expands the following parameters to two, which becomes the same complete command as above.
Of course, it can be easier to take list into account and write nothing before the comma, as follows:
$cp / etc/apt/sources.list {, .bak}
In this way, there is nothing before the comma, then the parameters remain the same, and the ones after the comma continue to expand.
Thank you for your reading. the above is the content of "the usage of cp and mv collocation {,} in shell" in Linux. After the study of this article, I believe you have a deeper understanding of the usage of cp and mv collocation {,} in shell in Linux, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.