Quick Link: Linux Command Line Examples
A certain Ben Emson has blogged some great examples of putting BASH commands (Linux commands) to work. He calls them scripts, but really they’re recipes or snippets that you can include in your scripts, or just use directly on the command line.
These 18 Useful bash scripts for web developers include recipes for dealing with non-standard files submitted by a client like “Get all JPG files and create the appropriate HTML list tags for them and add them to a file”, and “Bash command to remove spaces from filenames.”
Some of the general techniques Emson employed include:
- Using “for … in …” to loop through all of the files in a directory,
- Using the transpose command (tr) for converting names to lower case, changing spaces to underscores, etc.,
- Using bash commands within a pair of accent symbols (` `) to pre-process text before executing it as (part of) a command,
- A trick for incrementing a variable within a loop (see the comments, too), and
- Using pbcopy to place text into the clipboard.
- Command History (Linux & Mac OS X)
- The ALIAS Command Saves Repetitive Typing
- ZIP Up Files from the Command Line