.. _cheatsheet: ################ Unix Cheat sheet ################ :download:`Unix Cheat sheet ` Change Working Directory:: cd go to your login (home) directory cd ~username go to username's login (home) directory cd .. go up one directory level from here cd ../.. go up two directory levels from here cd /path/to/dir go to cd path/to/dir go to path relative to here (no leading slash). Make a directory:: mkdir dirname make a directory identified by 'dirname' List files:: ls list contents of current directory ls -a include files with "." (dot files) ls -l list contents in long format ls -rt list contents, sort by time modified in reverse order Determine a file type:: file filename show the content type of 'filename' Display file contents:: cat filename show contents of filename less filename show contents of filename one page at a time head filename show first 10 lines of filename tail filename show last 10 lines of filename head -50 filename show first 50 lines of filename Move (or rename) a file or directory:: mv srcfile destfile rename srcfile to destfile mv srcfile destdir move a file into the destdir directory mv srcdir destdir rename srcdir to destdir; if destdir exists, then move to srcdir to destdir mv -i srcdir destdir same as above, but prompt before overwriting Copy a file or directory:: cp srcfile destfile make a copy of srcfile called and call it destfile cp srcfile destdir make a copy of srcfile, and place it in the destdir directory cp -R srcdir destdir copy srcdir (and contents) to destdir cp -i src dest same as above, but prompt before overwriting Remove a file:: rm filename remove (delete) filename rmdir dir remove an empty directory rm -r dir remove a directory and its contents rm -i filename remove filename, but prompt before deleting Redirection:: cmd1 | cmd2 "pipe" output from cmd1 to input of cmd2 command > filename direct output of command to filename, replacing contents of filename Search files for text string:: grep string filename show lines containing string in filename grep string filelist show lines containing string in any file in filelist grep -v string filelist show lines not containing string grep -i string filelist show lines containing string, ignore case grin pattern directory recursive through directory; show lines of all ascii files that match pattern Limit search with grep:: ls | grep pattern show output of ls that matches pattern Search directories for file name:: find . | grep pattern recurse through current directory; show file names that match pattern find ~ -name "*.nii" recurse through home directory; show file names that end with '.nii' Compress files or directories: See: :ref:`howto-compress` Show running process:: pgrep processname show processes called 'processname' ps -ef | grep username show all processes owned by username cssh pgrep processname show jobs called 'processname' on all workstations cssh ps -ef | grep usrname show jobs owned by username on all workstations Terminate a process that you own (running with your username):: ctrl-C kill foreground process kill pid# kill process identified by pid number (see 'ps' above) pkill processname kill process identified by 'processname' (see 'pgrep' above) Show system resources:: nxload show resources available on all workstations top show process information on this system top -u username show process information of username on this system User information:: finger username show information about username w show who is logged in to this system Show Sun Grid Engine queue:: qstats | less display SGE queue information one page at a time Change password: See: :ref:`password`