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 » unix The latest public unix snipts.

showing 1-20 of 85 snipts for unix
  • Execute a Unix Command with Node.js
    // http://nodejs.org/api.html#_child_processes
    var sys = require('sys')
    var exec = require('child_process').exec;
    var child;
    
    // executes `pwd`
    child = exec("pwd", function (error, stdout, stderr) {
      sys.print('stdout: ' + stdout);
      sys.print('stderr: ' + stderr);
      if (error !== null) {
        console.log('exec error: ' + error);
      }
    });
    

    copy | embed

    0 comments - tagged in  posted by viatropos on Aug 15, 2010 at 3:37 p.m. EDT
  • Tail Log Output with Node.js
    // http://nodejs.org/api.html#_child_processes
    var sys = require('sys')
    var spawn = require('child_process').spawn;
    var filename = process.ARGV[2];
    
    if (!filename)
      return sys.puts("Usage: node <server.js> <filename>");
    
    var tail = spawn("tail", ["-f", filename]);
    sys.puts("start tailing");
    
    tail.stdout.on("data", function (data) {
      sys.puts(data);
    });
    
    // node tail.js development.log
    

    copy | embed

    0 comments - tagged in  posted by viatropos on Aug 15, 2010 at 2:43 p.m. EDT
  • Change ownership of a file
    chown -R wwwrun:www
    

    copy | embed

    0 comments - tagged in  posted by pazzypunk on Aug 04, 2010 at 2:32 p.m. EDT
  • A class that help you to convert dates to and from unix date format from .net datetime class
    /// <summary>
    /// Convertions between DateTime and unix time representations
    /// </summary>
    public class TimeHelper
    {
            /// <summary>
    	/// The base time 01/01/1970 12:00 am
    	/// </summary>
    	static DateTime baseTime = new DateTime(1970, 1, 1, 0, 0, 0);
    
    	/// <summary>
    	/// Covert the current date to the miliseconds  01/01/1970 12:00 am 
    	/// </summary>
    	/// <param name="current">The date to convert</param>
    	/// <returns>miliseconds  since 01/01/1970 12:00 am</returns>
    	public static string CFNormalization(DateTime current)
    	{
    		return (long)(current.Subtract(baseTime)).TotalMilliseconds+"";
    
    	}
    
    	/// <summary>
    	/// Convert from milisecond since 01/01/1970 12:00 am to DateTime
    	/// </summary>
    	/// <param name="miliseconds">The milisecond to convert</param>
    	/// <returns>DateTime that represent the date since 01/01/1970 12:00</returns>
    	public static DateTime CFDenormalization(long miliseconds)
    	{
    		return baseTime.AddMilliseconds(miliseconds);
    
    	}
    
    }
    

    copy | embed

    0 comments - tagged in  posted by dilaang on May 20, 2010 at 11:08 a.m. EDT
  • MacOS X all processes
    --show all processes except Dashboard
    ps -cm -U username | awk '/:/ && $5!~/Dashboard/'
    

    copy | embed

    0 comments - tagged in  posted by d13t on Apr 28, 2010 at 3:47 a.m. EDT
  • Very interesting way to generate a random string. Doesn't work on Snow Leopard tho.
    </dev/urandom tr -dc A-Za-z0-9./%? | head -c 10
    

    copy | embed

    0 comments - tagged in  posted by mandric on Apr 16, 2010 at 10:23 a.m. EDT
  • install Drush from CVS HEAD on any unix server
    ##
    ## Installs Drush (the Drupal Shell command line utility) from CVS HEAD 
    ## on any UNIX machine, such that all users that have /usr/local/bin in
    ## their $PATH can use Drush (granted they have access to a Drupal install).
    ##
    ##
    
    cd /usr/local/src
    cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d drush-HEAD contributions/modules/drush/
    curl -O http://download.pear.php.net/package/Console_Table-1.1.3.tgz
    tar zxvf Console_Table-1.1.3.tgz
    cp Console_Table-1.1.3/Table.php drush-HEAD/includes/table.inc
    ln -s /usr/local/src/drush-HEAD/drush /usr/local/bin/drush
    
    ##
    ## now any user that has /usr/local/bin in their $PATH can use Drush.
    ##
    ##
    ## ... later on, to keep drush up to date, run the following:
    
    #cd /usr/local/src/drush-HEAD
    #cvs update -dPA
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Mar 05, 2010 at 11:38 a.m. EST
  • find and delete
    find . -name "FILE-TO-FIND"-exec rm -rf {} \;
    

    copy | embed

    0 comments - tagged in  posted by mccu7pj2 on Mar 02, 2010 at 10:51 a.m. EST
  • Showing Unix System listening ports
    $ netstat -ntlup
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
    tcp        0      0 0.0.0.0:20000               0.0.0.0:*                   LISTEN      28946/perl          
    tcp        0      0 0.0.0.0:2273                0.0.0.0:*                   LISTEN      28855/mysqlmanager  
    tcp        0      0 0.0.0.0:199                 0.0.0.0:*                   LISTEN      28193/snmpd         
    tcp        0      0 127.0.0.1:10025             0.0.0.0:*                   LISTEN      22267/amavisd (mast 
    tcp        0      0 172.26.0.5:3306             0.0.0.0:*                   LISTEN      30760/mysqld        
    tcp        0      0 127.0.0.1:10026             0.0.0.0:*                   LISTEN      22389/smtpd         
    tcp        0      0 0.0.0.0:139                 0.0.0.0:*                   LISTEN      28352/smbd          
    tcp        0      0 127.0.0.1:3310              0.0.0.0:*                   LISTEN      28420/lt-clamd      
    tcp        0      0 127.0.0.1:10030             0.0.0.0:*                   LISTEN      28242/postgrey -d - 
    tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN      23007/pop3-login    
    tcp        0      0 127.0.0.1:783               0.0.0.0:*                   LISTEN      22298/perl          
    tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN      28148/dovecot       
    tcp        0      0 0.0.0.0:10000               0.0.0.0:*                   LISTEN      802/httpd           
    tcp        0      0 172.26.0.5:80               0.0.0.0:*                   LISTEN      802/httpd           
    tcp        0      0 127.0.0.1:8118              0.0.0.0:*                   LISTEN      28269/privoxy       
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      28199/sshd          
    tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      22339/smtpd         
    tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      28320/perl          
    tcp        0      0 0.0.0.0:445                 0.0.0.0:*                   LISTEN      28352/smbd          
    tcp        0      0 :::22                       :::*                        LISTEN      28199/sshd          
    udp        0      0 172.26.0.5:137              0.0.0.0:*                               28361/nmbd          
    udp        0      0 0.0.0.0:137                 0.0.0.0:*                               28361/nmbd          
    udp        0      0 172.26.0.5:138              0.0.0.0:*                               28361/nmbd          
    udp        0      0 0.0.0.0:138                 0.0.0.0:*                               28361/nmbd          
    udp        0      0 0.0.0.0:10000               0.0.0.0:*                               28320/perl          
    udp        0      0 0.0.0.0:20000               0.0.0.0:*                               28946/perl          
    udp        0      0 0.0.0.0:161                 0.0.0.0:*                               28193/snmpd         
    udp        0      0 0.0.0.0:53455               0.0.0.0:*                               27475/avahi-daemon: 
    udp        0      0 0.0.0.0:5353                0.0.0.0:*                               27475/avahi-daemon: 
    udp        0      0 172.26.0.5:123              0.0.0.0:*                               28787/ntpd          
    udp        0      0 127.0.0.1:123               0.0.0.0:*                               28787/ntpd          
    udp        0      0 0.0.0.0:123                 0.0.0.0:*                               28787/ntpd          
    udp        0      0 fe80::21e:90ff:fe29:123     :::*                                    28787/ntpd          
    udp        0      0 ::1:123                     :::*                                    28787/ntpd          
    udp        0      0 :::123                      :::*                                    28787/ntpd 
    

    copy | embed

    0 comments - tagged in  posted by yvoictra on Jan 17, 2010 at 8:38 a.m. EST
  • List subdirectories of curren directory.
    #include <dirent.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <string.h>
    #include <errno.h>
    #include <sys/stat.h>
    
    int main(int argc, char *argv[])
    {
    	DIR *d;
    	struct dirent *de;
    
    	d = opendir(".");
    	if (!d) {
    		perror("opening current directory");
    		exit(1);
    	}
    
    	errno = 0;
    	for (;;) {
    		de = readdir(d);
    		if (de == NULL)
    			break;
    		struct stat file_info;
    		memset(&file_info, 0, sizeof (file_info));
    		if (de->d_name[0] == '.')
    			continue;
    		if (stat(de->d_name, &file_info) == 0) {
    			if ((file_info.st_mode & S_IFMT) == S_IFDIR) {
    				printf("%s\n", de->d_name);
    			}
    		} else {
    			printf("stat() error %s on file %s\n",
    				strerror(errno), de->d_name);
    		}
    	}
    
    	if (errno != 0)
    		perror("reading directory");
    
    	closedir(d);
    	return 0;
    }
    

    copy | embed

    0 comments - tagged in  posted by marcbutler on Dec 25, 2009 at 12:17 a.m. EST
  • Shell script to read local IP address (works on GNU/Linux, *BSD and Solaris)
    #!/bin/sh
    # Shell script to read IP address
    # -------------------------------------------------------------------------
    # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
    # This script is licensed under GNU GPL version 2.0 or above
    # -------------------------------------------------------------------------
    # This script is part of nixCraft shell script collection (NSSC)
    # Visit http://bash.cyberciti.biz/ for more information.
    # -------------------------------------------------------------------------
    # Get OS name
    
    OS=`uname`
    IO="" # store IP
    case $OS in
       Linux) IP=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
       FreeBSD|OpenBSD) IP=`ifconfig  | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
       SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
       *) IP="Unknown";;
    esac
    echo "$IP"
    

    copy | embed

    0 comments - tagged in  posted by d1s4st3r on Dec 03, 2009 at 3:27 a.m. EST
  • forget the crontab man
    #minute (0-59),
    #|      hour (0-23),
    #|      |       day of the month (1-31),
    #|      |       |       month of the year (1-12),
    #|      |       |       |       day of the week (0-6 with 0=Sunday).
    #|      |       |       |       |       commands
    0       2       *       *       0,4     /etc/cron.d/logchecker
    

    copy | embed

    1 comment - tagged in  posted by juque on Nov 11, 2009 at 6:57 a.m. EST
  • check folder size
    % du -hs /path/to/directory
    

    copy | embed

    0 comments - tagged in  posted by chawei on Nov 04, 2009 at 8:45 a.m. EST
  • linux permission
    # permission
    useradd new-user
    chown new-user somefile
    
    groupadd new-group
    chgrp new-group somefile
    
    % chown user file
    % chown :group file
    % chown user:group file
    % chown -fR user:group file
    

    copy | embed

    0 comments - tagged in  posted by chawei on Oct 17, 2009 at 1:28 p.m. EDT
  • List Todays Modified Files
    find . -mtime -1 -type f -exec ls -lt {} \;
    

    copy | embed

    1 comment - tagged in  posted by elaforc on Sep 28, 2009 at 9:57 a.m. EDT
  • size of directories
    du -h —max-depth=1
    

    copy | embed

    0 comments - tagged in  posted by sevitzdotcom on Sep 26, 2009 at 7:27 a.m. EDT
  • file system usage
    df -h
    

    copy | embed

    0 comments - tagged in  posted by sevitzdotcom on Sep 26, 2009 at 7:26 a.m. EDT
  • check fcgi
    ps aux | grep fcgi
    

    copy | embed

    0 comments - tagged in  posted by chawei on Aug 28, 2009 at 9:03 a.m. EDT
  • disable Spotlight
    // disable spotlight indexing
    
    sudo mdutil -i off  
    
    // enable spotlight indexing
    
    sudo mdutil -i on
    
    // delete existing spotlight indexes
    sudo mdutil -E 
    
    // some other options:  -s = display status, -v = verbose
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 27, 2009 at 3:30 a.m. EDT
  • symbolic link
    #syntax to create symbolic link
    ln -s /export/space/common/archive /archive
    
    #example, link would be created in directory 'placement'
    ln -s /path/to/original/file/or/directory /path/to/the/placement
    
    #dropbox example
    ln -s /Users/username/Dropbox/theFolder /path/to/symbolic/links/directory
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 21, 2009 at 8:24 a.m. EDT
Sign up to create your own snipts, or login.