updatedb --prunepaths='/proc /cygdrive/[^/]*'
locate 'filename'
updatedb --prunepaths='/proc /cygdrive/[^/]*'
locate 'filename'
export VAR1="Hello"
export VAR2="World"
# WRONG: Interpreted as $VAR1_
echo "Create a file called $VAR1_$VAR2.log"
# CORRECT: Use quotes or brackets
echo "Create a file called ${VAR1}_${VAR2}.log"
echo "Create a file called "$VAR1"_"$VAR2".log"
$ ps -ef     # --everyone, --full
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Nov01 ?        00:00:00 init [3]
root         2     1  0 Nov01 ?        00:00:00 [migration/0]
root         3     1  0 Nov01 ?        00:00:00 [ksoftirqd/0]
$ ps -al     # --all (same as -e), --long
      PID    PPID    PGID     WINPID  TTY  UID    STIME COMMAND
     4516       1    4516       4516    ? 117771   Nov  4 /usr/bin/mintty
     5280    4516    5280       4412    2 117771   Nov  4 /usr/bin/bash
     5444    5280    5444        456    2 117771   Nov  4 /usr/bin/ssh
     6480       1    6480       6480    ? 117771   Nov  8 /usr/bin/mintty
# source the system wide bashrc if it exists
if [ -e /etc/bash.bashrc ] ; then
  source /etc/bash.bashrc
fi
# source the users bashrc if it exists
if [ -e "${HOME}/.bashrc" ] ; then
  source "${HOME}/.bashrc"
fi
# Set PATH so it includes Android SDK Tools
if [ -d "/cygdrive/c/sdk/android-sdk-windows/tools" ] ; then
    PATH=${PATH}:/cygdrive/c/sdk/android-sdk-windows/tools
fi
# Set Prompt to 'username@hostname:pwd\n'
export PS1="\[\e[0;33m\]\u\[\e[0m\]@\[\e[31m\]\h\[\e[39m\]:\w\n$ \[\e]2;\h:${PWD}\a\]"
# Default to human readable figures alias df='df -h' alias du='du -h' # Misc :) alias less='less -r' # raw control characters alias whence='type -a' # where, of a sort alias grep='grep --color' # show differences in color alias grep='grep --color --exclude-dir=.svn' # and exclude '.svn' folder alias rm='rm -i' # Some shortcuts for different directory listings if [[ "$(uname)" = "Linux" ]]; then alias ls='ls -hF --color=tty' # classify files in colour alias dir='ls --color=auto --format=vertical' alias vdir='ls --color=auto --format=long' fi alias ll='ls -l' # long list alias la='ls -A' # all but . and .. alias l='ls -CF' # # Programs and Binaries shortcuts alias emacs=/cygdrive/c/bin/emacs-23.2/bin/runemacs alias firefox="cygstart /cygdrive/c/Program\ Files/Mozilla\ Firefox/firefox.exe" alias mysql="cygstart /cygdrive/c/xampp/mysql/bin/mysql.exe" alias mysqldump='/cygdrive/c/xampp/mysql/bin/mysqldump.exe' alias php="/cygdrive/c/xampp/php/php.exe" alias junction='/cygdrive/c/bin/junction.exe' # Customized per workstation alias xampp_start=/cygdrive/c/xampp/xampp_start.exe alias xampp_stop=/cygdrive/c/xampp/xampp_stop.exe alias xampp_restart=/cygdrive/c/xampp/xampp_restart.exe alias todo="emacs ~/docs/secure/todos.org"
set -o vi.
Desired Action Shortcut Keys Auto Complete [Tab]Move to Beginning of Line [Ctrl]aMove to End of Line [Ctrl]eClear Screen [Ctrl]lthat's LClear Line before cursor [Ctrl]uClear Line after cursor [Ctrl]kClear Word before cursor [Ctrl]wClear Word after cursor [Alt]dYank/Paste from Clipboard [Ctrl]yCapitalize Current Word [Alt]uChange Current Word to Lower Case [Alt]lCapitalize First Letter [Alt]cCancel Changes and Restore the Line as in History [Alt]r
# Compress and Tar $ tar cvf -To search and replace in multiple files,| gzip -c > tgzfile.tar.gz # Untar and Decompress $ gzip -dc tgzfile.tar.gz | tar xvf - 
perl -pi -w -e 's/search/replace/g;' *.html
     -e means execute the following line of code.
     -i means edit in-place
     -w write warnings
     -p loop
To convert multiple JPEG files into one PDF file, first, install ImageMagick, then run: convert *.jpg -adjoin [file].pdf
$ sudo !!
$ sudo bash -c "echo 'Hello world' > helloworld.txt" # -OR- $ echo "Hello world | sudo tee helloword.txt
$ cat /proc/cpuinfo $ cat /proc/meminfo
$ df -h
$ readlink /etc/localtime /usr/share/zoneinfo/America/Los_Angeles
# Print username with ':' as field-separator, -F fs --field-separator=fs
$ awk -F: '{ print $1 }' /etc/passwd
# Calculate the sum of the first column in file
$ awk '{ sum += $1 }; END { print sum }' file
# Reverse a list of arguments
$ echo 'col1 col2 col3' | awk '{ print $3, $2, $1 }'
col3 col2 col1
$ echo 'col1:col2:col3' |awk -F: '{ print $3 ":" $2 ":" $1}'
col3:col2:col1
$ ps ax | grep -v grep | grep httpd $ ps ax | grep -v grep | grep httpd > /dev/null && echo 'httpd is running.' # OR $ ps ax | grep -v grep | grep httpd > /dev/null || echo 'httpd is not running.'
SSLRequire %{HTTP_HOST} eq "www.mydomain.com"
# Turn on Rewriting
RewriteEngine on 
# Apply this rule If request does not arrive on port 443
RewriteCond %{SERVER_PORT} !443 
# RegEx to capture request, URL to send it to (tacking on the captured text, stored in $1), Redirect it, and this is last rule.
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R,L]
Redirect permanent / https://www.mydomain.com/
<NameVirtualHost 122.123.124.1:80>
    ServerName mywebsite.com:80
    ServerAlias http://www.mywebsite.com:80
    ServerAlias 122.123.124.1:80
    Redirect permanent / https://www.mywebsite.com/
</VirtualHost>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Make sure you have this line in your httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R,L]
$ /etc/init.d/httpd restart
$ mysqldump -u root -p database_name > dumpfile.sql - OR - $ mysqldump -u root -p --databases database_name > dumpfile.sqlAll Databases:
$ mysqldump -u root -p -A > dumpfile.sql - OR - $ mysqldump -u root -p --all-databases > dumpfile.sqlSelected Databases:
$ mysqldump -u root -p -D database_1 database_2 database_3 > dumpfile.sql - OR - $ mysqldump -u root -p --databases database_1 database_2 database_3 > dumpfile.sqlA Table in a Database:
$ mysqldump -u root -p --databases database_name --tables table_name > dumpfile.sql
$ mysqldump -u root -p --opt database_name | gzip > dumpfile.sql.gz
$ ssh user@host "mysqldump database_name | gzip -9" | gzip -d > dumpfile.sql
$ mysql -u root -p database_name < dumpfile.sql # For compressed dump $ gunzip < dumpfile.sql.gz | mysql -u root -p database_name
mysql> CREATE USER 'user1'@'localhost' IDENTIFIED BY 'password'; mysql> CREATE USER 'user1'@'%' IDENTIFIED BY 'password';If you know the password hash, you can add a PASSWORD prefix to your call like this:
mysql> CREATE USER 'user1'@'%' IDENTIFIED BY PASSWORD '*93840205958...';Make sure you know what is the default password encoding in use:
mysql> SHOW VARIABLES LIKE 'old_passwords'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | old_passwords | OFF | +---------------+-------+ 1 row in set (0.00 sec)Ref: http://dev.mysql.com/doc/refman/5.1/en/encryption-functions.html#function_password
-- Grant everything to user1 from any host mysql> GRANT ALL PRIVILEGES ON *.* TO 'user1'@'%' WITH GRANT OPTION; -- You can shorten ALL PRIVILEGES with ALL mysql> GRANT ALL ON *.* TO 'user1'@'localhost'; mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'user1'@'localhost'; mysql> FLUSH PRIVILEGES;
mysql> GRANT ALL ON *.* TO 'user1'@'localhost' IDENTIFIED BY 'password';To check privileges for an account:
mysql> SHOW GRANTS; mysql> SHOW GRANTS FOR 'user1'@'localhost'; +--------------------------------------------------------------------+ | Grants for user1@localhost | +--------------------------------------------------------------------+ | GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'user1'@'localhost' | +--------------------------------------------------------------------+
mysql> SET PASSWORD FOR 'user1'@'localhost' = PASSWORD('mypassword');
mysql> SET PASSWORD FOR 'user1'@'localhost' = OLD_PASSWORD('mypassword');
mysql> SET PASSWORD FOR 'user1'@'localhost' = 'password-hash-string';
mysql> REVOKE ALL PRIVILEGES ON *.* FROM 'user1'@'localhost';
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/joe/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/joe/.ssh/id_rsa. Your public key has been saved in /home/joe/.ssh/id_rsa.pub. The key fingerprint is: 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 joe@mycomputer The key's randomart image is: +--[ RSA 2048]----+ | | | | | | | | | | | | | | | | | | +-----------------+Copy your public key to host server:
$ scp ~/.ssh/id_rsa.pub joe@example.com:~/.ssh/joe@mycomputer.pubThen, log into your host server and create/append the public key to a file named, authorized_keys:
$ cat ~/.ssh/joe@mycomputer.pub >> ~/.ssh/authorized_keys $ chmod go-w ~/. ~/.ssh/authorized_keys $ chmod go-rwx ~/.sshhttp://www.openssh.org/faq.html#3.14
| Exit Code Number | Meaning | Example | Comments | 
|---|---|---|---|
| 1 | catchall for general errors | let "var1 = 1/0" | miscellaneous errors, such as "divide by zero" | 
| 2 | misuse of shell builtins, according to Bash documentation | Seldom seen, usually defaults to exit code 1 | |
| 126 | command invoked cannot execute | permission problem or command is not an executable | |
| 127 | "command not found" | possible problem with $PATH or a typo | |
| 128 | invalid argument to exit | exit 3.14159 | exit takes only integer args in the range 0 - 255 | 
| 128+n | fatal error signal "n" | kill -9 $PPID of script | $? returns 137 (128 + 9) | 
| 130 | script terminated by Control-C | Control-C is fatal error signal 2, (130 = 128 + 2, see above) | |
| 255* | exit status out of range | exit -1 | exit takes only integer args in the range 0 - 255 | 
#!/bin/bashTo produce some interesting debugging output information,
#!/bin/bash -xSet the passed arguments to an array, e.g.
$ foo.sh bar
args = ("$@")   # args = bar
Use "$#" to get the number of arguments, e.g.
if [ "$#" -ne 1 ]; then echo "Must have exactly one argument." exit 1 fiFind out if a file exists
if [ -f "foo.txt" ]; then cat foo.txt fi # Check if file does not exist if [ ! -f "foo.txt" ]; then echo "foo.txt not found!" fiTo get the return code from previous command, use
$?
somecommand if [ $? -eq 0 ] then echo "command ran successfully." else echo "somecommand failed." >&2 exit 1 fi
somecommand if [ $? -ne 0 ]; then # output to stderr echo "[`date`] [error]somecommand failed." >&2 exit 1 fi # output to stdout echo "[`date`] [notice]somecommand succeeded."To add timestamp to a command's output:
$ somecommand | sed "s/^/[`date`] /" # Timestamp the error message, too $ somecommand 2>&1 | sed "s/^/[`date`] /"To check to see if an environment variable is set, use
-z to check for zero-length string:
if [ -z "$TEST_VAR" ]
then
    export $TEST_VAR="some value"
fi
To unset an environment variable:
$ unset TEST_VAR
echo, use these option:
(Note: Linux/Unix does not interpret carriage return char: \r)
       -n     do not output the trailing newline
       -e     enable interpretation of backslash escapes
e.g.
$ echo -e "Hello\nWorld " Hello World $ echo -ne "Hello\nWorld " Hello World $To get the script's base name and directory:
SCRIPTNAME=`basename $0` SCRIPTDIR=`dirname $0`
$ dircolors -p > ~/.dircolorsI can also edit this file, '.dircolors', to customize my color scheme. Remember to re-login to see the changes.
    for i in /etc/profile.d/*.sh; do
        if [ -r "$i" ]; then
            if [ "$PS1" ]; then
                . $i
            else
                . $i >/dev/null 2>&1
            fi
        fi
    done
And under "/etc/profile.d/", I see a file called, colorls.sh.  In it I see the following code:
# color-ls initialization
alias ll='ls -l' 2>/dev/null
alias l.='ls -d .*' 2>/dev/null
COLORS=/etc/DIR_COLORS
[ -e "/etc/DIR_COLORS.$TERM" ] && COLORS="/etc/DIR_COLORS.$TERM"
[ -e "$HOME/.dircolors" ] && COLORS="$HOME/.dircolors"
[ -e "$HOME/.dir_colors" ] && COLORS="$HOME/.dir_colors"
[ -e "$HOME/.dircolors.$TERM" ] && COLORS="$HOME/.dircolors.$TERM"
[ -e "$HOME/.dir_colors.$TERM" ] && COLORS="$HOME/.dir_colors.$TERM"
[ -e "$COLORS" ] || return
eval `dircolors --sh "$COLORS" 2>/dev/null`
[ -z "$LS_COLORS" ] && return
if ! egrep -qi "^COLOR.*none" $COLORS >/dev/null 2>/dev/null ; then
        alias ll='ls -l --color=tty' 2>/dev/null
        alias l.='ls -d .* --color=tty' 2>/dev/null
        alias ls='ls --color=tty' 2>/dev/null
fi
So, the 'ls' color scheme file could be .dircolors, .dir_colors, or dircolors.xterm etc.
    regsvr32 /u shimgvw.dll
After running the above command, all photos and images will lose their thumbnails.
    regsvr32 shimgvw.dll
    regsvr32 /u shmedia.dll
Once the above command is run, the thumbnail preview will be disabled for all video, movie and other media files.  That includes: AVI, WMA, WMV, ASF, and WAV files.
    regsvr32 shmedia.dll
% ps -p $$ PID TTY TIME CMD 2222 pts/1 0:00 cshTo find out what OS you're using:
$ uname
Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.
  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type or "unknown"
  -i, --hardware-platform  print the hardware platform or "unknown"
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit