******************************************************************************** Introduction ******************************************************************************** Facts you should know about linux: Linux is an implementation of Unix About 38 years ago, Bell Labs developed a new operating system, called "UNIX" About 15 years ago, home PC became popular. There is need to run unix on PC. Linux Torvalds, began to work on linux. Linux is written with C. Linux is an ideal operating system for power-users and programmers, Linux is free. Linux is secure and versatile. There is a Linux for everyone. Currently, there are many versions of linux. Redhat(Fedora), Debian,Gentoo, Knoppix, Mandrva, Slackware, SUSE, Ubuntu, and more. Downloadable ISO-images can be obtained from Linux.com. Linux is open source, it uses GNU tools, a set of freely available standard tools for handling the operating system. Linux comprises of two parts: the kernel and the shell. The kernel part carries out basic operating system functions such as accessing files, allocating memory and handling communications. A shell provides the user interface to the kernel. A number of shells are available on the Unix operating system including the Bourne shell and the C shell. The shell is basically an extensive program that runs all the time that you are logged on to the computer, and provides an interactive interface between the user and the computer functions. A modernized version of Bourne Shell is called the Bourne Again Shell, or bash. For C-shell, we have an extended one: tcsh. ******************************************************************************** File and Directory commands ******************************************************************************** The most used commands: ls - lists all files in current directory Format: ls [option] [FILE] option: -l list in long format -a list all files( including hiden files starting with ".") -d list directories -t sort by modification time -r reverse order while sorting -p append / indicator to directories examples: ls -la ls -lrtp format of FILE: *(any string),?(any one character) *.c, test.?, ... pwd - show your current directory that you are in. mkdir - create a directory cd - changes directory . current directory .. parent directory ~ your home directory / separate different level of directories \ for some special symbols rmdir - deletes a directory that is empty. cp - copies files Format: cp [option] file1 file2 option: -i prompts for confirmation before overwriting an existing file. -r copy recursively -f force. Overwrites without promption. rm - deletes files. Format: rm [option] file option: -i prompts for confirmation before deleting. -r deletes the directory and its contents. -f force. Deletes without promption mv - moves files from source to target. Difference with cp? also used to change file/directory name. Now, here are some commands to list file contents: cat - outputs file contents on the screen Format: cat [option] file option: -n number the lines -v display non printing characters. head - outputs the first few lines of the file on the screen. Format: head [option] file option: -n outputs first n lines tail - outputs the last few lines of a file on the screen. Format: tail [option] file option: -n outputs the last n lines -f outputs appended data as the file grows. more - outputs the contents of a file on the screen page by page. ?????? First lecture stops here ?????? how to connect linux? softweb.cc.sunysb.edu ssh where is terminal? more on cp (file/dir) file type and how to open. .exe? You can always get help about commands by 'man command' or 'command --help' ******************************************************************************** Text Editor -- Vi(Vim) Lecture 2, by Lingling Wu vimtutor ******************************************************************************** More on files and directories ******************************************************************************** chmod change file access permissions chmod [option] MODE FILE MODE '[ugoa]*([-+=]([rwxXst]*|[ugo]))+' or chmod 755 FILE find search for files in a directory hierarchy find [path] [expression] path can be empty, default is current directory -regex use regular expression -name pattern -mtime [+-]n modified in the last n days -mmin [+-]n modified in the last n minutes -size [+-]n examples find . -name "*.c" ln make links between files locate list files in databases that match a pattern touch change file timestamps whatis display a oneline summary about a command quite useful when you forget what one command should used to do which locate a command whereis locate the binary, source, and manual page files for a command df display number of free disk blocks and files du summary disk usage ******************************************************************************** Networking and Communications ******************************************************************************** telnet - used to communicate with another host. Format: telnet [options] hostname option: -l username rlogin - used to communicate with another host. The difference with telnet is that it logs you into the host with the same username as you are logged on with. rsh - connects to the specified hostname and executes the specified command. Format: rsh [option] hostname command option: -l username ssh - OpenSSH secure shell client Format: ssh [option] user@hostname ssh -l abc ams.sunysb.edu ssh abc@ams.sunysb.edu pine scp - secure copy Format: scp [option] user1@host1:file1 user2@host2:file2 ftp - File Transfer Protocol cd get put exit sftp - secure file transfer program Format: sftp [option] user@hostname lftp - sophisticated file transfer program talk - used to communicate with another user who is on the machine with name hostname. Format: talk user@hostname Mathlab may not work for this command. write - send a message to another user finger - display data about a user, including information listed in his/her .plan file. parameter could be user name, last name or first name whoami print effective userid w,who show who is logged on ******************************************************************************** clear clear the terminal screen grep print lines matching a pattern grep [options] PATTERN [FILE...] useful option -n display line number -v invert match basicly, grep string filename more complicated search can use regular expression ^word begin with word$ end with [0-9] numerate number * Matches the preceding element zero or more times. + Matches the preceding element one or more times. For example, ba+ matches "ba", "baa", "baaa", and so on. ? Matches the preceding element zero or one time. For example, ba? matches "b" or "ba". . any single character \. dot examples grep -n root /etc/passwd grep return *.c tar create tape archives and add or extract files tar cvf backup.tar file/dirname tar xvf backup.tar tar xvzf backup.tar.gz gzip gzip filename gunzip gunzip filename.gz zip unzip unzip filename.zip unrar unrar x file.rar PIPE | > redirect >> append top display linux tasks ps report a snapshot of the current processes kill send a signal to a process kill [ -signal | -s signal ] pid ... kill -9 pid Printing ... lpr submit print requests lpr [ -P printer ] files lpq display the print queue lprm remove print jobs from the print queue lprm [ -P printer ] job-ID super user commands google it and practice in your own linux. Do not practice super user commands in mathlab, else your account will be cancelled. ******************************************************************************** Shell Configuration: ******************************************************************************** Two popular shells: tcsh and bash there are many different shells available, but others tend to be very similar to one or both of these Most of the commands that we use are common. Check your shell type echo $SHELL command 'echo' comes with a return automatically, option '-n' will suppress the return. Change Shell you can always type the name of the shell to switch.(bash,csh,sh,tcsh) If you want to change permantly, (change your login shell), you can do this: chsh or ypchsh (chsh -s bash) Some nice feature of modern shells: command line editing file name completion (Tab key) startup file .cshrc .bashrc assignment ${var} reference to value of the variable ${#var} length of the value as a string tcsh: set name=value inherited environment variables: setenv name value bash: name=value inherited environment variables: export name=value shell variables: $cwd,$PWD This variable consists of a string which records the name of the current directory. $term,$TERM The terminal type. $path,$PATH an environment variable listing a set of paths to directories where executables may be found $HOME your home directory set path in tcsh: set path = ($path /a/b/c ) set path in bash: path = $path:/a/b/c all variables are set as strings in default, if want to evaluate the numeric value use $(( )), like $(($var1+$var2)), but integers only. prompt variables or commands could be part of prompt tcsh set prompt = "options" options: %/ full path of current directory %c,%. trailing component of the current directory %h,%!,! current history number %t,%@ time %n user name %d week day %w month %y year examples set prompt = "%n.%.> " bash PS1 = "options" \w full path of current directory \W base name of current directory \u user name \h host name alias: bash: alias name='command' tcsh: alias name 'command' example: alias print 'lpr \!* -Pps5' print part1.ps glossary.ps figure.ps The notation !* causes each argument given to the alias print to be inserted in the command at this point. The command that is carried out is: lpr part1.ps glossary.ps figure.ps -Pps5 an alias can override an existing command, like alias ls = 'ls --color' but the originally defined command can also be used by 'ls' or \ls unalias:remove a defined alias #: ignore words after it. source: evaluate a file Write or modify your own shell start up file. Shell script: usually begins with shebang: #!/bin/shellname more powerful: Perl ********************************************************************************