Bash commands for my own personal reference:


  • List applications listening on ports

netstat -lnp


  • List running processes

ps aux


  • List running processes and search for a particular process name

ps aux | grep process-name


  • Search for text within a set of files

grep "text string" *.*


  • Search for text within a set of files, case insensitive

grep -i "text string" *.*


  • Search for text within a set of files and display X lines after match

grep -A 3 "text string" *.*


  • Search for text within a set of files and display X lines before match

grep -B 3 "text string" *.*


  • Search for text within a set of files and display X lines before and after match

grep -C 2 "text string" *.*


  • Check the current directory

pwd


  • Get BIOS system information

sudo dmidecode

  • On Ubuntu, you can use apt-get to get available package versions of a particular package using:

sudo apt-cache madison <package name>


  • On Ubuntu, to install a specific version of that package, use the above command to get version info then:

sudo apt-get install <package name>=<version>


  • Use Ubuntu apt-mark, you can hold onto a specific package version:

sudo apt-mark hold <package name>


  • Disable an upstart service from starting on Ubuntu:

sudo su -c 'echo "manual" >> /etc/init/mysql.override'


  • To remove old kernel packages from the boot partion on Ubuntu you can use the following command:

sudo apt-get remove --purge $(dpkg -l 'linux-image-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')


  • To automatically make directories and sub directories within the path add the -p parameter:

mkdir -p /home/ryan/Projects/this/sub/does/not/exists/


  • To get a list of open connections on your machine:

sudo netstat -tupn

 

Ryan is a hacker dad living in Cape Town, South Africa who likes Skate Boarding JavaScript and Functional Programming.

ryanwild @javascript_fn