Post on 30-Dec-2015
description
In this module you will learn:
• What is the computer shell• What is the command line interface• What is the directory tree• Some UNIX commands
The Shell
The shell is a program that provides an interface to the operating system
graphical interface
graphical shell command-line shell
command-line interface
You can type the application name (+ options) in the command-line terminal screen and then type [Return]
command
The directory structure
Root (/)
home bin etc var tmpusr
allegrakristian
courses
applications
data
phospho
tmp
The file-system is arranged in a hierarchical structure, like an inverted tree
The top of the hierarchy is traditionally called root
When you first login, your current working directory is your home directory
• Access you home directory using the command-line interface
• Create a text file “myfile.txt” and save it in your home directory
• Start the gedit text editor
• Go to the command-line interface and type “ls” at the prompt
About UNIX
Everything in Unix is either a file or a process
A process is an executing program identified by a unique PID
(PID = Process IDentifier)
A file is a collection of data
About Unix commands
%rm myfile.txt [Return]
• The shell searches the file containing the program rm• executes the program rm on myfile.txt • After the process rm myfile.txt has finished running, the shell returns the prompt % to you, indicating that it is waiting for further commands.
Commands are themselves programs
Here you can type a new command
General remarks
• If you've made a typo: CTRL-u to cancel the whole line
• Unix is case-sensitive
• There are commands that can take options
• The options change the behaviour of the command
• UNIX uses command-line completion
• %command_name -options <file> [Return]
• %man <command name> [Enter]
• %whatis <command name> [Enter]
General remarks
• CTRL-A sets the cursor at the beginning of the line
• CTRL-E sets the cursor at the end of the line
• You can use a text editor to write stuff
• You can use up and down arrows to recall commands
• The command whereis tells you where is a given program
General remarks
Listing files and directories
The directories ‘.’, ‘..’, and ‘~’
% ls -a [Enter]
% cd . [Enter]
% cd .. [Enter]
% ls ~/oeiras
File system security (access rights)
-rwxr-xr-- 1 gould admin 2541 2009-08-19 16:57 new_scop.txt
Each file (and directory) has associated access rights, which may be found by typing ls -l
permissions
number of links
owner
group owner
size in bytes
date and time of the last modification
file's name
r allows users to list files in the directoryw allows users to delete files from the directory or move files into itx allow users to access files in the directory
Access rights on directories
d
Running your program from the command line
%python test.py
%pymol
%chmod a+x test.py%test.py BUT: #!/usr/bin/python
Processes and Jobs
Backgrounding a current foreground process
Listing processes
A process may be in the foreground, in the background, or be suspended
Backgrounding a long process has the effect that the Unix prompt is returned immediately, and other tasks can be carried out while the original process
continues executing
% sleep 10 & [Enter]
% sleep 100[Ctrl Z] (^Z shortcut)% bg
Running background processes
% ps #list of processes with their associated PID and status % jobs #list of running processes% fg %jobnumber #restart (foreground) suspended process% fg #restart(foreground) the last suspended process
UNIX Variables
% echo $OSTYPE
shell variables apply only to the current instance of the shell and are used to set short-term working conditions
environment variables have a farther reaching significance, and those set at login are valid for the duration of the session.
Variables are a way of passing information from the shell to programs when you run them
Some are set by the system, others by you, yet others by the shell, or any program that loads another program
When you type a command, your path (or PATH) variable defines in which directories the shell will look to find the command you typed.
If the system returns a message saying "command: Command not found", this indicates that either the command doesn't exist at all on
the system or it is simply not in your path.
Setting the path
set path = ($path /Applications/blast/)
To add this path PERMANENTLY, add the line to your .cshrc AFTER the list of other commands
setenv PATH ${PATH}:/Applications/Blast
Transferring files between and connecting to remote hosts
% scp <SourceFile> <user@host:directory/TargetFile>
% scp <user@host:/directory/SourceFile> <TargetFile>
% sftp <user@host>password:$ cd <directory>$ get TargetFile$ put SourceFile
wget [option]... [URL]...
[URL]: http://host[:port]/directory/fileftp://host[:port]/directory/file
% ssh user@hostPassword: