Introduction to the *nix Environment

Much of the work in the HEP field is done in *nix, or Unix-like, environments. Most commonly, these are the various distributions of Linux and the Mac operating systems. Learning how to navigate and work efficiently in this environment can save a lot of time. This page can help get you started if you are unfamiliar with *nix environments and can be used as a reference.

The terminal

Most of the work you will be doing will make use of the terminal, a text-based environment used to navigate the directory structure, compile and run code, submit jobs to batch systems and monitor their progress, launch applications, and connect to remote machines. To launch this application in Scientific Linux click on 'Applications' in the top desktop panel --> hover over 'System Tools' --> and click on 'Terminal' in the extended menu. A window will open with a single line that begins with
bash-4.1$ 
or something similar and a cursor. The text before the cursor is referred to as the command prompt.

Navigation and directory structure

The directory tree structure in Linux assigns each user a home area in /home/username

Environment variables

Useful commands

command option
short form
long form
man foo
show the MANual entry for the command foo
Gives in-depth information on user commands, system calls, devices, etc using the program less. Useful for finding detailed descriptions of optional command arguments. Type q to quit.
ls
LiSt the contents of the current directory, not including hidden files (filenames beginning with a '.')
Can be given a relative or absolute path as an optional argument. This command has many helpful options which are used frequently. For example, ls -ltrah will list the contents in a detailed Long format (-l) sorted by modification Time (-t) in Reverse order (-r) including All files (-a) in a Human-readable size format (-h). To have ls use color to distinguish filetypes use ls --color.
pwd
Print the current Working Directory as an absolute path
cd path
Change the current Directory to path, where path can be relative or absolute.
Leaving path empty will take you to your home directory. The directory one step above your current directory can be denoted by ../, two directories above by ../../, etc. To return to the previous directory, use =cd -=
mkdir path/directory
MaKe the DIRectory directory in path. Directories in path must exist.
rm file
ReMoves the file file
Will not remove directories. To make rm 'nice' and have it ask you if you are sure you want to delete the file, use rm -i.
rmdir directory
ReMoves the DIRectory directory, provided it is empty.
To remove a directory AND its contents at the same time use rm -rf. The (-r) option makes rm operate Recursively and the (-f) option Forces removal while ignoring nonexistent files and never prompting. WARNING: Make absolutely sure you want to remove the entire directory before using this command. Be extra careful when using this command with the wildcard '*' character.
more file
print the contents of file to the screen
Reads the contents of a file and prints it to the terminal. Press '=ENTER=' to advance and '=q=' to Quit. File content remains in the terminal. For large files consider using less.
less file
Similar to more but allows backward movement as well as forward movement.
Starts up faster than more and editors for large files. Scroll using arrow keys, '=ENTER=', and '=SPACE='. Search for pattern using '/_pattern_'.

The .bashrc file

bash - GNU Bourne-Again SHell From the manual entry on bash:
"Bash  is  an sh-compatible command language interpreter that executes commands read from the standard input or from a file."

The .bashrc file is a hidden configuration file stored in your home directory. It allows you to customize your terminal. There are many things you can do with this file:
  • customize your command prompt
  • set environment variables
  • set command aliases
  • create a customized function
  • and more

Below is an example .bashrc file.
#This is a commented line.
#This is my favorite .bashrc file.
#--Emily Johnson


###########################
# user-defined aliases #
###########################

#gives color to different types of files
alias ls="ls --color"

#clears screen
alias c="clear"

#useful long-form ls
alias lss="ls -ltrah"

###########################
# other user preferences #
###########################

# several custom prompt examples
PS1="\[\e]0;\h \u \w\a\]\h \u$ "
# PS1="\u:\W$ "
# PS1="\[\e[0;32m\]Andrew\[\e[m\] \[\e[1;34m\]\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\] "
# and my personal favorite:
# PS1="\[\033[0;31m\][\[\033[1;31m\]\u\[\033[0;33m\]@\[\033[0;32m\]\h\[\033[0;34m\]] \[\033[1;35m\]\w \[\033[0;32m\]~'~\[\033[0;35m\]@\[\033[0m\] "

#sets the editor for the SVN repository to vim. Other common choices: emacs, gedit, nano
export SVN_EDITOR=vim

###########################
# system-specific portion #
###########################

#changes the color-coding used by ls --color to my own preferences
eval `dircolors /home/john2105/.dir_colors`

#instructs the interpreter to look in my home directory for
#the newer Adobe Reader
PATH=$PATH:.:/home/john2105/adobe/Adobe/Reader9/bin
export PATH

export TMOUT=0

-- EmilyJohnson - 23 Aug 2016
Topic revision: r4 - 13 Sep 2016, EmilyJohnson
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback