bash

Customize directory colors

You can use the command ls --color (or an alias) to show directories with colours for folders, files, links, etc. However, you may not realise these colours can be easily configured using bashrc and a configuration file. Edit your .bashrc file (in your home directory) to include the following line ... More

Control memcached from the command line  linux

memcached is a general-purpose distributed memory caching system originally developed by Danga Interactive for LiveJournal but now used by many other sites. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source (such ... More

Find all files containing a given string  mac

A quick one-liner to recursively search files for a given text string. Open up a terminal session and enter the following - replacing "foo" with the text to search for. find . -exec grep -l "foo" {} \; You can also limit the search to files with a particular extension (e.g. HTML or ... More

Collaborate in the shell with screen (multiuser)  linux

Screen is a neat little program that allows you to use multiple virtual terminals in a single session on Unix/Linux and Mac. However, it does more than just that. It can also allow you to share your current session on a machine with another user - allowing you to collaboratively ... More

Bash Command Substitution  linux

Bash command substitution performs a given command replacing the marker with the resulting standard output. It is particularly useful when you want to store the output of a command in a variable or as an alternative method of chaining multiple commands together. Bash command substitution is achieved by wrapping your ... More

Remove duplicate lines from text files (with sort)

A quick method to remove duplicates from text files - including for example CSV files - where multiple records have been added (perhaps automatically) at different times resulting in multiple copies of the same record scattered throughout the file. Here is a simple one-liner bash command to remove duplicates using sort. More

Control Console with SysReq  linux

System request (often abbreviated SysRq or Sys Req) is a key on keyboards for PCs that has no standard use. This key can be traced back to the operator interrupt key of the IBM System/370 mainframe computer. But under Linux there's a bunch of useful things available via ... More

Get a list of all processes not run by you  linux

Find the currently running processes on your system that were not started by yourself. A great way to find out what is hogging your system on multiple-user setups or remote logins. Open up a terminal session and enter: ps aux | grep -v `whoami` ps aux returns (a) all processes with ... More

Get file type information from the command line  linux

Often forgotten the file command will give you a simple summary of a file's type and content. At the prompt enter file where is the name of the file you are interested in. You will receive output detailing the files contents, e.g. A Word Document.doc ... More

Find all running processes of a program

Find the pids of all instances/processes of a given program running on your system Open a terminal and enter ps ax | grep "firefox" ...replacing 'firefox' with the name of the program you are looking for. The columns in the output are as follows: (1) pid 'process id' (2) tty ... More

Set CDPATH to ease folder navigation

CDPATH is an environment variable which tells the cd command where to look for the specified folder. By including the parent folders of commonly used locations you can access folders more easily - and without typing an entire path. More

Use ifconfig.me to return your IP and Host

ifconfig.me is a web service that displays information about your connection, including IP address, hostname and User Agent string. Helpfully it provides a simplified interface that can be easily queried to get this information from the command line. More

Execute last command as root  linux

Re-run previously entered command as root user. sudo !! !! is automatically substituted to the content of the previous command. Turning the above line into sudo . More

Control-R Through Your History  linux

Interactively search through your command line history with a simple keyboard shortcut. At a new shell prompt (bash or Terminal.app on Mac) press Ctrl-R Start typing the search string to lookup in your bash history. As you type the top matching command in your history will appear. Hit Return ... More

Use screen to manage persistent sessions  linux

GNU Screen is a command-line application that allows use of multiple virtual sessions within a single real terminal or remote session. Importantly, it allows for persistent running of command-line applications independent of the shell that initiated them program, meaning active applications can persist during disconnection. More

Add Git Branch Name to Terminal Prompt (Mac)  git

When in a repository directory you can show the name of the currently checked out Git branch in the prompt, making it easier to track where you are (and where you're about to commit). The following instructions are written for Mac OS X (Lion) or later, using a terminal ... More