260 likes | 359 Views
UNIX command line. 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 shell. command-line shell.
E N D
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 shell command-line shell graphical interface command-line interface
What happens when you double click on the icon of an application?
command What happens when you double click on the icon of an application?
command-line interface prompt Here you write the command
You can type the application name (+ options) in the command-line terminal screen and then type [Return] command
Root (/) usr home etc var tmp bin kristian allegra phospho courses tmp data applications The directory structure 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 • Start the gedit text editor • Create a text file “myfile.txt” and save it in your home directory • 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 Commands are themselves programs %rm myfile.txt [Return] • • The shell searches the file containing the programrm • • 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. 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
General remarks • %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 up and down arrows to recall commands • The command whereis tells you where is a given program • You can use a text editor to write stuff
Listing files and directories The directories ‘.’, ‘..’, and ‘~’ % ls -a [Enter] % cd . [Enter] % cd .. [Enter] % ls ~/oeiras
Handling files and directories more less clear
File system security (access rights) Each file (and directory) has associated access rights, which may be found by typing ls -l size in bytes permissions owner -rwxr-xr-- 1 gould admin 2541 2009-08-19 16:57 new_scop.txt d file's name number of links group owner date and time of the last modification Access rights on directories • r allows users to list files in the directory • w allows users to delete files from the directory or move files into it • x allow users to access files in the directory
Changing access rights: chmod %chmod go-rwx myfile.txt %chmod a+rw biglist
Running your program from the command line %pymol %python test.py %chmod a+x test.py %test.py BUT: #!/usr/bin/python
Processes and Jobs 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 Running background processes % sleep 10 & [Enter] Backgrounding a current foreground process % sleep 100 [Ctrl Z] (^Z shortcut) % bg Listing 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 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 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. % echo $OSTYPE
Setting the path 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. setenv PATH ${PATH}:/Applications/Blast set path = ($path /Applications/blast/) To add this path PERMANENTLY, add the line to your .cshrc AFTER the list of other commands
Transferring files between and connecting to remote hosts % ssh user@host Password: % scp <SourceFile> <user@host:directory/TargetFile> % sftp <user@host> password: $ cd <directory> $ get TargetFile $ put SourceFile % scp <user@host:/directory/SourceFile> <TargetFile> • wget [option]... [URL]... • [URL]: http://host[:port]/directory/file • ftp://host[:port]/directory/file