Public
snipts » unix
showing 1-20 of 79 snipts for unix
-
∞ 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
-
∞ Bless CD To be opened automatically on mac when inserted
sudo bless -folder "/Volumes/VolumeName/" -openfolder "/Volumes/VolumeName/"
-
∞ Recursive dos2unix
# Convert DOS file to UNIX, replacing DOS characters with UNIX equivalent. for file in `find . -type f`; do dos2unix $file $file; done
-
∞ run unix command in background
nohup bash syncr.sh &
-
∞ Find with grep
find ./ -name *.* -exec grep -i "something" '{}' \; -print
-
∞ mirror website with wget
mkdir -p /var/www/mirror cd /var/www/mirror wget --mirror –w 2 –p --html-extension –-convert-links –P /var/www/mirror/site http://www.yourdomain.com -
∞ Get Current IP Address
ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1 }'



Linux in a Nutshell