Regular expressions in bash

Using regular expressions(REs) is just like using REs in other common languages (C#, java, php, python...). REs in bash has two syntaxes, basic and extended, which are defined in IEEE POSIX standard. The basic syntax is the default mode in bash.

Commonly used metacharacters used in bash are

  • [ ]

    bracket expression. Used to match a selection of characters.

  • .

    dot sign matches any single character.

  • *, +, ?

    matches a preceding item zero or more times, one or more times, zero or one time, resp.

  • ^, $

    matches the empty string in the start, or the end of a line.


bash commands: tar

tar for converting a group of files into one archive, or recovering files from an archive

common options

tar command cannot be used alone. It must be used with one of -c, -r, -t, -u, -x.

create a tar file

tar -cf eulerProjects.tar /Users/shao/Info/github/eulerProjects
tar -czf eulerProjects.tar.gz /Users/shao/Info/github/eulerProjects

options used here: c:create, z: zip. f:file

-z and -j have to be used to compress files into gzip, and bzip2 formats! When recovering from an archive, such options are not necessary.