Ask HN: Can I see your cheatsheet?
### Disk and Hardware<p>Hardware Summary<p><pre><code>    sudo lshw -short
    </code></pre>
Get the total disk space left and summary of folder usage<p><pre><code>    df -h .; du -sh -- * | sort -hr
    </code></pre>
Simple partition summary<p><pre><code>    lsblk

</code></pre>
What version of Linux are you running<p><pre><code>    uname -a
    &gt; Linux TREEBEARD 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 
      x86_64 x86_64 x86_64 GNU&#x2F;Linux
    
    lsb_release -a
     &gt; Distributor ID: Ubuntu
     &gt; Description:     Ubuntu 16.04.4 LTS
     &gt; Release:         16.04
     &gt; Codename:     xenial
 
 What flavour of Ubuntu are you running (see https:&#x2F;&#x2F;itsfoss.com&#x2F;which-ubuntu-install&#x2F; )
 
     cat &#x2F;var&#x2F;log&#x2F;installer&#x2F;media-info
     &gt; Unity
   </code></pre>
How long has the PC been running<p><pre><code>     uptime
     &gt;  23:09:26 up 61 days,  8:28,  1 user,  load average: 0.82, 0.48, 0.34

</code></pre>
Count files in folder and sub folders<p><pre><code>    find . -type f | wc -l

</code></pre>
### Files and Folders<p>Get a tree view of subfolders<p><pre><code>    ls -R | grep &quot;:$&quot; | sed -e &#x27;s&#x2F;:$&#x2F;&#x2F;&#x27; -e &#x27;s&#x2F;[^-][^\&#x2F;]*\&#x2F;&#x2F;--&#x2F;g&#x27; -e &#x27;s&#x2F;^&#x2F;   &#x2F;&#x27; -e &#x27;s&#x2F;-&#x2F;|&#x2F;&#x27;
</code></pre>
Find the most recently used files including all subdirectories<p><pre><code>    find . -type f -mtime -7 -print0 | xargs -0 ls -lt | head
  </code></pre>
Find string in all files (example searchs logs for Exception)<p><pre><code>    find &#x2F;var&#x2F;log&#x2F;www.lifepim.com -type f -print0 2&gt;&#x2F;dev&#x2F;null | xargs -0 grep --color=AUTO -Hn &#x27;Except&#x27; 2&gt;&#x2F;dev&#x2F;null
</code></pre>
Find a string &#x27;blah&#x27; in all files with recursive (deep) search from current folder &#x27;.&#x27;<p><pre><code>    grep -Rnw &#x27;.&#x27; -e &#x27;blah&#x27;
</code></pre>
Limit above search to only .html files<p><pre><code>    grep -Rn --include=*.html &#x27;.&#x27; -e &#x27;blah&#x27;
    
    
    
</code></pre>
### Processes<p>List all processes<p><pre><code>    ps -ef
   
   </code></pre>
Show a tree of processes<p><pre><code>    pstree
   
   
</code></pre>
Find the processes I am running<p><pre><code>    ps -u duncan
    
    </code></pre>
Get list and PID of specific processes (eg python)<p><pre><code>    pgrep -a python
    </code></pre>
Show all processes and usage<p><pre><code>    top
    htop   (will need to run sudo apt install htop first)
    
</code></pre>
### Network<p>Get IP Address and network details<p><pre><code>    &#x2F;sbin&#x2F;ifconfig
</code></pre>
See list of PC&#x27;s on the network<p><pre><code>    arp -n   
    
    ip -r neigh
    
    nmap -sA 192.168.1.0&#x2F;24
    </code></pre>
Lookup name of IP Address<p><pre><code>    nslookup 162.213.1.246
    &gt; Non-authoritative answer:
    &gt; 246.1.213.162.in-addr.arpa      name = wssa.beyondsecurity.com.
  </code></pre>
Get the IP address of a domain name<p><pre><code>     host www.acutesoftware.com.au
    &gt; acutesoftware.com.au has address 129.121.30.188
  
  
 Show the routing table

    route 

</code></pre>
Port scanning<p><pre><code>    nmap

 
 ### Shell tips
 
 Show top commands from your shell history 
 
     history | awk &#x27;{a[$2]++}END{for(i in a){print a[i] &quot; &quot; i}}&#x27; | sort -rn | head
          35 cat
          25 awk
          18 pwd
          15 ls
          14 cd
     
     
  
</code></pre>
### Data Collection<p>Download a file<p><pre><code>    wget http:&#x2F;&#x2F;www.acutesoftware.com.au&#x2F;aikif&#x2F;AIKIF-Overview.jpg
    
</code></pre>
Download a site for offline reading<p><pre><code>    wget --recursive  --page-requisites http:&#x2F;&#x2F;www.acutesoftware.com.au&#x2F;cont_articles.html

</code></pre>
### Data extraction<p>Get a list of URLs from a html file (like an exported list of Chrome bookmarks)<p><pre><code>    grep -Eoi &#x27;&lt;a [^&gt;]+&gt;&#x27; source.html | grep -Eo &#x27;HREF=&quot;[^\&quot;]+&quot;&#x27; | grep -Eo &#x27;(http|https):&#x2F;&#x2F;[^&#x2F;&quot;]+&#x27; &gt; urls.csv
    </code></pre>
Grep log files<p><pre><code>    cat &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log  | grep &quot;POST&quot;          # number of posts to lifepim
    cat &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log  | grep &quot;login&quot; | wc -l # number of login page accesses
    awk &#x27;{print $1}&#x27; &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log | sort | uniq -c   # count per IP address
    awk &#x27;{print $7}&#x27; &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log | uniq  # list of pages accessed
    
    cat &#x2F;var&#x2F;log&#x2F;www.lifepim.com.error.log | grep &quot;Exception&quot; | uniq      # list of exceptions
    
    awk &#x27;{print $11}&#x27; &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log | sort | uniq -c | grep -v &quot;lifepim&quot;  # count by referrers
    
        1 &quot;https:&#x2F;&#x2F;newsbout.com&#x2F;id&#x2F;19184625381&quot;
        1 &quot;https:&#x2F;&#x2F;umumble.com&#x2F;links&#x2F;156005&#x2F;what-software-will-you-trust-when-you-get-senile?&quot;
        1 &quot;https:&#x2F;&#x2F;www.producthunt.com&#x2F;ask&#x2F;616-what-s-the-best-personal-knowledge-base&quot;
</code></pre>
Looping through list of gz files and grepping for blog hit count<p><pre><code>        for i in &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access*.gz
        do
            echo -n &quot;Checking zipped logfile $i - &quot;
            zgrep &#x27;&#x2F;blog&#x2F;&#x27; &quot;$i&quot; | wc -l
        done


        Checking zipped logfile &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log.2.gz - 45
        Checking zipped logfile &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log.3.gz - 112
        Checking zipped logfile &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log.4.gz - 92
        Checking zipped logfile &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log.5.gz - 62
        Checking zipped logfile &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log.6.gz - 64
        Checking zipped logfile &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log.7.gz - 85
        Checking zipped logfile &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log.8.gz - 213
        Checking zipped logfile &#x2F;var&#x2F;log&#x2F;www.lifepim.com.access.log.9.gz - 80
</code></pre>
### Date and Time<p>Display Annual Calendar for current year<p><pre><code>    cal -y 
   
   </code></pre>
Show the current date in ISO format ( yyyy-mm-dd )<p><pre><code>    echo $(date -I)
    </code></pre>
Store the current date &#x2F; time as string in a bash variable<p><pre><code>    DATE=`date &#x27;+%Y-%m-%d %H:%M:%S&#x27;`
    echo $DATE
    
   </code></pre>
### SQL tips<p>Show table size of selected tables in a schema<p><pre><code>    SELECT table_name as &#x27;Database Name&#x27;, 
    sum( data_length + index_length ) as &#x27;Size in Bytes&#x27;, 
    round((sum(data_length + index_length) &#x2F; 1024 &#x2F; 1024), 4) as &#x27;Size in MB&#x27; 
    FROM information_schema.TABLES where table_name like &#x27;as_%&#x27; or table_name like &#x27;sys_%&#x27; 
    GROUP BY table_name; 
</code></pre>
Get a list of column names for a table<p><pre><code>    select * from information_schema.columns where table_name = &#x27;as_task&#x27;;
</code></pre>
Show usage in log file grouped by date<p><pre><code>    select DATE_FORMAT(log_date, &#x27;%Y-%m&#x27;), count(*) from sys_log group by DATE_FORMAT(log_date, &#x27;%Y-%m&#x27;) order by 1;
</code></pre>
Show usage by user_id and date<p><pre><code>    select log_date, user_id, count(*) from sys_log group by log_date, user_id order by log_date;
</code></pre>
Show users by week<p><pre><code>    select WEEK(log_date), max(log_date) as date_until, count(*) as num_user_actions, 
     count(distinct user_id) as active_users_this_week from sys_log 
     where DATE_FORMAT(log_date, &#x27;%Y-%m&#x27;) &gt; &#x27;2018-05-05&#x27; group by WEEK(log_date) order by 2;</code></pre>