useful bash stuff #1

useful bash stuff

Here's some simple but very useful stuff you can do in bash.

create multiple things at once

By using {} around a comma-separated list, you can create multiple files or directories at once.

For example, this:

mkdir foo/today
mkdir foo/tomorrow
mkdir foo/yesterday

can be replaced with:

mkdir foo/{today,tomorrow,yesterday}

almost the same command

Say you typed this to see files from a certain month.

ls 2016-07-*.txt

Now, if you want to see files for the previous month, you could type this:

ls 2016-06-*.txt

Or, you could just type this:

^07^06

putting them together

Here's an example showing both being used:

 $ touch foo{1,2,3}.txt

 $ ls
foo1.txt  foo2.txt  foo3.txt

 $ touch foo{1,2,3}.log

 $ ls
foo1.log  foo1.txt  foo2.log  foo2.txt  foo3.log  foo3.txt

 $ ls *.txt
foo1.txt  foo2.txt  foo3.txt

 $ ^txt^log
ls *.log
foo1.log  foo2.log  foo3.log

Comments !

blogroll

social