Matt Fiddles

Life's so vast, there's just so much to do...

User Tools

Site Tools


FORD Tell me Arthur...
FORD This boulder we're stuck under, how big would you say it was? Roughly?
ARTHUR Oh, about the size of Coventry Cathedral.
FORD Do you think we could move it? (Arthur doesn't reply) Just asking.

- Ford and Arthur in a tricky situation, Fit the Eighth.

Where will you go today?

"Many of the truths that we cling to depend on our point of view."

- OB1-Wan Kenobi

Bash Tips


Get the current unix time:

[user]$ date +%s

Get the unix time of a specific time

[user]$ date -d "8:35am Mar 3, 1995" +%s

Convert a unix time (from 1970) to human readable time:

[user]$ date -d @1458349599
Fri Mar 18 19:06:39 MDT 2016


Traps and Signals

Errors and Signals and Traps

Verify if a bash function exists

type -t function
# type is a shell builtin
if type __function | grep -q '^function$' 2>/dev/null; then

Display the longest line in a file (careful!):

cat /file | awk '{print length, $0}' | sort -nr | head -1

Show the line number of the longest line (it will be the second number, adjust cut -d1-20 if needed):

cat -n /file | awk '{print length, $0}' | sort -nr -k 1 | head -1 | cut -c1-20

bash random numbers using shuf

# output a number between 0 and 100
shuf --random-source=/dev/urandom -i 0-100 -n 1

Find Files

Find files between a certain size“

find /dir -type f -size +100k -size -512k

Find files that have hard links:

find /dir -type f -links +2

Find empty directories

find /dir -type d -empty

When to use quotes

For this error: base64: invalid input use this:

  base64 -di


computers/linux/bash-tips.txt · Last modified: Sep 20, 2017 (13 months ago) by Matt Bagley