Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to UNIX A User’s Perspective: Day 3: Advanced Commands & vi.

Similar presentations


Presentation on theme: "Introduction to UNIX A User’s Perspective: Day 3: Advanced Commands & vi."— Presentation transcript:

1 Introduction to UNIX A User’s Perspective: Day 3: Advanced Commands & vi

2 What We Will Cover Today Shell customizations File operation commands The UNIX search utility vi Shell script basics

3 Clean Up: Standard Error Redirecting standard error – 2> = redirect standard error Let’s redo the link example seen yesterday – cat file 2> errors – cat index.html 2> errors

4 BASH! User friendly & Free Want to switch – $ bash Easy to navigate and edit at command-line – Let’s see…

5 Bash Tip 1 History recall – The up/down arrow Korn Shell equivalent – $ set –o vi Let’s you use vi control keys at the command-line

6 Bash Tip 2 Tab completion – Hitting the tab key will attempt to complete file name from the current directory – Example $ cd $ cd pu (hit the tab key)

7 Bash Tip 3 Remembering your history – Attempts to auto complete commands previously entered – Start with CTRL-R – Start typing Try ls -al

8 Bash Customization Ideas Make you life easier Examples: – $ alias procs=‘echo “Number of processes are: ”;ps | wc –l’ Issue the command ‘procs’ – $ procs – $ alias ll=‘ls –al’ – $alias l=‘ls’ These can be placed in your.profile so they are always available

9 Understanding Your Environment env – Values that follow you when you change shells set – Values set when you enter a shell – Lost when leave that shell

10 File Operations join grep diff cmp dircmp split sed

11 join cd cp –p /u/ux101is1/jointest*. sort –k 1 jointest1 > jtest1s sort –k 1 jointest2 > jtest2s join jtest1s jtest2s – What are the issues? – What are possible resolutions?

12 grep cd grep your_user_name /etc/passwd – What did you find? grep –i Filter * – What did you find? – What is the problem?

13 diff cd diff jtest1s jtest2s

14 cmp & dircmp cmp file1 file2 – cmp jtest1s jtest2s dircmp directory1 directory2 – dircmp -ds public_html public_html/test > dircmp.txt

15 split Example – $ split -l 1 jtest1s student – $ ls –al – $ cat student*

16 sed Example: – cd – cp -p jtest1s sedtest – $ cat sedtest – $ sed -e 's/mark/mike/g' sedtest > sedtest1 – $ cat sedtest1

17 Subshells No change to your current shell state – ( some commands ) – Example 1: $ ( date; who ) > whowhen.txt – Example 2: $ cd $ pwd $ ( cd pub*; pwd ) $ pwd – Implications?

18 The UNIX Search Tool find – Very versatile – Built in command handling – Extremely extensible – Can be used to search by any file characteristic

19 Advanced find Example 1: – find /u/msaba/public_html -type f -print | grep refs

20 Advanced find Example 2: – find /u/msaba/public_html -type f -print | grep refs 2> errors

21 Advanced find Example 3: – find /u/msaba/public_html -type f -print 2> errors | grep refs

22 Advanced find Example 4: – find. -name "*" -exec grep -i "ocks" {} /dev/null \;

23 find: Directory Tree Mapping Show the directory hierarchy of /tmp – $ find /tmp –type f –o –print – $ find /tmp –type d –print

24 Making find More Efficient A better way of invoking grep large number of files is: – $ find. -type f -print | xargs grep ocks – $ find. -type f -print 2> errors | xargs grep ocks 2>> errors This results in far fewer invocations of grep – Runs faster – Less system load

25 vi – The Only Editor You Need Why learn vi? – You don’t always have a GUI interface – It’s on every UNIX system – It’s powerful – Try it, you’ll like it!

26 Let’s Edit Something To create a new file – # vi new_file_name – # vi To open a file for editing – # vi existing_file_name

27 Additional Modes for Starting vi vi –r file – Recover the last saved version after a crash (rare) vi –R file – Read-Only vi +n file – Open with cursor at line number n vi file1 file2 file3 – Open multiple files, move between using :n

28 A Cool Feature of vi :r – Reads into the current file the contents of a file :r file – OR – The output of a command :r !command

29 Shell Scripts The first line: – #!/usr/bash The rest of the file: – Standard command sequences

30 A shell Script Example cd public_html vi bash.script – #!/usr/bash – cp –p /u/ux101fa*/ jointest* /u/ux101fa*/ public_html – sort -k 1 jointest1 > autojtest1s – sort -k 1 jointest2 > autojtest2s – join autojtest1s autojtest2s $. bash.script

31 What Should You Know? How to Log on and off of a UNIX system Be familiar with UNIX shells Be familiar with the UNIX file system UNIX Paths, ownership and permissions Use UNIX commands Use vi Write a basic shell script

32 Question? Anyone… anyone?

33 THANK YOU FOR ATTENDING Please fill out the Evaluation Form before leaving.

34


Download ppt "Introduction to UNIX A User’s Perspective: Day 3: Advanced Commands & vi."

Similar presentations


Ads by Google