Monday, February 26, 2007

Common Unix/Linux Commands

To list the content of a file:
    $ cat filename |more
To extract .tar.gz file:
    $ tar -xzvf filename.tar.gz
To modify user specific shell setting, edit the User Dependent File: .bashrc

To create an alias:
    $ alias ll='ls -l'
    $ alias la='ls -A'
    $ alias grep='grep --color'

    # My alias in Cygwin
    $ alias emacs='/cygdrive/c/bin/emacs-23.1/bin/runemacs.exe'
    $ alias firefox='cygstart /cygdrive/c/Program\ Files\ \(x86\)/Mozilla\ Firefox/firefox.exe'
To create file/folder links:
    $ ln -s target symbolic_name    # create a symbolic link
    $ ln target hard_link_name      # create a hard link
To temporary go to the directory of an application:
    $ pushd `which gcc`             # the command inside backticks always run first.
    $ popd                          # go back the current directory.
To extract just the path from a filename use dirname:
   $ dirname /usr/bin/sort          # output "/usr/bin"
   $ dirname stdio.h                # output "."
   Script: cd "`dirname \"$0\"`"    # go to the folder that contains this script file

How to Find a file in Linux/Unix

To find all file with a '~' end recursively:
   $ find -name "*~"
To find a file 'abc*', case insensitively, starting from root:
   $ find / -iname 'abc*'
More advanced search:
   # find files with size less than 5000k
   $ find /some/folder -name '*.mov' -size -5000k

   # find files with size more than 10MB
   $ find / -size +10000k

   # find files accessed in the last 10 minutes
   $ find / -amin -10 -name '*.log'
   $ find / -mmin -10 -name '*.log'   # modified in the last 10 mins.
   $ find / -atime -5 -name '*.log'   # accessed in the last 5 hours.
   $ find / -mtime -5 -name '*.log'   # modified in the last 5 hours.

Other Tools

Cygwin Consoles:
    $ MinTTY    # a lightweight console with lots of useful features
    $ Console2/Console.exe
File Management Utilities:
    $ mc    # Midnight Commander (similar to Norton Commander.)
Games:
    $ typespeed    # a typing game

  To modify the word list used in typespeed, go to "/usr/share/typespeed/words/".

No comments:

Post a Comment