10 Most Used Linux Commands

Whilst skimming my Bash history today looking for an esoteric one liner I’d written earlier I started to ponder what my most used commands were, it’s easy enough to find out! This is actually output from my Mac, not a Linux box, I tricked you πŸ˜€

<br /> Chill:~ rus$ history | awk {'print $2'} | sort | uniq -c | sort -nr | head -n 10<br /> 106 ssh<br /> 49 ls<br /> 44 cd<br /> 42 curl<br /> 34 scp<br /> 25 vi<br /> 15 mv<br /> 15 cp<br /> 12 grep<br /> 10 rm<br />

Bash Shortcuts

Meta-< -> go to beginning of history file
Meta-> -> go to end of history file
Meta-f -> go to next word in command line
Meta-b -> go to previous word in command line
Meta-d -> delete next word in command line (from the actual position of the prompt)

Ctrl-a -> go to the start of command line
Ctrl-e -> go to the end of command line
Ctrl-p -> previous command in history
Ctrl-n -> next command in history
Ctrl-f -> next character in command line
Ctrl-b -> previous character in command line
Ctrl-r -> reverse search in history file
Ctrl-d -> delete current character
Ctrl-k -> delete from the prompt to the end of command line
Ctrl-_ -> undo (yes, but limited)

Changing variables in a BASH while loop

There is an error that I often run in to when working with files and while loops in BASH. Often I have scripts similar to the following, where I cat a file and read it in using a while loop to process variables in the file:

#!/bin/bash
count=0;
cat testfile | while read line
do
    count=$(($count+1));
    echo $count;
done
echo "Total $count";

and using the following test data in testfile as: