> file redirects stdout to file
1> file redirects stdout to file
2> file redirects stderr to file
&> file redirects stdout and stderr to file

You can redirect stdout to stderr by doing 1>&2

echo test 1>&2 

1 is stdout. 2 is stderr.

Here is one way to remember this construct (altough it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as “redirect stderr to a file named 1“. & indicates that what follows is a file descriptor and not a filename. So the construct becomes: 2>&1.




find . | grep “x” —–print many warnings like “xx/yy/zz” is a directory


1) find . -type f | grep “x”

type “f”  means a regular file.

2) git grep




  • OS-X ctrl + l (alternative: clear) it is not really clean screen, it just move log up out current screen so you still able to scroll it.  When you press command + k it really clear console.
  • cd -; get back to the directory u were previously in.
  • echo; kind of printf
  • (cd /tmp && ls)
    Jump to a directory, execute a command and jump back to current dir
  • tail – output the last part of files (default is 10 lines)
  • ps aux | grep firefox; http://superuser.com/questions/117913/ps-aux-output-meaning
  • ps aux | sort -b -k  +4 | tail; Display the top ten running processes – sorted by memory usage
  • ps aux | sort -b -k  +3 | tail; Display the top ten running processes – sorted by CPU usage;
  • sort -k position (start with 1)
  • echo “!!” > foo.sh; Create a script of the last executed command
  • http://www.thegeekstuff.com/2008/08/15-examples-to-master-linux-command-line-history/
  • history; list of history commands
  • !5; run the 5th command in the history list
  • rm !(*.foo|*.bar|*.baz)
  • pgrep firefox = Get the PID of a process by name
  • ls -R | grep “:$” | sed -e ‘s/:$//’ -e ‘s/[^-][^\/]*\//–/g’ -e ‘s/^/ /’ -e ‘s/-/|/’;  same as tree command, but there is no “tree” command on mac OS;
  • mkdir -p a/long/directory/path
    Make directory including intermediate directories;you can also use the list notation:mkdir -p root/child0/child1/{ab,cd,de,ef}will create 4 directories named ‘ab’, ‘cd’, ‘de’, ‘ef’ in root/child0/child1.

  • cat ~/.ssh/id_rsa.pub | ssh user@machine “mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys”; Copy your SSH public key on a remote machine for passwordless login; Copy your ssh public key to a server from a machine that doesn’t have ssh-copy-id


create symlink


How do I create soft link / symbolic link?

To create a symbolic link in Unix or Linux, at the shell prompt, enter the following command:
ln -s {target-filename} {symbolic-filename}

For example create softlink for /webroot/home/httpd/test.com/index.php as /home/vivek/index.php, enter the following command:
ln -s /webroot/home/httpd/test.com/index.php /home/vivek/index.php
ls -l


lrwxrwxrwx 1 vivek  vivek    16 2007-09-25 22:53 index.php -> /webroot/home/httpd/test.com/index.php