# Unix commands I need often

### but which are tedious to work anew out each time

General, not OSX-specific or linux-specific, and see also shell to yak-shave your way into whole other shell paradigms. See, more specifically, fish and bash.

I suppose if I were a good person I'd submit the following to tldr or bro pages or version my .cheats folder in my dotfile repo, but I'm now exhausted and just want to go home.

## Vars, expansions, filenames, whitespace hell

See bash or fish depending on your choice of shell.

Or avoid both by using some other utility. rename is a script that makes renaming work how you imagine it should, avoiding the mysterious punctuation stew at least somewhat.

rename -s html txt *.html


NB depending on your distro you may get some other systutil rename which is much less powerful than the one I linked to, albeit still often powerful enough.

## Misc

### Trailing whitespace

A shell script to remove trailing whitespace from a file - put this in trimspace.sh:

#!/bin/bash
# OSX version
sed -i '' -e's/[[:space:]]*$//' "$1"

#!/bin/bash
# GNU version
sed -i -e's/[ \t]*$//' "$1"


Then you can trim trailing whitespace from your… whatever… by putting this line in there:

find . -type f -print0 | xargs -0 -I {} trimspace.sh \{\}


### find common diacritics in filenames because of some kind of unicode strife

find . -iname "*[üñàáèéöäçã]*"


### sync only if drive present

test -d  /Volumes/syncdrive/ && rsync --delete -avz \
192.168.0.1:/path/to/stuff/ /Volumes/syncdrive/


## Meta-command-lines

Command lines to command your command lines:

### tldr

tldr:

New to the command-line world? Or just a little rusty? Or perhaps you can't always remember the arguments to lsof, or tar?

$npm install -g tldr$ tldr tar


### cheat

cheat

…allows you to create and view interactive cheatsheets on the command-line. It was designed to help remind *nix system administrators of options for commands that they use frequently, but not frequently enough to remember.

$pip install cheat$ cheat tar


### bro pages

…are a highly readable supplement to man pages. Bro pages show concise, common-case examples for Unix commands. The examples are submitted by the user base, and can be voted up or down; the best entries are what people see first when they look up a command.

bropages is conspicuously silent on why they chose “bro”, although they do have perhaps the nicest social editing workflow to compensate for the unfortunate choice.

$gem install bropages$ bro tar


### how do i

Are you a hack programmer? Do you find yourself constantly Googling for how to do basic programing tasks?

Suppose you want to know how to format a date in bash. Why open your browser and read through blogs (risking major distraction) when you can simply stay in the console and ask howdoi

$pip install howdoi$ howdoi tar


Seems to search the internet for you, and not be command-line specific, which is broader in scope than some of the other entrants here, but also noisier.

### commandlinefu

is basically bro pages bit with a more esoteric API for querying and no integration of the social features.

\$ curl https://www.commandlinefu.com/commands/matching/tar/dGFy/sort-by-votes/plaintext


The dGFy bit is a base64 encoding of tar for some godawful reason.

### bash hackers wiki

bash hackers wiki: avoid its the paradigmatically awful bash manual