19
Linux environment Graphical interface – X-window + window manager Text interface – terminal + shell

Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Embed Size (px)

Citation preview

Page 1: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Linux environment● Graphical interface – X-window + window

manager

● Text interface – terminal + shell

Page 2: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Linux or Mac Desktop

● Open up terminal● ssh [email protected]● ssh –X [email protected]

Page 3: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Windows

● Need ssh client PuTTY

● http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

XShell4● http://www.netsarang.com/download/down_xsh.html

● For X applications also need X-forwarding tool Xming (use Mesa version as needed for some apps)

● http://www.straightrunning.com/XmingNotes/ Make sure X forwarding enabled in your ssh client

Page 4: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

New option from all - FastX

● Give link to documentation● Good for● Can use to ssh to all interactive nodes – same

usage rules apply!● Can also use the frisco{1-6}.chpc.utah.edu

nodes for usage beyond that allowed on interactive nodes.

Page 5: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Good resources for More Information

● Some useful websites

http://www.ctssn.com/

http://unix.t-a-y-l-o-r.com/Unix.html”

Page 6: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Terminal basics● Two basic shells - slightly different command

syntax csh/tcsh ksh/bash

● Type commands on command line, send command by pressing Enter

● Useful key combinations: ctrl-a – start of line ctrl-e – end of line ctrl-c – cancel text typed on line ctrl-z – put running command to background (come

back via command fg)

Page 7: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Basic commands

● ls – list contents of a directory● pwd – display current directory● cd – change to directory (cd test)● cp – copy file (cp from_file to_file)● mv – move file (mv from_file to_file)● rm – delete file (rm test1)● mkdir – make directory (mkdir test)● rmdir – remove directory (rmdir test)● man – help for given command (man cp)

Page 8: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Wildcards

● more files can be specified via wildcards● * - matches any number of letters incl. none● ? - matches any single character● [] - encloses set of characters that can match

the single given position● - used within [] denotes range of characters● ~ - followed by user name = home directory

(~unid)● e.g. - *.csh, figure?.jpg, file[0-9].dat, figure[0-9].*

Page 9: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Command flags

● commands can take flags that modify their behavior

● flags are formed with – (dash) and letter● consult man pages of each command for list of

available flags● e.g.

ls -l – list files in long format rm -r * – remove both files and directories (along

with all files in those directories) -- very dangerous!

Page 10: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Exercise 1

● Try to make and then cd to a new directory, e.g., IntroLinux1

● List contents of a directory, e.g., /uufs/chpc.utah.edu/common/home/u0028729/CHPCstuff/IntroLunix1

● Try to copy some files from this directory, e.g., to your IntroLinux1 directory

● Work with ls, flags, and wildcards ● Open man page for some command (e.g. ls) and

try some of its flags (e.g. -l, -lt, -ltr)

Page 11: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

File view commands● cat – display contents of file● more – display contents of file with page breaks

(next page with Space key)● head – display top of file● tail – display end of file● grep – search for pattern in file (grep “pattern“ test1)

● vi – edit file (more on this later)

file – tells you type of file

Page 12: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Exercise 2

● View program files via cat, more, head and tail● Vary number of lines viewed with head and tail

● Search for a string in a file with grep

Page 13: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Command output redirection

● > redirect to a new file (cat test1 > test3)● >> - append to a file (cat test2 >> test3)● | - pipe – redirect command output to another

command ls -l | more

Page 14: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Exercise 3

● Use cat to concatenate two files● Use pipe, e.g. paginate result of ls

Page 15: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Unix File Permissions

● Shown with ls -l● User (u), group (g), other (o), all (a)● Permissions are read (r), write (w), execute or

search for a directory (x)● chmod – to change permissions of file or

directory● Executable and shell scripts must have

executable permissions

Page 16: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Some other useful commands

● wc – e.g. wc -l file.txt● cut – e.g. cut -f 2 -d : file.txt● du – e.g. du -h● df – e.g. df -h● ln – e.g. ln -s ~/bin/prog.exe prog1.exe

● Use man pages to find out what these commands do.

Page 17: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

The vi editor● two modes – command, input ● command mode – commands input via

keyboard keys i, a, r, R – enter input mode - insert, append,

replace character, replace G – go to (1G – go to line 1, G – go to end of file) x, dd – delete character, line : - enter external command (:w – write file, :q –

quit, :q! - quit discarding changes, :wq – write and quit)

/, ? - search forward, backward (/test)● input mode – works like any other text editor

Page 18: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Use of the vi editor

● to input text, enter input mode● to quit input mode, push Esc key● searching, deleting,... done in command mode● search and replace:

:s/old_text/new_text – replace next occurence on current line

:s/old_text/new_text/g – replace all occurence on current line

:%s/old_text/new_text/g – replace all occurences in the whole file

Page 19: Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell

Exercise 4● Open a file with vi - vi script.csh● Enter edit mode (i) and write text:

#/bin/tcsh

ls -1 | wc -1

● Exit edit mode (Esc), and save the file (:w).● Oops – we made a typo – last letter is l, not 1. Use

replace to fix it.● Save file again and quit (:wq)● Change mode of the script to be able to execute it. chmod u+x script.csh

● Practice some more editing with vi