Showing posts from January, 2014

Linux Command line tips and Bash stuff

Linux Command Line Tips and Many More

Here is a selection of command-line tips that I've found useful when working on Linux. The emphasis is on somewhat less-known techniques that are generally important or useful to technical users. It's a bit long, and users certainly don't need to know all of them, but I've done my best to review that each item is worth reading in terms of projected time savings, if you use Linux heavily.

To get more information on a command mentioned, first try "man <command name>". In some cases, you must install a package for this to work -- try aptitude or yum. If that fails, Google it.


Learn basicBash. Actually, read the whole bash man page; it's pretty easy to follow and not that long. Alternate shells can be nice, but bash is powerful and always available (learning mainly zsh or tcsh restricts you in many situations).Learn vim. There's really no competition for random Linux editing (even if you use Emacs or Eclipse …


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{…