--------------------------------------------------------------------------------
Quick Urgent Information
--------------------------------------------------------------------------------
p.s. Mac OS is BSD. All GNU packages will be missing
cure: https://brew.sh/   "brew install"


--------------------------------------------------------------------------------
Ia. Date & Time
--------------------------------------------------------------------------------
$ cal 		#calendar for current month
$ cal 2020      #calendar for this year 
$ date -u       #time in UT

--------------------------------------------------------------------------------
Ib. Looking up tables and files
--------------------------------------------------------------------------------
$ eman ascii	  #quick look up of ascii table
$ man man         #the top of the help pages

$ file filename         #determine type of file

$ locate file	#quick search for files with name "*name*"
$ whereis program	#quick search for programs
$ which program         #locate program in user's path

$ apropos keyword       #search "whatis" database for "keyword"
       whatis  searches  a set of database files containing short
       descriptions of system commands for keywords and displays
       the result on the standard output.  Only complete word matches
       are displayed.

$ tree     	#graphical overiew of directory structure

--------------------------------------------------------------------------------
Ic. Powerful commands or keystrokes
--------------------------------------------------------------------------------

$ cntrl "l" (ell)  ... clear screen
$ cntrl "u" (u) .....  clear line
$ cd -          #takes you to previous directory
$ !!            #repeat previous command
$ mv !$ a.tmp	#move the last file (parameter) on previous line to a.tmp
$ !mv:p         #print last command starting with "mv"
$ : > a.txt     #clear file a 
$ true > a.txt  #clear file a 

--------------------------------------------------------------------------------
Id. Emergencies
--------------------------------------------------------------------------------
You have deleted a paragrahp in vi by mistake. You "u"ndo but it
gets worse. Use "cntrl-r" to recover.

You are unable to delete or even list some file which was created
by a runaway program. One such example is a file starting with "-".
Use the Finder to locate the file and "command delete".

When you find "sed" is not producing expected results then the first
reason is that there are characters which are not displayed on the
screen, hidden characters.

There are several ways to see non-print and un-printable characters

$ cat -e filename  (does not show "\t")
$ cat -t filename  (useful to see "\t")
$ cat -v filename  (displahy non-print as ^X for cntr-X)

in vi 
:set list          (useful)

--------------------------------------------------------------------------------
Ie. DOS & Unix files
--------------------------------------------------------------------------------
The end of a line (record) in DOS is signified by two characters, \r\n
where \r is the carriage return (0x0D) and line return (0x0A). In
Unix and modern Mac OS (which adopted Unix as the foundation) the end of
the line is \n. 

To convert DOS to Unix use one of the following
$ tr -d '\r' < infile > outfile
$ sed 's/\r//' infile > outfile 

--------------------------------------------------------------------------------
If. The last line in a file appears to be missing
--------------------------------------------------------------------------------

Some programs can create files with the last character in
the file not an "\n". In this case, the last line is not recognized
by Unix tools. So you will get a count which is one less when you
execute "wc"

$ echo -n "a\nb" 
a
b

$ echo -n "a\nb" > a.txt

$ wc  a.txt
       1       2       3 a.txt

We see that, per wc, the file has three characters, two words and
one line.

Do not panic. The cure is use the editor and add in the last "\nl"
or process it through any streaming utility, e.g.

$ awk 1 a.txt > b.txt
(problem fixed!)


--------------------------------------------------------------------------------
IIa. Spelling (not sophisticated) & Dictionary (quite good)
--------------------------------------------------------------------------------

$ look persni 	#looking for persnickety  
$ dict hello    #great for finding synonyms

--------------------------------------------------------------------------------
IIb. Mac Specific
--------------------------------------------------------------------------------

Sometimes you want to open a pdf file but with "Preview" whereas your default
is Acrobat.

$ open -a Preview a.pdf

Sometimes you want to open a text file with TextEdit but the file does not have
.txt extension

$ open -e file

Use the manual pages to see other options for "open".


--------------------------------------------------------------------------------
IIIa. Time in Tokyo, India, Israel, Europe
--------------------------------------------------------------------------------

$ date -u  #time in UT

$ zdump Asia/Tokyo
$ zdump Asia/Kolkata #but not Mumbai! my, how persnickety
$ zdump Israel
$ zdump Europe/Amsterdam

$ cal
$ cal 2020
$ cal 3 2020

--------------------------------------------------------------------------------
IIIb. Measure the speed of network
--------------------------------------------------------------------------------
https://www.speedtest.net/ 


--------------------------------------------------------------------------------
IVa. Time to leave
--------------------------------------------------------------------------------
$ leave +0100  #leave in one hour from now
$ leave 2100   #leave at 9 pm

--------------------------------------------------------------------------------
IVb. Alarm Clock
--------------------------------------------------------------------------------

Use leave as above.  However, after the time for alarm has gone off
you need to "kill" leave.

$ pkill leave

--------------------------------------------------------------------------------
V. Check spelling in vi
--------------------------------------------------------------------------------
Turn on spell feature in vi
:set spell
- ':set spell' activates vim spellchecker. Use ']s' and '[s' to move between
  mistakes, 'zg' adds to the dictionary, 'z=' suggests correctly spelled words
- check my .vimrc https://github.com/cfenollosa/dotfiles/blob/master/.vimrc

--------------------------------------------------------------------------------
Text to Voice
--------------------------------------------------------------------------------

$ say "Hello Kitty. How is the weather in Tokyo?"
$ say -f filename   #to read a file (pretty good)

--------------------------------------------------------------------------------
VI. Procrastinate 
--------------------------------------------------------------------------------
$ curl -s http://api.open-notify.org/iss-now.json | jq .   #where is ISS?

$ fortune    	#procrastiante for a few minutes
	#believe it or not, fortune has 10 options!
$ rev file.txt		#good for wasting say 20 seconds
$ sl 
$ while 1; do sl; done   
	In order to kill this process
$ cntrl z
$ kill -KILL $(ps | grep sl | grep -v grep | awk '{print $1}')

$ nc -v towel.blinkenlights.nl 23   #the ultimate procrastinator
	in order to kill this simply control c

check out
http://1stoldsite.to.infn.it/groups/group4/mirror/www/webomatic/unix.toolkit/timesink.html

--------------------------------------------------------------------------------
VII. Keyboard shortcuts
--------------------------------------------------------------------------------
alt+backspace delete previous word
alt+f skip  to next space
alt+b skip to previous space
ctrl+u cuts all text up to the cursor
ctrl+k cuts all text after the cursor to end of line
ctrl+a moves cursor to start of line
ctrl+e moves cursor to end of line

------------------------------------------------------------------------
VIII. Making templates for bib files
------------------------------------------------------------------------

I usually make bib files with 
%aaaa

%bbbb 

and so on.  

$ printf '%s\n' {a..z} | gsed 's/./%&&&&&\n/'

------------------------------------------------------------------------
Check out "ranger" (now installed on my computer)
------------------------------------------------------------------------

------------------------------------------------------------------------
Interesting website
------------------------------------------------------------------------
http://www.tuxradar.com/content/more-linux-tips-every-geek-should-know