vaheeD khoshnouD

linux, mikrotik, macosx

Bash Rules

Written by vaheeD on December 28, 2012
4.00 avg. rating (84% score) - 1 vote


Environment Variables

these variables can be saved in ~/.bash_profile or ~/.bashrc

decide which command lines should not be saved on the history list

HISTIGNORE="&:[ ]*:ls:exit"

list of search paths for commands:

PATH="$PATH:/usr/local/sshfs/bin/"

list of directories used as search path for the “cd” command

CDPATH="/root/Desktop"

list of directories used as search path for the “man” command

MANPATH="$MANPATH:/usr/local/sshfs/share/man/"


Colorful prompt

# Bright
PS1="\n\[\e[1;31m\]\t - \d\n\[\e[1;32m\]\u@\H:\[\e[1;36m\]\w \\$ \[\e[0m\]"
# Dark 
PS1="\n\[\e[0;31m\]\@ - \d\n\[\e[0;33m\]\u@\H:\[\e[0;32m\]\w\\$ \[\e[0m\]"

Login timeout seconds

TMOUT="600"

Current process PID

echo $$

The number of seconds the script has been running

echo $SECONDS

Command Substitution

old-style

kill -TERM `cat /var/run/ppp0.pid`

new-style

kill -TERM $(cat /var/run/ppp0.pid)

Special shorcuts

run last command

!!

reuse last parameter (you can use <ESC+.> instead)

cd !$

clear command line to start

[ctrl-u]

clear command line to end

[ctrl-k]

jump to end of line

[ctrl-e]

jump to start of line

[ctrl-a]

upper case to end of word

[alt-u]

lower case to end of word

[alt-l]

word forward

[alt-f]

word backward

[alt-b]

run last command containing word

!?word?[space]

first parameter of last command

!:1[space]

all arguments of the previous command

!-1:1*[space]

third argument from the command before the last one

!-2:3[space]

search history(can be repeated)

[ctrl+r]

Standard Error Redirection

1 represents stdout
2 represents stderr

stdout to file :

command > file

stderr to file :

command 2> file

stdout to stderr :

command 1>&2

stderr to stdout :

command 2>&1

stderr and stdout to file :

command > /dev/null 2>&1
command &> /dev/null

 

4.00 avg. rating (84% score) - 1 vote

Posted Under: Linux, Macosx

About vaheeD

Leave a Reply

Your email address will not be published. Required fields are marked *

Protected by WP Anti Spam