Main Page

From CleanPosts

Revision as of 02:06, 8 July 2021 by Selah (Talk | contribs)
Jump to: navigation, search


Linux Jedi Mind Tricks

  • Linux Novice - Someone who wonders what RTFM means.
  • Linux User - Someone who has tried to RTFM.
  • Windows User - Someone who has never heard RTFM.
  • Linux Guru - Someone who doesn't need to RTFM.
  • Linux Hacker - Someone who knows what isn't in TFM.
  • Linux Jedi - The one who WTFM.


Average two values in scientific notation echo "9.936E-2 1.138E-2" | awk '{printf "%.3E\n", ($1+$2)/2}' | sed -E 's/-0?/-/g'
Calculate pi at scale 500 and print at scale 400 PI=$(BC_LINE_LENGTH=0 bc -l <<< 'scale = 500; 4*a(1)'); echo ${PI:0:400}
Calculate the Lorentz factor for fractions of c awk 'BEGIN { for (v =0; v <=99; v++) printf "%.2f %.4f\n", v/100, 1/sqrt(1-(v / 100)^2)}'
Center text in a terminal window of any size ls -l | awk '{ pddrintf("%*s\n", ('${COLUMNS}' + length($1))/2, $9); }
Count MP3 files and report disk usage find /home -name '*.mp3' -ls | awk '{s+=$7;f+=1}END{print " MP3 files: "f"\nTotal size: "s/1000000" MB"}'
Count processes running as each user: ps -ef | awk '{print$1}' | sort | uniq -c | sort -nr
Get a one-line description for the files in a directory ls -l /usr/bin | awk '{print $9}' | xargs whatis | sed '/appropriate/d'
List files referenced by library symbolic links sudo ls -lR /lib | grep ^l | awk '{print $9" "$10" "$11}' | grep ^lib | sort
List all processes by owner ps -ef | awk '{print$1}' | sort | uniq -c | sort -nr | sed '/UID/d'
List directories find . -type d -print
List only non-blank lines in a file awk 'NF >0' file.txt
Print all lines with exactly 40 characters awk 'length ==40' tags.tx3
Print all prime numbers between 1 and 5000 seq 1 5000 | factor | awk 'NF==2 { print $2 }' | tr '\n' ',';echo
Print a random line from a file of unknown length awk 'BEGIN{ srand() }; rand() * NR < 1 { line = $0} END {print line}' tags.tx3
Print a short list of your most recently-used commands fc -rl | awk '{print $1=""; print}'
Print lines with only four letter words (or less) awk 'length < 5' tags.tx3
Print number of processes running as each user ps -ef | awk '{print $1}' | sort | uniq -c
Print sizes of files in current directory with commas ls -lp | grep -v / | awk '{$1=$2=$3=$4=$6=$7=$8="";print}' | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'
Print the first sixteen binary numbers echo "obase=2;i=0;while(i<=15) {i;i+=1}" | bc | awk '{printf "%4s\n", $0}'
Print the unique commands in your history history | awk '{$1=""} !a[$0]++'
Print working directory file information ls -l | awk '{$5=sprintf("%9s",$5); printf "%s %9s", substr($1,1,4),$5" "; for (i=9;i<=NF;i++) printf $i" "; printf "\n"}'
Print your command history, omitting duplicates history |c awk '{$1="";print }' | sort | uniq
Print your top fifteen most frequently-used commands: history | awk '{print $2}' | sort | uniq -c | sort -n | tail -n15 | sort -nr
Reverse the order of the fields on each line awk '{for (i=NF;i>0;i--){printf $i" "};printf "\n"}' gettysburg2.txt
Search for "foo" and "bar" in any order awk '/foo/ && /bar/' tags.txt
Search for "foo" and "bar" in that order awk '/foo.*bar/' tags.txt
See what's eating your system clocks ps aux --sort %cpu | awk '{print $3,$1,$11}' | tail -30
Show all mounted media lsblk &verbar; awk 'NF >6 {print$1,"\t",$4,"\t",$7}'
Sort user processes by memory footprint ps aux --sort -%mem | awk '{print $4,$1,$11}' | sed '/root/d' | head -50
Strip blank lines from a text file awk 'NF > 0' yeshua > yeshua2
Tally up a column of figures awk '{s+=$1} END {print s}' figures.txt
Tally up bytes of all files in a directory ls -l | sed '/^d/d' | awk '{ x += $5 } ; END { print "Total bytes: " x }'
Tally up bytes of selected files in a directory du -b *.msg | awk '{s+=$1} END {print s}'
Print prime numbers echo {1..80} | factor | awk 'NF==2 { print $2 }'
Use awk like grep awk '/sex/' tags.txt

Awk Scripts

Show ASCII table

# Usage: awk -f showascii
    for (i=0; i<16; i++) {
      for (j=32+i; j<128; j+=16) {
        if (j == 32) { x = "SPC" }
        else if (j == 127) { x = "DEL" }
        else { x = sprintf("%c",j) }
        printf("%3d: %-5s",j,x)
      print ""

Tally up a column of figures

#! /bin/sh
case "$1" in 
[1-9]*) colnum="$1"; shift;; 
*) echo "Usage: `basename $0` colnum [files]" 1>&2; exit 1;; 
awk '{sum += $col} 
END {print sum}' col=$colnum OFMT='%.2f' ${1+"$@"}

Use awk to list the thirty most-common words in a text file

#Usage: awk -f wordfreq textfile.txt

{   nbytes += length($0) + 2 # +2 for CR/LF
    nfields += NF
    $0 = tolower($0)
    for (i=1; i<=NF; i++) {
    show = (show == "") ? 30 : show
    width1 = length(show)
    PROCINFO["sorted_in"] = "@val_num_desc"
    for (i in arr) {
      if (width2 == 0) { width2 = length(arr[i]) }
      if (n++ >= show) { break }
      printf("%*d %*d %s\n",width1,n,width2,arr[i],i)
    printf("input: %d records, %d bytes, %d words of which %d are unique\n",NR,nbytes,nfields,length(arr))

CLI Applications

abcde CD ripper Text-mode CD ripper
abook Address book Access your contact information from any terminal
ac Unix tool Report statistics on uptime
aiksaurus Text-mode thesaurus Example: aiksaurus brutal
bc Text-mode calculator Interactive or scripted, with C syntax
bwbasic Bywater Basic BASIC interpreter, see bwbasic for commands and functions
cacaview Image viewer Renders images using ASCII text and color
cal Text-mode calendar Display a calendar in the terminal
calcurse Calendar/appointments See calcurse for detailed help information
cdw Text mode CD writing tool Ncurses interface
Concalc Text-mode calculator Uses parser-algorithm of extcalc
cmus Music player Built from ncurses
dict Text-mode dictionary Example: type dict syllogism
dirsplit Split a directory into volumes Makes volumes custom size, minimizes wasted space.
factor Math tool Print the prime factors of a number'
fc-list Unix tool List the fonts installed on your system
ffmpeg Video converter Extract audio: ffmpeg -i video.vob audio.mp3
file Unix tool Print information about files'
freesweep Minesweeper game Use space bar to expose a square
genisoimage ISO file system creator Build burn-ready images from files or directories
irssi Text-mode IRC chat client Undernet: /connect Diemen.NL.EU.Undernet.Org
links Text-based web browser Type ESC to see pull-down menu
lynx Text-mode web browser Renders HTML to text files nicely
make GNU utility Compile and install software old-school
mathomatic Text-based algebra system Mathomatic for detailed user guide
mc Orthodox (two panel) file manager See mc for more information
mksquashfs Squash filesystem tool apt install squashfs-tools
nano Text editor
ncdu Interactive disk usage Based on Ncurses
newsboat RSS news aggregator
nl Unix tool Number lines of files
oggenc From Vorbis tools Convert .WAV files to .ogg: oggenc *
paste Unix tool Combine multiple files
perl Interpreter The Perl 5 language interpreter
ps Unix tool Report a snapshot of the current processes
sc Text-mode spreadsheet Spreadsheet with vi-like bindings
streamripper Internet radio Save streams to audio files
tr Unix tool Translate characters
w3m Text-based web browser With enhanced table rendering support
whatis Unix tool 'Display one-line manual page descriptions
wordgrinder Word processor ESC for drop-down menu


Excel Built-in Functions

GUI Applications

calibre Ebook reader Organize, read, convert to various formats
gprename File renamer Rename files in bulk
starplot Star data renderer Depict the stellar neighborhood
wine-solitaire MS Windows Solitaire Under WINE (WINE Is Not an Emulator)
xaos Mandelbrot Set Explore the set in real time with fast rendering
xclip Unix tool Copy terminal output to X11 clipboard
xedit Text editor Edit files in an X11 window


Absmag Calculate absolute magnitude from visual magnitude and radial distance in light-years
Anagram Find all permutations of a string
Arclen Arc length of a parabola
Average Find the mean of a set of numbers of any length Convert comma-delimited spreadsheets to sc/Xspread format
Cosine Calculate the cosine function
Factor Calculate the factor of a number
Factorial Factorial function, using -c flag
Fibonacci Print the first n Fibonacci numbers
Gamma Calculate the gamma function over a range
Intersect Find the point of intersection of two co-planar lines defined by four points
Intercept Return slope-intercept form of the equation of a line through two points.
Loop Loop through a range
Lotto Five dolla quick pick Lotto
Ls List the files in the working directory
MAGA MAGA twitter account name generator
Nilakantha Calculate Pi using Nilakantha's series
Palindrome Find all palindromic words in a file
Paste Paste two files together in columns
Synodic Synodic period between two planets (how many days until the inside planet laps the outside planet)
TOF Hohmann ellipse time-of-flight, in days


Change double-spaces to single spaces sed 's/ \+/ /g' > redpine2.txt
Display subdirectories in a tree format grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//----/g' -e 's/^//' -e 's/-/|/'
List the unique words in a file sed -e $'s/\t//g' -e "s/punct:\+//g" -e "s/./\L&/g" | tr ' ' \\n | sort | uniq
Prepend an asterisk to every line in a file sed -ne 's/.*/* &/p' enterprise.txt > enterprise2.txt
Remove tags from HTML file sed -e :a -e 's/<[^<]*>/ /g;/</{N;s/\n/ /;ba;}' CleanPosts.html
Sort the Holy Bible by verse length === perl -e 'print sort {length $a <=> length $b} <>' kjv.txt


70 columns set wm=60
Append text after the cursor [count] times a
Append to end of current line A
Back one word b
Back screenful ^B
Begin overstrike or replace mode, use ESC key to exit R
Capitalize the first letter of each line :%norm gUl
Change c
Change current word to a new word cw
Close tab tabc
Copy all lines and put at end of file 1,$co$
Create abbreviation ab abbr phrase
CTRl F - Forward screenful ^F
D caret, not CTRL d - Delete to beginning of line d^
Delete all lines %d
Delete all lines in file 1,$d
Delete all text on a line after, and including, a period norm f.1D
Delete blank lines :v/\S/d
Delete character x
Delete [count] characters before the cursor X
Delete [count] lines dd
Delete {count} lines, starting with [range] [range]d[elete]
Delete d
Delete five lines d5d
Delete from current line to end of file .,$d
Delete lines 1 through 9 1,9d
Delete lines x through y x,yd
Delete the characters under the cursor until the end of the line D
Delete to end of line d$
Delete unicode character %s/\%u200d//g
Delete word backward db
Delete word from cursor on dw
Directory list Explore
Display file list !ls
Down half screenful ^D
Edit {file} always. Discard any changes to the current buffer e[dit]!
Edit {file} e[dit]
Edit the file whose name is under or after the cursor gf
Enable left-right scrolling set nowrap
Enter Insert mode, replacing characters rather than inserting R
Example 10G goes to line 10 nG or n
Execute {cmd} and insert its standard output below the cursor r[ead] !{cmd}
Exit Visual mode without making any change <Esc>
Filter through 'equalprg' option command =
Filter through external command !
Find match, ahead /foo
Find match, behind ?foo
Find previous N
Force autowrap set fo-=1
Format lines to 'textwidth' length gq
Forward one word w
Get file r filename
Go to column 56
Go to file beginning gg
Go to file end G
Go to last tab tabl
Go to next line
Go to next tab tabn
Go to previous line
Go to screen bottom L
Go to screen middle M
Go to screen top H
Highlight matches set hlsearch
indent line >>
Indent paragraph 5>>
Insert i
Insert tab TAB -
Insert text at the beginning of the cursor line I
Insert text before the cursor [count] times i
Insert the file [name] below the cursor r[ead] [name]
Join all lines ending in a hyphen and reformat to 80 character lines :g/-$/j  :%s/- //g  :%!par -w 80
Join lines 13 and 14 13,14j
Join next line to the end of the current line J
Justify selected range to 40 columns wide !par 40j
List all the current marks not a motion command marks
Make backspace standard set backspace=2
Move cursor to the beginning of current line 0
Move cursor to the end of current line $
Move lines to end of file 1,10m$
Move the current line to the clipboard .!xclip -sel clip
Moves the cursor down one line j
Moves the cursor one character to the left h
Moves the cursor one character to the right l
Moves the cursor up one line k
Move tab to position n tabm n
Number of lines for command line set cmdheight=3
One page backward ^b
One page forward ^f
On lines containing a # symbol, delete all text after the first comma g/^#/norm f,1D
Open new tab tabnew filename
Open up a new line following the current line and add text there o
Open up a new line in front of the current line and add text there O
Paste after p
Paste from buffer 2 [there are 9] "2p
Paste twice 2p
Pattern Search backward for the pattern ?
Pattern Search forward for the pattern /
Quit always, without writing cq[uit]
Quit current file and exit - same as "q! ZQ
Quit, no warning q!
Quit Vim. This fails when changes have been made q[uit]
Quit without writing q[uit]!
Quit with warning q
Read in sorted file r !sort phone.txt
Remove line breaks w ++ff=unix
Repeat command .
Repeat the latest "/" or "?" [count] times in opposite direction N
Repeat the latest "/" or "?" [count] times n
Replace a by nothing g/a/s///g
Replace foo with newline %s/foo/^M/g
Replace old with new in range 50,100s/old/new/g
Replace tabs with spaces set retab
Replace the character under the cursor with {char} r{char}
Replace the letter a, by blank g/a/s// /g
Replace with confirm 50,100s/old/new/gc
Restore line U
Return the number of search matches :%s/love//gn
Reverse order of file :g/^/m 0
Same as above, but only write the lines in [range] [range]wq[!] [file]
Scroll the screen so the cursor is at the bottom zb
Scroll the screen so the cursor is at the top zt
Search forward for the [count]'th occurrence of {pattern} /{pattern}[/]
Set 70 columns wide set wm=60
Set amount by which text is tabbed set shiftwidth=4
Set bar at column 70 set colorcolumn=70
set wrapping set wrap
Shift left <
Shift right >
Show line numbers set nu
Show ruler set ru
Show tabs and end of lines 1,$l
Sort file 1,$!sort
Start editing a new file e file
Start Visual mode per character v
Switch case ~
To the mark {A-Z0-9} in the correct file `{A-Z0-9}
Turn on ruler set ruler
Unabbreviate a word una word
Undent line <<
Undo last change u
Up half screenful ^U
Visual block, by characters CTRL-v
Visual block, by lines CTRL-V
Visual mode, by line V
Write current file if modified and exit ZZ
Write file to disk and quit the editor wq
Write lines 10 through 25 into file named temp 10,25w temp
Write lines to shell 1,10w !command
Write out w[!][>>] filename
Write the current file and exit always wq!
Write visual block to clipboard w !xclip -selection clipboard
Write workspace to named file w file
Write workspace to original file w
Yank 5 lines 5yy
Yank current line Y
Yank current line yy
Yank from cursor to end of current word yw
Yank line [address]y[a-z][count]
Yank to end of current line from cursor y$
Yank y

Because I am an 1337 h4x0r and don't want to use anything that you n00bs might be able to understand.

Terminal Cruise

Book 1

TCA Elohim 256 12978
TCB Pilgrims 272 8046
TCC Salem 199 10389

TCD Covenant 260 12922
TCE Binah 260 8795
TCF Rosh 260 11297

TCG Yeshua 260 13183
TCH Rumbek 248
TCI Temples 126 11297

Book 2

TCJ Council 288
TCK Change 260 13172
TCL Demonstroke 288

TCM Robyn 260
TCN Comet
TCO Agent 260 13116

TCP Judith 310 -
TCQ Desecration 121
TCR Apollo 249 11541

Book 3

TCS Europa
TCU Exiler

TCV Coup
TCW Luna
TCX Chase
TCY Contact
TCZ Partners
APP Appendices 155



  • streamripper -u 'WinAmpMPEG/5.0'
  • find -name '*.mp3' -exec mv -i {} /home/minix/Desktop/music \;
  • ffmpeg -i 1205201058.mp4 -vf scale=1280:-1 -crf 30 -preset veryslow smaller.mp4 # Reduce the resolution (preserving aspect ratio) and quality of a video from your phone to save space. In my case from 240MB to 7MB. It took about 4 minutes to process though.
  • Add an overlay.png (here: the mask) to a movie (in.mp4):
  1. 1⃣ ffmpeg -i in.mp4 %04d.split.png
  2. 2⃣ for i in *.split.png; do composite -gravity center overlay.png $i $i.png;done
  3. 3⃣ ffmpeg -pattern_type glob -i '*.png.png' -c:v libx264 -r 25 -pix_fmt yuv420p "out.mp4"


  • Transcode an audio file into a pseudo-video for upload to Twitter, using a static dummyimage.png:
  • ffmpeg -loop 1 -i dummyimage.png -i audio.mp3 -shortest -c:v libx264 -pix_fmt yuv420p -c:a aac video-for-twitter.mp4

  • Create high quality gifs with ffmpeg on Linux/Unix cli Make custom color palette f=in.mp4 ffmpeg -i $f -vf fps=15,scale=320:-1:flags=lanczos,palettegen p.png
  • Generate HQ gif ffmpeg -i $f -i p.png -filter_complex "fps=15,scale=300:-1:flags=lanczos[x];[x][1:v]paletteuse" out.gif
  • Change the system default editor -- sudo update-alternatives --config editor
  • Use CUPS printer management system -- localhost:631 (in a browser address bar)
  • find -name '*.txt' -exec grep -vxFf 1.txt {} \; > output.txt
Personal tools
Strangers In Paradise