# Bash Cheat Sheet

This is a collection of bash scripts solving a series of eclectic use cases which we have encountered in the past. These instructions use linux commands and directory structures.

## Replace String in All Files in Directory

Especially when coding you may find yourself changing a variable name or some library path, which is referenced in multiple places across multiple files. sed and grep come in handy here, and can help you do all that menial name changing in one simple line from your terminal:

Please note that the slashes (/) in the above code are part of the sed syntax and should stay the same independently of your text change. Also note that some characters need escaping in sed.

## Check Sequence of Files for Missing Entries

Say you are keeping your photography files in a single directory and have them incrementally numerated. And say you would like to check if there is any index number wherefore neither a .JPG nor a .NEF file is present. The following script would help you find any such indices starting form DSC_a0000 and up to DSC_a8888:

This command can also be easily modified to suit slightly different needs - say you are only interested in indices for which .JPG files are missing:

Or specifically indices for which a .NEF file is present but a .JPG file is missing:

## Append Text Line to Text File

Quotation marks are optional here and come in handy only if your code snippet contains many special characters (;, \, etc.). You can escape single characters by prefixing them with a backslash (\).

full history here