Tips & Tricks


As already said, the comma operator can make life easy for you on GNU/Linux command line. Here are some examples :

Convert to lower case

Comma operator can be used to convert the whole string or only the first letter to lower case.

Here is an example :

$ words=”Example of comma OPERATOR”

$ echo ${words,}
example of comma OPERATOR

${words,,}
example of comma operator

So we see that through a single comma only the first letter was converted to lower case while through double comma, complete string was converted to lower case.

Use comma with file names

Comma operator can be used with file names. A couple of examples are shown below.

$ touch new_file{1,2,3}
himanshu@himanshu-Inspiron-1525:~/practice$ ls new_file*
new_file1 new_file2 new_file3

So we see that comma operator helped in creating three files easily.

Similarly, for one of the very popular work people do on command line is to rename files by adding .old or .new temporarily. You can save the time by doing something like :

mv my_filename.{old,new}

This will rename my_filename.old to myfilename.new.

Go Back to Menu