Skip to content

Instantly share code, notes, and snippets.

@NapoleonWils0n
NapoleonWils0n / wordpress_vhost.txt
Created November 2, 2012 01:14
apache: wordpress apache virtual host
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DirectoryIndex index.php
DocumentRoot /var/www/wordpress/html/
<Directory /var/www/wordpress/html/>
Options -Indexes
@NapoleonWils0n
NapoleonWils0n / WWW_: No-WWW.txt
Created November 2, 2012 01:15
apache: rewrite no www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^your-site.com [NC]
RewriteRule ^(.*)$ http://www.your-site.com/$1 [L,R=301]
@NapoleonWils0n
NapoleonWils0n / arg_check.sh
Created November 2, 2012 01:21
bash: argument check
#!/bin/sh
# check how many arguments are passed to the script
# if less than 3 arguments are passed to the script, print an error and exit
if [[ $# < 3 ]]
then
printf "%b" "error not enough aruments"
exit 1 # exit with non zero
# if more than 3 arguments are passed to the script, print an error and exit
@NapoleonWils0n
NapoleonWils0n / awk.sh
Created November 2, 2012 01:24
bash: awk
#!/bin/sh
# print the first word of every line of input
awk '{print $1}' input.txt
# print the last line
ls -l | awk '{print $1, $NF}
@NapoleonWils0n
NapoleonWils0n / bash_alias.sh
Created November 2, 2012 01:24
bash: bash alias
ln -s path/to/source path/to/alias
@NapoleonWils0n
NapoleonWils0n / bash_file_testing.sh
Created November 2, 2012 01:43
bash: bash file testing
#!/bin/sh
# Bash File Testing
# -b filename Block special file
# -c filename Special character file
# -d directoryname Check for directory existence
# -e filename Check for file existence
# -f filename Check for regular file existence not a directory
# -G filename Check if file exists and is owned by effective group ID.
@NapoleonWils0n
NapoleonWils0n / bash_tricks.sh
Created November 2, 2012 01:45
bash: show only dot files
# ===========================================================
# = Showing All Hidden (dot) Files in the Current Directory =
# ===========================================================
# Use ls -d along with whatever other criteria you have.
ls -d .*
ls -d .b*
ls -d .[!.]*
@NapoleonWils0n
NapoleonWils0n / braces.sh
Created November 2, 2012 01:46
bash: list files with braces
ls *.{jpg,gif}
@NapoleonWils0n
NapoleonWils0n / brackets.sh
Created November 2, 2012 01:47
bash: brackets
#!/bin/sh
#Square brackets—matches any of a series of characters in a filename.
#For example, ls a[rn]t.jpg matches art.jpg and ant.jpg, but does not match aft.jpg.
#If the first character is a caret (^), it matches every character except for the characters l
ls a[rn]t.jpg
@NapoleonWils0n
NapoleonWils0n / cd_to_previous_directory.sh
Created November 2, 2012 01:48
bash: cd to previous directory
# cd to previous directory
cd -