IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » bash The latest public bash snipts.

showing 21-40 of 578 snipts for bash
  • Tar gz (ok compression, fast)
    tar -zcvf archive_name.tar.gz directory_to_compress
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:53 p.m. EDT
  • Untar to directory
    tar -xvf archive_name.tar -C /tmp/extract_here/
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:53 p.m. EDT
  • Untar
    tar -xvf archive_name.tar.gz
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:53 p.m. EDT
  • Tar
    tar -cvf archive_name.tar directory_to_compress
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:52 p.m. EDT
  • Unzip
    unzip archive_name.zip
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:52 p.m. EDT
  • Zip
    zip -r archive_name.zip directory_to_compress
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:52 p.m. EDT
  • Validate IP in bash
    #!/bin/bash
    
    # Test an IP address for validity:
    # Usage:
    #      valid_ip IP_ADDRESS
    #      if [[ $? -eq 0 ]]; then echo good; else echo bad; fi
    #   OR
    #      if valid_ip IP_ADDRESS; then echo good; else echo bad; fi
    #
    function valid_ip()
    {
        local  ip=$1
        local  stat=1
    
        if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
            OIFS=$IFS
            IFS='.'
            ip=($ip)
            IFS=$OIFS
            [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
                && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
            stat=$?
        fi
        return $stat
    }
    
    # If run directly, execute some tests.
    if [[ "$(basename $0 .sh)" == 'valid_ip' ]]; then
        ips='
            4.2.2.2
            a.b.c.d
            192.168.1.1
            0.0.0.0
            255.255.255.255
            255.255.255.256
            192.168.0.1
            192.168.0
            1234.123.123.123
            '
        for ip in $ips
        do
            if valid_ip $ip; then stat='good'; else stat='bad'; fi
            printf "%-20s: %s\n" "$ip" "$stat"
        done
    fi
    

    copy | embed

    0 comments - tagged in  posted by yvoictra on Jul 23, 2010 at 6:10 a.m. EDT
  • Bulk File Rename
    # Bulk File Rename
    # 'sed' command is used here to replace the filename with 'mv' command
    # which is then piped to Shell -
    # Search for '*' and replace with 'mv "<FILENAME>" <FILENAME>.old'
    # and pipe it to Shell
    ls *.* | sed -e 's/\(.*\)/mv "\1" "\1.old"/' | sh
    
    # To rename *.php3 files to *.php3.old
    ls *.php3 | sed -e 's/\(.*\)/mv "\1" "\1.old"/' | sh
    
    # To rename *.php3 files to *.php
    ls *.php3 | sed -e 's/\(.*\).php3/mv "\1.php3" "\1.php"/' | sh
    

    copy | embed

    0 comments - tagged in  posted by winker on Jul 22, 2010 at 7:52 a.m. EDT
  • Converts windows line ending to Unix/Linux line ending
    perl -pi -e 's/\r\n/\n/g' <input-file>
    

    copy | embed

    0 comments - tagged in  posted by mailo on Jul 20, 2010 at 3:58 p.m. EDT
  • Verify signatures
    # Import a public key
    gpg --import <public_key>.asc
    
    # Verify a signature
    gpg --verify <file_name>.asc
    
    # To surpress the warning, trust public keys
    #  shows the long identifier of the public key
    gpg --with-colons --list-keys "<public_key>"
    #  trusts it
    gpg --trusted-key 0123456789ABCDEF --update-trustdb
    

    copy | embed

    0 comments - tagged in  posted by dalord on Jul 20, 2010 at 9:46 a.m. EDT
  • calculator
    #!/bin/bash
    
    while [ $ != 'x' ]
    do
    echo "Welcome to calculator (x to quit)"
    echo "Enter the first operand: "
    read value1
    echo "Enter an operator (+, -, *, /): "
    read operator
    echo "Enter the second operand: "
    read value2
    if [ " $ operator " = " + " ] ; then
    answer=$(echo "scale=2;value1+value2" |bc);
    elif [ " $ operator " = " - " ] ; then
    answer=$(echo " scale=2;value1-value2" |bc);
    elif [ " $ operator " = " / " ] ; then
    answer=$(echo "scale=2;value1/value2" |bc);
    elif [ " $ operator " = " * " ] ; then
    answer=$(echo "scale=2;value1*value2" |bc);
    elif [ " $ operator " = " % " ] ; then
    answer=$(echo "scale=2;value1%value2" |bc);
    fi
    echo "Answer: $value1 $operator $value2 = $answer";
    done
    

    copy | embed

    0 comments - tagged in  posted by eriksulymosi on Jul 15, 2010 at 11:18 a.m. EDT
  • Configurar interfaz virtual en Linux
    ; Importante si te quieres comunicar con otra red :D
    
    # ifconfig ethx:1 IP
    

    copy | embed

    0 comments - tagged in  posted by edh on Jul 14, 2010 at 1:18 p.m. EDT
  • Cambiar MAC Adress en Linux
    ; El cambio no es permanente 
    
    # ifconfig ethx down
    # ifconfig ethx hw ether 00:AA:BB:CC:11:22
    # ifconfig ethx up
    

    copy | embed

    1 comment - tagged in  posted by edh on Jul 14, 2010 at 1:05 p.m. EDT
  • Disable ping reply
    # Disable ping reply temporarily
    echo "1" >  /proc/sys/net/ipv4/icmp_echo_ignore_all
    
    # Enable the ping reply back
    echo "1" >  /proc/sys/net/ipv4/icmp_echo_ignore_all
    

    copy | embed

    0 comments - tagged in  posted by d1s4st3r on Jul 09, 2010 at 5:00 a.m. EDT
  • Check if gzip/delfate is enabled (2 ways)
    curl -I -H "Accept-Encoding: gzip,deflate" "$URL"  --silent | grep -i "Content-Encoding:"
    
    # OR
    curl -H "Accept-Encoding: gzip,deflate" "$URL" --silent --write-out "%{size_download}"  --output /dev/null
    curl "$URL" --silent --write-out "%{size_download}"  --output /dev/null
    # 2nd must be greater the 1st
    

    copy | embed

    0 comments - tagged in  posted by timendum on Jun 29, 2010 at 10:52 a.m. EDT
  • Script that tests if a given value is a positive integer
    #!/bin/bash
    
    VALUE=3
    
    if [[ $VALUE =~ ^[0-9]+$ ]]; then
    	echo "$VALUE is an integer"
    else
    	echo "$VALUE is not an integer"
    fi
    

    copy | embed

    0 comments - tagged in  posted by d1s4st3r on Jun 18, 2010 at 11:03 a.m. EDT
  • Simple Python HTTP Server
    python -m SimpleHTTPServer
    

    copy | embed

    0 comments - tagged in  posted by jonbiddle on Jun 17, 2010 at 9:14 a.m. EDT
  • Script that determines the MIME type of a file
    #!/bin/bash
    ##########################################################################
    # Title      :	getmimetype - determine MIME type of file
    # Author     :	Heiner Steven <heiner.steven@odn.de>
    # Date       :	1999-08-24
    # Requires   :	[ngm]awk
    # Category   :	Mail
    # SCCS-Id.   :	@(#) getmimetype	1.7 06/07/19
    ##########################################################################
    
    PN=`basename "$0"`			# Program name
    VER='1.7'
    
    : ${LOCALLIB:=/usr/local/lib}
    
    # We need a new version of AWK, i.e. "nawk" or "gawk"
    awk=
    for path in `echo "$PATH" | sed 's/^:/.:/;s/:$/:./;s/:/ /g'`
    do
        for p in mawk gawk nawk
        do
        	[ -x "$path/$p" ] || continue
    	awk=$path/$p; break 2
        done
    done
    : ${NAWK:=${awk:=awk}}
    
    Usage () {
        echo >&2 "$PN - determine MIME type of file, $VER
    usage: $PN file [file ...]
    
    Reads the files
    	$LOCALLIB/mimetypes
    	$HOME/.mimetypes"
        exit 1
    }
    
    Msg () {
        for MsgLine
        do echo "$PN: $MsgLine" >&2
        done
    }
    
    Fatal () { Msg "$@"; exit 1; }
    
    set -- `getopt h "$@"`
    [ $# -lt 1 ] && Usage			# "getopt" detected an error
    
    while [ $# -gt 0 ]
    do
        case "$1" in
    	--)	shift; break;;
    	-h)	Usage;;
    	-*)	Usage;;
    	*)	break;;			# First file name
        esac
        shift
    done
    
    MimeTypes=${TMPDIR:=/tmp}/pmt$$
    trap 'rm -f "$MimeTypes" >/dev/null 2>&1' 0
    trap "exit 2" 1 2 3 15
    
    > "$MimeTypes"
    for file in $LOCALLIB/mimetypes $HOME/.mimetypes
    do
        if [ -r "$file" ]
        then
        	cat "$file" >> "$MimeTypes"
        fi
    done
    
    # Define some MIME type defaults
    cat <<-EOT >> "$MimeTypes"
    	# MIME type		File Extensions
    	text/plain		.*\.[tT][eE][xX][tT]$ .*\.[tT][xX][tT]$
    	text/html		.*\.[hH][tT][mM]$ .*\.[hH][tT][mM][lL]$
    
    	image/jpeg		.*\.[jJ][pP][eE][gG]$ .*\.[jJ][pP][gG]$
    	image/gif		.*\.[gG][iI][fF]$		
    	image/png		.*\.[pP][nN][gG]$		
    
    	video/mpeg		.*\.[mM][pP][eE][gG]$ .*\.[mM][pP][gG]$
    	video/avi		.*\.[aA][vV][iI]$
    
    	application/postscript	.*\.[pP][sS]$	
    	application/pdf		.*\.[pP][dD][fF]$
    
    	audio/basic		.*\.[aA][uU]$
    	audio/wav		.*\.[wW][aA][vV]$
    	audio/mp3		.*\.[mM][pP]3$
    	EOT
    
    for file
    do
        [ -f "$file" ] || continue
        if file "$file" | grep -i text >/dev/null
        then defaulttype=text/plain
        else defaulttype=application/octet-stream
        fi
        echo "$defaulttype	$file"
    done |
        $NAWK '
        	BEGIN {
    	    # Read the MIME type table
    	    mimetypes = "'"$MimeTypes"'"
    	    while ( getline < mimetypes ) {
    	    	if ( $1 ~ /^\#/ ) continue		# ignore comments
    		if ( $0 ~ /^[ 	]*$/ ) continue	# ignore empty lines
    
    		if ( (k = split ($0, f)) > 1 ) {
    		    mimetype = f [1]
    		    for ( i=2; i<=k; i++ ) typeOf [$i] = mimetype
    		}
    	    }
    	    close (mimetypes)
    	    #for ( i in typeOf ) print "<" i ">", typeOf [i]
    	}
    	{
    	    mimetype = ""
    	    for ( t in typeOf )  {
    	    	if ( $0 ~ t ) {
    		    mimetype = typeOf [t]
    		    break
    		}
    	    }
    	    if ( mimetype == "" ) mimetype = $1
    	    print mimetype
    	}
        '
    

    copy | embed

    0 comments - tagged in  posted by d1s4st3r on Jun 17, 2010 at 9:09 a.m. EDT
  • replace string in files
    #!/bin/bash
    for file in *.groovy
    do
      echo "Traitement de $file ..."
      sed -e "s/string1/string2/g" "$file" > "$file".tmp && mv -f "$file".tmp "$file"
    done
    

    copy | embed

    2 comments - tagged in  posted by Bakoi on Jun 16, 2010 at 5:27 a.m. EDT
  • grep find
    # grep find excluding .svn directories
    # from http://wordaligned.org/articles/ignoring-svn-directories
    alias gf='find . -path "*/.svn" -prune -o -type f -print0 | xargs -0 grep -I -n'
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jun 15, 2010 at 9:07 p.m. EDT
Sign up to create your own snipts, or login.