Linux Tips and Tricks
Unix/Linux Commands to Know and Cherish (with many thanks to Steve Lantz, CAC)
- Shell: bash or tcsh
- The shell defines many of the commands you enter at the command line
- The Bourne Again Shell is an update to the original Bourne shell (sh)
- Similarly tcsh is an update to csh, the C Shell (up-arrow to get last command)
- Getting help: man
man= "manual" = the way you get help, e.g.,man ls
- Working with directories: cd, pwd, ls, mkdir, rmdir
cd= change directory (popd,pushdto use directory stack);cd ..= up one levelpwd= print working directory = print your current location (also known as .)ls -lgives you complete directory listing,ls -alets you see .prefix-filesmkdirto create a new directory,rmdirto remove an existing one
- Environment variables: export (bash, sh) or setenv (tcsh, csh)
- Variables that are local to the shell are defined with
set - Env variables are inherited by shells started in the parent shell
- Type
setto see locals,envto see environment
- Variables that are local to the shell are defined with
- To view an environment variable:
echo $varname- PATH - list of directories to search when you ask the shell to run a program
- LD_LIBRARY_PATH - list to search for shared libraries
- To add a directory to the path:
export PATH=$PATH:/opt/intel/bin - Move, copy, remove files:
mv,cp,rm - To view the contents of a file:
cat filenamecat= “concatenate to standard output”, stdout is the terminal by default
- Redirect stdout using symbols
cat file1 > file2replaces (clobbers) file2 with the contents of file1cat file1 >> file2appends file2 with the contents of file1cmd1 | cmd2to pipe stdout of cmd1 to stdin of cmd2
- Text editors:
nano,vi,emacs- Terminal window becomes plain text editor
- No graphical interface, all editing done via special key sequences
- Controlling processes
- control sequences: ctrl-c = kill, ctrl-z = suspend
- bg to put process in background, fg to bring to foreground,
jobsto see bg list
- For more tips and tricks...