Académique Documents
Professionnel Documents
Culture Documents
Learning the basic shell commands which are needed for working with FLUKA Learning how to use an editor This tutorial is a general introduction, it does not focus on a specific LINUX distribution This is a hands on introduction
Interrupt whenever you have questions try the commands I explain immediately on your computer
June 23-27th
What is LINUX?
LINUX is an operating system Was originally developed as open source alternative to UNIX Strictly speaking LINUX is the name of the kernel, the heart of the operating system The system as whole is called Linux distribution: kernel + additional software: window system, desktop manager, word processing software, browser, All main Linux distributions (Ubuntu, Fedora, Scientific Linux, Suse, Knoppix,) have a graphical user interface which is very similar to Windows All Linux systems offer to interact with via a terminal Terminal is similar to DOS Terminal: command line environment
June 23-27th
Logging in
When you start your system, after the booting process you will see a login screen (not on FLUPIX live CD) There you have to enter your username and your password You get your username and password from your computer administrator Once you have logged in successfully you will see the desktop It looks similar to a Windows desktop and has similar functionality There should be a task bar from which you can access the installed programs Exercise: Try to log in on your computer and explore which programs are installed on your system
June 23-27th
The shell
A shell is a program which provides access to the operating system by interacting on a command line Can be compared to a DOS To use a shell you have to open a terminal (sometimes called konsole) first There are different types of shell: bash, csh, tcsh, ksh, The different shells work slightly different but for our course the difference will not really matter You can find out which shell you are using by typing:
echo $SHELL
Exercise: try to open a terminal and find out which shell you are using You can have several terminals open at the same time
June 23-27th
General remarks
Exit the shell by typing exit You can use the shell to navigate through the file system and show the files and directories. From the shell you can execute programs, search for files, All commands and file names are case sensitive:
ls, LS, Ls are different things README.txt and readme.txt are different filenames You can use all characters of the English alphabet, all digits and _ . Dont start filenames with a point Dont use * $ ? [ ] / \ : ; ( ) ! ~ & # ^ in file names, some are allowed but they have a special meaning Dont use white spaces or special characters like , they are allowed but you will have problems to call such files from the command line
FLUKA course CERN: Linux for FLUKA users 6
June 23-27th
Directories
You are working always in a specific directory. The command pwd prints the current directory. The position of a directory is expressed as path, i.e. /somedirectrory/an/other/a/b/c/
Exercise: print the current directory You should get something like /home/username/ where username is your username
Separators are / and not \ The root directory is / (NB this has nothing to do with the account of the system administrator which is also called root) There is a home directory for each user, normally in /home/ username . Create new files and directories only in your home directory. Exercise: find your home directory
June 23-27th
You can use the command cd to change directory, i.e. to go from the current directory to an other.
Syntax: cd directoryname
cd ../../../
On some systems cd without a directory name changes the directory to the home directory Exercise:
Change to the root directory and then go back to your home directory
June 23-27th
Syntax: ls directory Omitting the directory name gives you the contents of the current directory List the contents of your home directory List the contents of the root directory
Exercise:
Most commands have options to change their behavior For ls the option l gives a longer output (MORE INFORMATION) You have to give the - character in front of the first option
Exercise: type ls -l in your home directory You will see information about permissions, ownership, size and date Try other options of ls: h, a, S, r, t You can give several options at the same time Syntax: man commandname Type q to exit the man pages Exercise: read man pages for the command ls
June 23-27th
Creating directories
Directories are also called folders The command mkdir creates directories:
The command rmdir deletes empty directories (if it is not empty you have to delete first all files and directories which are inside):
Syntax: rmdir directoryname go to your home directory and create there a directory called mydirectory Go to mydirectory and create inside a new directory called myotherdirectory
Exercise:
June 23-27th
10
Syntax: touch filename If filename exists it changes the timestamp of the file
The command cp copies a file to an other place. The original file remains. The new file can also be created in the same directory as the original when it has an other name.
The command mv moves a file to an other place or renames the file. The original file is deleted.
Syntax: mv pathtooldfile pathtonewfile Syntax: rm filename Use rm with care: the files are really deleted, they do not go to the trash
FLUKA course CERN: Linux for FLUKA users 11
June 23-27th
Exercise
Rename it to myfile2 Create a copy of myfile2 called myfile3 Create a folder called myfolder and move myfile2 to this folder Delete all files and folders that we have created in this exercise
June 23-27th
12
Konqueror is a file manager like the Explorer on Windows Konqueror can be used also as browser Start konqueror by typing konqueror (if it is not installed use an other browser like firefox or opera)
Exercise:
Create a directory called ex7 Start konqueror Go to the course website
http://www.fluka.org/course/Legnaro-07/Exercises/ex6/ Copy the file ex_6.inp to the folder ex7 (right click on ex_6.inp, Save As) Rename the file to ex_7.inp
June 23-27th
13
Editing files
To write something to a file you have to use an editor: Normally there are several editors installed:
Use the one which you like most. I recommend nedit. Dont use emacs or vi if you are a beginner! You can start a browser by typing its name on the command line Exercise:
Find out which editors are installed on your system by looking in the start menu or by typing the name of the editors listed above on the command line Find out how to save files Open the file ex_7.inp with the editor Change the line
FLUKA Course Exercise
to
June 23-27th
less, grep
Syntax: less filename With the arrow keys you can go up and down Type q to exit from less
Exercise: use the command less to view the content of the file ex_8.inp The command grep can be used to search for patterns in files
Syntax: grep pattern filename The search is case sensitive, use the option -i to make the search case insensitive
June 23-27th
15
The command diff compares two files and shows the differences
Syntax: diff file1 file2 Exercise: Use diff to find the difference between the files ex_7.inp and ex_8.inp
The command tail shows the last lines of a file. You can chose the number of displayed lines by giving the option n followed by a number.
The command head works like tail but shows the first lines of a file. Exercise: Use head and tail to display the first and last lines of the file ex_7.inp
June 23-27th
16
Permissions
LINUX is a multi user system To make sure that a user does not overwrite the files of other users, for each file permission are set That means for each file, directory or program the owner can restrict the access by other users There are 3 types of permissions: read, write and executable which can be set for the owner of the file, a group of users and for everyone To change the permissions of a file use the command chmod
To make it readable: chmod +r filename To allow execution: chmod +x filename To allow writing: chmod +w filename
June 23-27th
17
Executing programs
path/program ./program
go to the root directory and run the program again
So far we have used only commands which are part of the shell but there are also other commands (but depending very much on the system) Exercise:
Type acroread at the shell (if it does not work try xpdf )
This works although the program is not in the current directory. The reason is a environment variable (PATH) which contains paths in which the shell looks up if a command is not found Most likely acroread is in /usr/bin/acroread and the variable PATH contains /usr/bin/
FLUKA course CERN: Linux for FLUKA users 18
June 23-27th
Shell variables
In a shell, variables (only strings) can be defined, some are already predefined: PWD, SHELL, USER This variables are called environment variables The command echo prints whatever string is following, it also expands variables (i.e. it shows the value of the variable) and handles special symbols To access the content of a variable type a $ just before the name (dont put a space between $ and the variable name)
echo $VARIABLENAME Assigning hello to a variable: MYVARIABLE=hello Printing the content of MYVARIABLE echo $MYVARIABLE
June 23-27th
19
Shell variables
Exercise:
in your home directory create a directory called fluka In the directory fluka create a directory called flutil Create a variable called FLUPRO and assign /home/username/ fluka/ to it (username is your username) Type: cd $FLUPRO What happens?
A variable is lost when you exit the shell. A variable is only available at the present shell. If it should be also available in subprograms of the shell you have to export it
To make it permanent, i.e. always available when you are opening a shell: set the variable in the profile file (.bashrc,). When you install FLUKA you should do this with the FLUPRO variable.
FLUKA course CERN: Linux for FLUKA users 20
June 23-27th
Tar and gz
Windows users are probably familiar with zip files A zip file contains one or more files that are compressed In the LINUX world there are the programs gzip and gunzip to compress and decompress files There is the command tar to create archives of files, i.e. merging several files to one single file. This is called taring/untaring a file. tar can also compress/uncompress files (there is no need to use gzip and gunzip to for zipped tar files). For the FLUKA course you will need this only once, to install FLUKA FLUKA comes as a file with the ending .tar.gz, a zipped tar archive To extract (i.e. unzip and untar) a file use tar with the options zxvf
June 23-27th
21
When you start a program from the command line, it is not possible to enter any other command until the program has finished If you start for example the acrobat reader and you want to keep it open but you want still have access to the command line you can start it as background job. To do so give the symbol & at the end of the command.
To bring it back to foreground type the command fg You can bring running programms to background by suspending them using Ctrl-z and sending them to background with the bg command Example:
acroread Ctrl-z bg
FLUKA course CERN: Linux for FLUKA users 22
June 23-27th
Nohup
The command nohup is used to run a command which does not stop when you exit your terminal The output is written into a file called nohup.out, you dont see the output on the screen Normally there is no need to use nohup But for simulations which can last hours or days it is very comfortable to use nohup, because if you close the terminal by mistake, or you log out the process is going on fair the graphical user interface of FLUKA uses this command. You can close flair and your terminal and the simulation is still running Remember that you dont see the output on the screen, you have to look into the file nohup.out However if you switch off your computer nohup is also aborted, and so is the program you started with nohup
FLUKA course CERN: Linux for FLUKA users 23
June 23-27th
Tab completion Cut and paste with a three button mouse ssh to connect to other computers Using wild cards Using the Shell for programming History, commands you have entered before can be accessed by the arrow keys (up and down) Customizing the shell with alias Use konqueror to create, move, rename, change permissions or delete files and directories
June 23-27th
24
Summary of commands
Command touch mkdir rm rmdir ls cd exit less grep cp mv diff tar
June 23-27th
description creates new, empty file creates new directory deletes file deletes empty directory shows files and directories changes to an other directory exits the shell shows content of a file looks for strings in file copies file moves file or renames file shows differences between files creates or extracts archives
FLUKA course CERN: Linux for FLUKA users 25