Tips tagged bash


Tip #480   Diff Two Directories

A quick script to compare files from two directories (for example a backup and working directory).

Read more »


Tip #445   Local/remote webserver

Serve files on port 8080 for anybody from the directory from where you start this command:

:;while [ $? -eq 0 ];do nc -vlp 8080 -c'(r=read;e=echo;$r a b c;z=$r;while [ ${#z} -gt 2 ];do $r z;done;f=`$e $b|sed 's/[^a-z0-9_.-]//gi'`;h="HTTP/1.0";o="$h 200 OK\r\n";c="Content";if [ -z $f ];then($e $o;ls|(while $r n;do if [ -f "$n" ]; then $e "<a href=\"/$n\">`ls -gh $n`
";fi;done););elif [ -f $f ];then $e "$o$c-Type: `file -ib $f`\n$c-Length: `stat -c%s $f`";$e;cat $f;else $e -e "$h 404 Not Found\n\n404\n";fi)';done Read more »


Tip #412   Vi mode in bash

Add "set -o vi" at the bottom of ~/.bashrc or /etc/bashrc, then press ESC in prompt to enter vi mode and search your issued command in history by giving a "/" at front.

For example, in shell command line, press ESC, type /ls, enter. Read more »


Tip #403   list the most recent files in a directory

If you just want to find out what's new in a directory:

Read more »


Tip #387   Deleting whole words on a bash command line

To delete a word on a bash command line, hit ESC then backspace. Read more »


Tip #377   Alter autocompletion settings

Try changing the following in your ~/.inputrc to alter the behaviour of auto completion on application/file names:

set completion-ignore-case on
- performs filename matching and completion in a case-insensitive fashion. The default value is 'off'.

set completion-query-items 200
- number of possible completions that determines when the user is asked if they want to see the list of possibilities. The default limit is 100.

- if set to 'on', words which have more than one possible completion cause the matches to be listed immediately instead of ringing the bell. The default value is 'off'.

- if set to 'on', a character denoting a file's type is appended to the filename when listing possible completions. The default is 'off'. Read more »


Tip #376   Change prompt color dynamically

I'm frequently logged into multiple different boxes concurrently. To help me keep track of which box I'm working on at the moment, I have this in my .bashrc file, which I keep rsynced across the various boxes.

Read more »


Tip #375   Bash function to decompress archives

From; original author unknown:

Read more »


Tip #362   Tar remote dir over SSH

If you work on remote boxes a lot, you ll probably need a to backup a directory from there onto your machine sooner or later.. This can easilly be done using ssh & tar; all in 1 line of (script friendly) code:

Read more »