Latest 100 public
snipts » unix
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); } });
-
∞ 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
-
∞ Change ownership of a file
chown -R wwwrun:www
-
∞ 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); } }
-
∞ MacOS X all processes
--show all processes except Dashboard ps -cm -U username | awk '/:/ && $5!~/Dashboard/' -
∞ 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
-
∞ 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
-
∞ find and delete
find . -name "FILE-TO-FIND"-exec rm -rf {} \;
-
∞ 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
-
∞ 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; }
-
∞ 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"
-
∞ 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
-
∞ check folder size
% du -hs /path/to/directory
-
∞ 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 -
∞ List Todays Modified Files
find . -mtime -1 -type f -exec ls -lt {} \;
-
∞ size of directories
du -h —max-depth=1 -
∞ file system usage
df -h
-
∞ check fcgi
ps aux | grep fcgi
-
∞ 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
-
∞ 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


