linux interfaces - southern illinois university carbondalecs491-2/postings/linux-interfaces.pdflinux...

Post on 16-Jul-2020

7 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Linux Interfaces

● UNIX began as a non-graphical or command-line OS, where users interacted with the OS by typing commands instead of pointing and clicking with a mouse.

● The M$ DOS (disk operating system) was also a command-line OS (though much more primitive).

● Though some people still believe Linux and UNIX are hard to use because of the command line, modern Linux and UNIX have both graphical and non-graphical interfaces.

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells

● A shell is a command interpreter, which lets a user interact with the OS (kernel).

● Shells are the command line interface (CLI) for Linux/UNIX systems.

● The default Linux shell is bash, though most UNIX shells are also available (csh, tcsh, ksh).

● A shell can be run either in a console (completely non-graphical OS interface) or in a terminal window (running on the graphical interface).

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells (contd.)

● In Windows, the “command-prompt” window provides a shell/CLI (though it is quite basic).

● While most Windows users rarely use the command line, 30 years of use in UNIX has resulted in a very powerful interface.

● Most Linux users make some use of shells, and system administrators use them constantly.

● Sometimes the shell/CLI is the fastest way to accomplish a task and sometimes a GUI is—you should use the best tool for the job!

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells (contd.)

● Key productivity features of Linux/UNIX shells:– piping/pipes:

grep lab2.c printf | wc -l

– redirection: grep lab2.c printf > lab2-printfs

– metacharacters: rm ~/temp/test[1-9].{text,txt}

– control constructs: for f in *.c ; do grep $f printf ; done

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells: Piping

● Piping allows commands that read from “standard input” and write to “standard output” to be combined to obtain new functionality.

● Commands of this type are called filters.● The shell pipe symbol is: | (vertical bar). ● Examples:

– grep printf lab2.c | wc -l

– locate bash | grep .ps

– ls -l *.c | grep Jun | wc -l

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells: Redirection

● Redirection allows output from commands to be written/appended to a file to be saved.

● Redirection also allows input to commands to come from a file.

● Examples:– ls -l *.c | grep Jun | wc -l > count

– grep printf lab2.c >> labs-printfs

– grep printf < lab2.c

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells: Expansions

● Shells have a number of metacharacters (characters not taken literally) that are used in various expansions, which save typing, etc.

● Among the key expansion phases are:

1) Brace expansion

2) Tilde expansion

3) Parameter expansion

4) Command expansion

5) Arithmetic expansion

6) Filename expansion (also known as globbing)

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells: Expansions (contd.)

● Brace expansion allows multiple words containing alternative parts to be generated:– echo a{bc,def,ghi}j produces: abcj adefj aghij

– mv file.{txt,text} has the same effect as: mv file.txt file.text

● Tilde expansion allows a users home directory to be compactly specified as part of a path:– ~smith/Docs/foo means /home/smith/Docs/foo– ~ alone means current user's home directory

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells: Expansions (contd.)

● Parameter expansion evaluates a shell variable and may manipulate its value:– $var1 ${var1} ${var1%.txt}

● Command expansion evaluates a command and substitutes in its result:– $(ls *.txt) or may write as `ls *.txt`

● Arithmentic expansion evaluates an arithmetic expression and substitutes in its result:– $(( 1+2 )) $(( $x + 2))

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells: Expansions (contd.)

● Filename expansion uses several metacharacters to do pattern matching on filenames, effectively representing multiple files.

● Appears similar to regular expressions used in several commands, but is not the same!

● Filename expansion metacharacters:– * matches any string, including the null/empty string– ? matches any single character– [...] matches any single enclosed character:

[yY] [0-9] [:digit:] [a-zA-Z] [:alpha:]

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells: Control Constructs

● Shells typically provide a wide variety of control constructs, though syntax varies among shells.

● Typical conditional constructs:– if-then, if-then-else, if-then-elseif, case/switch

● Typical looping constructs:– while, until, for, map (through a list)

● Control constructs can be used in commands:– for f in *.txt do mv $f ${f%txt}text done

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Shells: Scripts

● A shell script is a program written in a shell language and placed into an executable file.

● Often used to automate tasks that involve a sequence of commands (can be run by cron).

● E.g., convert mp3's to wav's in some directory: #!/bin/bash

cd $1 #get directory from first command-line argument

for f in *.{mp3,MP3}

do lame --decode $f ${f%.$ext}.wav

done

exit 0

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Design Philosophy

● Linux/UNIX philosophy:– Develop many small components that can be combined

(and reused) to solve a wide range of problems

– Usually accessible as a shell program and/or as part of a library for calling from any program

– GUIs are typically just a “front end” to program or library, which can also be accessed w/o the GUI

● Windows philosophy:– Develop “monolithic programs” that solve a fixed set

of problems (and cannot easily be combined/reused)

– Nearly always accessible only via a GUI interface

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

The Linux GUI

● In Linux and UNIX, the graphical user interface (GUI) is not an integral part of the OS.

● The GUI is built in layers above kernel.● Linux uses the X Window System (X11)

as its base graphical interface system.● X11 provides low level window drawing, etc.● A toolkit provides a higher-level API with a

consistent “look and feel”.● A window manager uses a toolkit to provide a

desktop environment and program windows.

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

The Linux GUI (contd.)

● X was developed at MIT from 1984—1987.

● X is based on a client-server architecture:– Server: display + input devices

– Clients: applications

● There are two main X11 implementations for x86:– XFree86.org and X.org

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

The Linux GUI (contd.)

● X Windows is extremely flexible:– The protocol is network transparent, so the server

and clients can be on different machines on network

– Allows remote adminstration and viewing applications from multiple machines on a single display

– Directly supports server-based, thin-client computing

– Does not tie OS to a single window manager (look)

– GUI problems do not necessarily impact the OS

– Can run Linux w/o wasting cycles on a GUI (server)

– Less efficient if directly accessing hardware (in games)

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Window Managers

● Many window managers are available for Linux:– KDE, Gnome, FluxBox, FVWM, IceWM, etc.

– WMs provide the basic desktop environment with window control, look and feel, etc.

– They differ in their looks, capabilities, resource usage, ability to customize, etc.

– KDE and Gnome are the most widely used

● Users have much choice/flexibility, but there is a tradeoff in lack of uniformity for developers (or when using a different machine).

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Desktop Environments

● KDE and Gnome are often called desktop environments since they not only provide WMs but also a set of basic utility applications (editors, file browsers, web browsers, media players, etc.)

● KDE is the most used DE/WM and is generally considered the most familiar for Windows users.

● Both provide configuration tools that can change many aspects of the way they look and function (number of mouse clicks, window focus, etc.).

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

KDE

● Based on Qt toolkit, mainly written in C++.● Provides familiar desktop environment:

– desktop with icons, panel (menu button, clock, application bar, application applets), window titlebars (max,min,close buttons), window focus, themes/art

– includes virtual desktops (pager on panel)

● Encompasses a large collection of utilities/apps:– control panel, screensavers, file/web browser, email,

organizer, printing interface, media players, games, office suite, various network clients, system monitors

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

KDE: Konqueror

● The KDE web and file browser– Understands many protocols via kio_slaves:

http, file, sftp, smb, etc.

– Can browse both local and remote files

– Highly configurable in how files are viewed

– Can bookmark both web sites and local/remote files

– Can associate actions with mime types (e.g., show in text previewer, open in editor, play with media player)

– Right-click for service menus (actions—easy to write)

– Change permissions and other properties

Linux Shells and GUIs © Norman Carver Computer Science Dept. SIUC

top related