Nuxified

FOSS technologies explained

  • Useful Articles
  • Blogs
  • Images
  • Tips
  • Archives

March 25, 2007

Curly Braces are Damn Useful Things

In the bash shell curly braces { and } are surprisingly useful things to reduce typing.

With the mkdir command they help you create trees of directories in one command. For instance:

mkdir -p foo/{bar,baz,goo/loo/imp}/build

mkdir -p foo/{bar,baz,goo/loo/imp}/build

will create the following directory structure:

foo/bar/build
foo/baz/build
foo/goo/loo/imp/build

foo/bar/build foo/baz/build foo/goo/loo/imp/build

The curly braces can also be used with other commands such as cp and mv. E.g. you want to move file foo/bar/a.out to foo/bar/hello you can use the following command:

mv foo/bar/{a.out,hello}

mv foo/bar/{a.out,hello}

The source file (a.out) is separated from the destination file (hello) within the curly braces by the comma (,).

The curly braces are used in much the same way with cp. For example if you want to copy foo/bar/hello to foo/baz/goodbye you would use the following command:

cp foo/{bar/hello,baz/goodbye}

cp foo/{bar/hello,baz/goodbye}

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Article by dylunio / Community Blogs

Learn Unix

I run Unix Tutorial website and help anyone interested to pick up Unix skills. If you have questions or just want to share your ideas – please join the Unix Tutorial on Facebook.

Tech Stack Solutions

Tech Stack Solutions is my company that provides Unix support. Sign up or simply get in touch to find out how I can help!

Search this Website

You May Also Like

Recent Posts

  • Advice on using SUDO
  • FFmpeg 4.0
  • KDE Plasma 5.9.0 Release
  • How to Install Ubuntu Linux without a DVD or USB
  • How to Securely Save All Your Passwords with Keepass
  • 9 Signs You Should Use Linux on Your Computer
  • The Easiest Way to Optimize Your MySQL Database Performance
  • Setting up a Linux Web Development Environment in Windows
  • Hunting Down Disk Space Hogs on Linux Command Line
  • 6 Simple Android Apps for Monitoring and Managing Your Linux Server

Archives

Categories

  • Community Blogs
  • Images and Screenshots
  • News
  • Technical Topics
  • Useful Articles

Basic Unix Commands

Basic Unix Commands
  • ls command
  • mkdir command
  • man command in unix
  • cd command - change directory
  • uname command

Advanced Unix Commands

Advanced Unix Commands
  • ln command - symlinks
  • tune2fs unix command - filesystem parameters
  • du command - disk usage
  • lsb_release command
  • find unix command

Unix Reference

Unix Reference
  • SSH port forwarding
  • unix commands
  • visudo tutorial
  • mtime unix
  • lrwxrwxrwx
  • Unix Tutorial digest

Unix Books

Unix Tutorials

Unix How-Tos
  • check raspbian version
  • autostart in KVM
  • List files in Ubuntu package
  • check CentOS version
  • create bootable USB in MacOS
  • Useful Articles
  • Blogs
  • Images
  • Tips
  • Archives

Copyright © 2022 · Education Pro Theme on Genesis Framework · WordPress · Log in