BASH TRICKS



Here are some awesome bash trick which will make you more productive on bash:

History expansion
    !! = previous command
    !$ = last word of previous command
    !-n = nth previous command
    !#$ = last word of current line
    !<start of command> will execute the command from history starting with letters after "!"

Brace Expansion:
    {a..b} = numbers a to b in order.
    {a,b,c} = words a, b, c. Useful for paths: touch /tmp/{foo,bar,baz}

Parameter Expansion:
Suppose that foo=/usr/local/blah.txt
    ${variable#word} = removes word from the beginning of variable. For example, ${foo#*/} = usr/local/blah.txt
    ${variable##word} = same thing, but removes longest pattern matching word. For example, ${foo##*/} = blah.txt
    ${variable%word} = removes word from end of variable. For example: ${foo%.txt} = /usr/local/blah
    ${variable%%word} = same thing but longest matching suffix

Process Substitution:
    <(command) = treats the output of command as a file. diff -u <(ssh web{1,2} cat /etc/passwd)) shows you a           unified diff between /etc/passwd on web1 and 2

Basically, the entire bash manpage is useful and awesome. Enjoy


Linuxskool thanks Daniel Chan for spreading words of trick.


Popular posts from this blog

Grsecurity: Configure RHEL5/6 Kernel for Grsecurity

Linux Command line tips and Bash stuff

How to check Perl Module version in Linux