Matt Fiddles

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

User Tools

Site Tools


Sidebar

"There are of course many problems connected with life, of which some of the most popular are `Why are people born?'

`Why do they die?' `Why do they spend so much of the intervening time wearing digital watches?'"

- The Book.



Where will you go today?

Luke can't levitate his X-Wing out of the bog.

Luke Skywalker: "I can't. It's too big."

Yoda: "Size matters not. Look at me. Judge me by my size, do you? Hmm? Hmm. And well you should not. For my ally is the Force, and a powerful ally it is. Life creates it, makes it grow. Its energy surrounds us and binds us. Luminous beings are we, not this crude matter. You must feel the Force around you; between you, me, the tree, the rock, everywhere. Yes, even between the land and the ship."
computers:linux:bash-tips

Bash Tips

Date

Get the current unix time:

[user]$ date +%s
1458349599

Get the unix time of a specific time

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

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

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

Online: http://www.onlineconversion.com/unix_time.htm

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

http://www.cyberciti.biz/faq/bash-shell-scripting-find-out-if-function-definedornot/

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

https://stackoverflow.com/a/15490765

colors: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html

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