1 day 5 additional unix commands. 2 important vs. not often in unix there are multiple ways to do...

16
1 Day 5 Additional Unix Commands

Upload: ann-underwood

Post on 01-Jan-2016

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

1

Day 5

Additional Unix Commands

Page 2: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

2

Important vs. Not• Often in Unix there are multiple ways to do

something.– In this class, we will learn the important commands, and

the most standard ones.

• Editors– vi, emacs, pico, joe etc. – These are all editors, all have different abilities, vi can do

everything the others can do, and is the most standard editor.

– More vs. less• Less can do a few more things than more…but they are not

immediately important. You can look at less later.

Page 3: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

3

Cat• Remember that “more” shows you the contents of a

file.– It stops after each screen and waits for you to hit a space

• cat does the same thing, but does not stop.– So cat shows you the whole file without pausing.

• This is mostly useful for scripting. We will see its use later.

Page 4: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

4

diff• Shows you the difference between 2 text files.

– diff file1 file2– This will show us all the differences between file1 and

file2. – Example:

• 12c12

• < This Line was in File 1

• ----

• > This line replaced it in File 2

Page 5: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

5

grep• grep looks for something in a file.

• grep enda file1

• Would look for any occurrence of the word “enda” in the file: file1

Page 6: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

6

grep vs. egrep• grep and egrep are very similar programs.

– egrep can do a few additional things:– Look for multiple things at once:

• egrep ‘enda|edna’ file1

• Would look for EITHER the word enda or the word edna

– Both support the -i option which tells them to ignore case, making them case insensitive.

Page 7: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

7

head• Looks at the first few 10 lines of the file.

– Sometimes handy when it’s a huge file, and you only care about what is at the top

• You can specify how many lines you want to see:– head -5 file1

• Will show you the first 5 lines

Page 8: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

8

tail• Looks at the last 10 items in a file.

• Very useful for seeing the most recent things which happened in a file.

• Often used to look at logfiles.

• You can change how many lines it shows you:– tail -5 file1

• Shows you the last 5 lines in the file

Page 9: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

9

sort• Sorts a bunch of stuff, and returns it to you sorted:

– sort file3

• Would return a sorted version of the file. Each line is sorted as a whole.

Page 10: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

10

uniq• Removes any duplicates that might be found in a

file

• uniq file1

• Would show you everything in file 1, but without any duplicate lines.

Page 11: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

11

Pipes• A pipe takes the output of one command, and sends

it to another.

• e.g. We have seen that cat shows us what is in a file:– cat letters | sort

• Normally cat would just show you the contents of the file letters on the screen. But here its output is being “piped” into the command sort. The result is that we will see the contents of the file letters sorted now.

Page 12: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

12

Piping with more• One of the most common questions that comes up in

unix, is “how do I stop it, there is more than a screen full”

• We know that “more” shows us a file, but stops at the end of each line.

• So we can use pipes and“more” to stop ANYTHING– e.g. ls /home

• Shows us a list of files in the directory /home

• There are so many, it will scroll off our screen before we can see it.

– ls /home | more• Still shows us the same thing, but stops at each screen full.

Page 13: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

13

who / w / finger• who tells you who is currently logged in.

– And when they logged in.

• w tells you what everyone is currently doing

• finger tells you:– When someone last logged in– If they have new mail– When they last read mail

Page 14: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

14

date / cal• Date tells you what time and date the machine

thinks it is.

• cal can show you a calendar for any month.

• By itself, it shows you this months calendar.

• Look at:– cal 9 1752 – This is the official calendar for September 1752

• They adjusted the calendar then. Hence the weirdness

Page 15: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

15

echo• echo prints what you just typed.

– Mostly useful for scripts

• Here is one example where its useful today:– echo “hello” | write enda

Page 16: 1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important

16

Zipping and Unzipping• In Windows you have probably seen files which are

zipped already.– blah.zip

• Zip is a way to compress a file and make it smaller. Then its easier to email or send to someone. When they get it, they will need to unzip it.

• In unix, we will use the commands:– gzip– gunzip

• Once a file has been zipped, you can no longer look at it in “more” as it is now a binary file.