Download presentation
Presentation is loading. Please wait.
Published byAnn Underwood Modified over 9 years ago
1
1 Day 5 Additional Unix Commands
2
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.
3
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.
4
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
5
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
6
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.
7
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
8
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
9
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.
10
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.
11
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.
12
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.
13
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
14
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
15
15 echo echo prints what you just typed. –Mostly useful for scripts Here is one example where its useful today: –echo “hello” | write enda
16
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.