Download
introduction to unix kde and the bash shell n.
Skip this Video
Loading SlideShow in 5 Seconds..
The user interface – Command Line Environments PowerPoint Presentation
Download Presentation
The user interface – Command Line Environments

The user interface – Command Line Environments

99 Views Download Presentation
Download Presentation

The user interface – Command Line Environments

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Introduction to Unix, KDE, and the bash shell The user interface –Command Line Environments

  2. UNIX/Linux many flavours, each with a common “UNIfied” set of functions often (though not always) Open-Source and collaborative effort supports numerous architectures developed mainly in C was text-based, now has X GUI support (since mid ’80s) similar to MS-Windows in some respects but different in others, and usually faster!

  3. UNIX Types and flavours Traditional UNIX (DEC UNIX, SunOS etc.) LINUX runs on x86 (and other) platforms (PowerPC, Alpha, mobile phones, PDAs, etc: you name it, there's probably a version for it) Linux is at the heart of the UWA network  Mail servers  File servers (smb1, smb2 etc)  News server  Web cache

  4. More UNIX flavours Linux “distros” include Red Hat/Fedora, Mandrake, SuSE, Debian, Ubuntu, Slackware, Gentoo (more?...) All distros based on common kernel Free, Open Source software – collaborative through internet-wide development SUN Solaris – graphical interface is CDE (Common Desktop Environment)

  5. UNIX: Linux and Apple Linus Torvalds (Finnish Student) wrote a version of UNIX for the PC as an exercise to help him understand operating systems in 1991 He posted it on the Internet as Linux The rest you probably know… In 2000, Apple chose Darwin (another open-source UNIX-like OS, BSD-based) as the basis for the new Mac OS-X Yes, OS-X is essentially UNIX!

  6. What is KDE ? K Development Environment play on Sun's CDE Open Source software project (1996) Aims – to provide for UNIX a desktop environment that is Consistent User friendly Contemporary Implemented in C++ It is not simply a window manager – but a whole desktop system

  7. Command line environments The command line is a powerful way of interacting with the OS Can be very efficient Allows complex tasks to be achieved economically Very flexible Has a steeper learning curve than GUI style interaction May be less frustrating for repetitive tasks In fact you will customise with scripts and automate with aliases etc GUI and CL both have their place…

  8. Shells - Intro Shell provides a ‘coating’ around the operating system. Allows the user to interact with the OS Lots of different command line shells exist with different facilities In Windows – DOS/Command Prompt UNIX C Shell (csh) syntax related to the C programming language, enhanced to tcsh Bourne shell (sh) Bourne Again Shell (bash) tends to be the LINUX standard shell – derived from a shell called sh Case sensitive

  9. Command Line Interpreter Prompt Allows the user to type a command Windows eg. c:\_ UNIX eg. stonkin~: $_ But might also display other information such as the working directory (configurable) Commands allow additional information to be given to the command or program via: Arguments. UNIX eg. lpr -Puserarea Switches or options. Windows eg. dir /w UNIX eg. ls -l

  10. What can you do with a shell ? Customize your session For example set variables such as your home directory, or the path to search to find programs. Interactive use Execute issued commands Process commands – e.g. interpret special characters Shell also supplements OS commands Programming Combine lots of commands into a shell script

  11. Shells Bash Shell (which we will use) C Shell Bourne Shell Korn Shell and many others too provide a human interfaces to the operating system and ... More on the web at: http://unixhelp.ed.ac.uk/shell/

  12. Typical Shell Features environment is customizable to suit the user and their applications control of files and directories has internal commands and can also invoke external commands control of these processes/programs can write programs using the facilities of the shells alone many have extra features eg.filename completion, command history etc

  13. The Bourne Again Shell (Bash)- Facilities Some metacharacters for filename abbreviation * match zero or more characters ? Match a single character [abc..] match one of selected characters (can use ranges eg. a-z) [!abc ] match any character except these ~username HOME directory of user a|b match pattern a or pattern b

  14. Commands bash shell prompt often ends with a $ character commands typically accept flags, and arguments $ls -la $mkdir mydirectory $javac -g HelloWorld.java shell expand wildcards (* ? [ ] ) and variables ($x) before calling the command arguments are often files/directories flags are switches/options, usually in no specific order to find out more about a command use the on-line “manual” pages, read using the man or info commands

  15. Files and Directories organised hierarchy for data storage many different types of file directories (aka folders) for tidiness tree structure / root of the tree /mydir directory at the root /mydir/mysub sub-directory of mydir absolute and relative pathnames cd /this/is/an/absolute/pathname cd this/is/a/relative/pathname cd ../at_same_level_in_hierarchy

  16. Files and Directories directory entries “.” and “..” frequently used file management commands: mkdir, rmdir, cd mv, cp, rm ln ls pwd

  17. Basic file manipulation commands Command prompt UNIX Windows metaphor List directory dir ls Double click folder etc Copy file copy cp Edit->copy Move file move mv Drag/drop Cut/paste Remove file del rm Drag to trash view contents (text) type cat d.click select notepad… Make directory mkdir mkdir File->New->Folder Remove directory rmdir rmdir Drag to trash

  18. Filenames / Linking Files two types of links hard links symbolic links Hard Links multiple names for the same file Symbolic Links one file with one “proper” name and other pointers to that file redirect using a link name to an existing file use the ‘ln’ command ln <filename> <linkname> ln -s <filename> <linkname>

  19. Some example UNIX commands pwd ls –a –l (same as ls –la) ls –l *.txt cd ~/mydirectory cp myfile ../’my other directory’/. cp –r ~auser/hisdir/* . mv mydir/my*.html .

  20. Command History Bash lets you repeat and modify previous commands in very sophisticated ways – history substitution. The ! Character starts a history substitution Here are some (but not all) possibilities: history list last 16 commands !! Repeat the last command !N repeat command number N in the history list !-N nth command back !?string? Most recent command containing string !$ last argument of previous command ^old^new^ substitute old for new in last command

  21. Permissions enhanced security in multi-user environment files and directories Readable, Writeable, eXecutable (rwx) for who? User, Group, Others or All (ugoa) ls -la file1 -rw-rw-r-- 1 ais 13632 0 Jan 17 13:00 file1

  22. Setting Permissions chmod (change permission codes) +/- chmod a+rx u+w dap.doc chmod 755 dap.doc 4(read) + 2(write) + 1(exec) = 7 for user 4(read) + 1(exec) = 5 for group 4(read) + 1(exec) = 5 for others umask assigns default permissions

  23. Command I/O This is done using data streams, connected to the user terminal: STDIN - Standard Input (descriptor 0) STDOUT - Standard Output (1) STDERR - Standard Error (2)

  24. Redirecting I/ O output can be redirected from screen to a file can be segregated from STDERR this way using > and >> characters input can be redirected from a file rather than the keyboard using < and << for input STDERR can also be redirected coupling also possible 2>&1 More on the web about redirection at: http://cs-www.bu.edu/help/unix/redirecting_input_and_output.html

  25. Command Line Pipes a pipe | connects the STDOUT of one command to the STDIN of another allows concurrent processing coupling of simple commands to perform complicated tasks if no STDOUT then broken pipe! limit on number of commands in pipeline

  26. Shell Variables Variables have A symbol (variable name) An associated value Used to store values for use later Some special ones are defined by the shell e.g. Home directory Path Some are defined by system admin or specific programs when you log in (startup scripts) You may define your own Useful when you want to automate tasks

  27. Path Environment Variable commands/executable files usually stored centrally on system /usr/local/bin; /usr/bin the PATH environment variable should be set to find them echo $PATH otherwise, append to the PATH variable PATH=$PATH:/aber/nns/bin

  28. DISPLAY Environment Variable text only commands normally output to STDOUT X windows based applications try to open X window dialog boxes on your machine’s display If not: export DISPLAY=<machine-name>:0.0 e.g. export DISPLAY=mymachine.dcs.aber.ac.uk:0.0 then try running your application again

  29. Example echo $HOME Gives your home directory echo prints the result on the terminal $ symbol means substitute the value of the variable echo $PATH Gives the directories that will be searched to find programs or commands set Prints all variables and their values export Sets a global variable value eg export PATH=‘mynewdirectory:’$PATH

  30. Aliasing If you often use a command you could create an alias to it Similar idea to a shortcut in Windows Some commands are already aliased for you Type alias at the prompt to see all current aliases Of course aliases mean you can have a lot of personalised commands. Eg. alias listall=‘ls –la’

  31. Vi/Vim/GVim Visual Interface text editor many functions available 2 modes of operation: command and insert ESCAPE to return to command mode case sensitive keyboard control (note!) Graphical window version called GVim GVim = Vi core + advanced features once learnt, never live without!

  32. Vi Characteristics full editing facilities, with copy+paste command reverse (undo) function Regular Expression text searching text marking and return well constructed commands support for multiple changes with one single command – you can effectively create your own editing commands

  33. External Commands thousands of applications available should be available in your shell path maintainer dependent operating system specific most popular: vi, sed, awk, grep, fgrep, sort, uniq if in doubt look at the man/info page!

  34. Summary Input output redirection Shell variables Command history /substitution Aliasing Filename Wildcard characters Filename Completion (press tab key to complete a filename) Other features for programming There are lots- so simple scripting stuff later

  35. The MS Windows command prompt The shell will attempt to execute anything you type It will search the current directory plus anything in the PATH environment variable May be an internal command, a binary (machine executable) program or a batch file the shell can interpret. The search path is sometimes important because it determines which version of a program is run It is not case sensitive

  36. Command line environment Windows Command Prompt DOS like shell Emulated in 32 bit systems (98) You can do most things that the GUI can do with a lot less clicking And you can automate tasks If you want to write programs you will need to use system calls. Command prompt is however a pretty basic shell compared to the UNIX shells.

  37. A few example Windows commands X: - change working directory to drive X cd \ - change to root directory cd .. – change to parent directory cd ..\mydir - change to sibling directory mydir dir /w - lists contents of the directorywithout attributes dir directory\ - list contents of subdirectory copy *.txt a:\ - copy all txt files to drive a move myfile.txt d:\directory\newname.txt

  38. Files and paths (windows) Files and paths X: (change current directory to) volume X \ directory separator, root directory (/ in UNIX) . this directory, .. parent directory Absolute E.g. X:\myfile.txt \myfile.txt Relative E.g. X:filename X:directory\ ..\..\mydir\filename

  39. Useful in Windows command prompt Metacharacters (wildcards) * matches any sequence of characters ? Matches a single character More powerful shells support more complex possibilities %x% evaluates variable x (windows) Redirection > send to a file >> append to a file | pipe send output to another command

  40. Environment variables Store values used by that shell. E.g. >set myvar=Hello World >echo %myvar% Hello World >