October 11th, 2018
I sent an email to every person who answered the survey before October 10, 15:45
That email contains your account on the server. It has two parts:
The password is confidential. Only for your eyes
You are legally responsible for whatever happens with your account
To connect to the server we use a protocol called ssh
In Microsoft Windows™ we can use PuTTY
(you have to download and install it)
The server name, or hostname is
rstudio.iu.edu.tr
You can have an ssh client as an extension in Google Chrome
Look for it on Chrome Web Store
You can also install the Official Microsoft SSH client
The SSH client is a part of Windows 10, but it’s an “optional feature” that is not installed by default.
You use it from PowerShell or any other shell.
The command is sshusername@server
sshusername@serverThe first time you connect, there will be a warning
Just say “yes”. This is to verify that you are connecting to the correct server
To be sure that nobody else uses your account
change the password I gave you for a good password
There is an online app for generating passwords
If you do not trust this app, you can download the code and modify it
The command to change your password is
passwd
You need to write the old password once, and the new passwords twice
rm (remove file)To delete (remove) a file, use the rm command. As an example, we are going to create a copy of the science.txt file then delete it.
Inside your unixstuff directory, type
$ cp science.txt tempfile.txt $ ls $ rm tempfile.txt $ ls
rmdir (remove directory)You can use the rmdir command to remove a directory
(make sure it is empty first)
Try to remove the backups directory
You will not be able to since UNIX will not let you remove a non-empty directory
Create a directory called tempstuff using mkdir , then remove it using the rmdir command.
clear (clear screen)Before you start the next section, you may like to clear the window
At the prompt, type
$ clear
This will clear all text and leave you with the $ prompt at the top of the window.
cat (concatenate)The command cat can be used to display the contents of a file on the screen. Type:
$ cat science.txt
As you can see, the file is longer than than the size of the window, so it scrolls past making it unreadable.
lessThe command less writes the contents of a file onto the screen one page at a time. Type
$ less science.txt
As you can see, less is better than cat for long files
headThe head command writes the first ten lines of a file to the screen.
First clear the screen then type
$ head science.txt
Then type
$ head -5 science.txt
What difference did the -5 do to the head command?
tailThe tail command writes the last ten lines of a file to the screen.
Clear the screen and type
$ tail science.txt
Question. How can you view the last 15 lines of the file?
lessUsing less, you can search though a text file for a keyword (pattern).
For example, to search through science.txt for the word 'science', type
$ less science.txt
then, still inside less, type a / (forward slash) followed by the word to search
/science
As you can see, less finds and highlights the keyword. Type n to search for the next occurrence of the word.
grepgrep searches files for specified words or patterns. Type
$ grep 'science' science.txt
As you can see, grep has printed out each line containing the word science.
Is this all?
Try typing
$ grep 'Science' science.txt
The grep command is case sensitive; it distinguishes between Science and science.
To ignore upper/lower case distinctions, use the -i option. Type
$ grep -i 'science' science.txt
To search for a phrase or pattern, you must enclose it in single quotes
(this symbol: ')
For example to search for spinning top, type
$ grep -i 'spinning top' science.txt
-v display those lines that do NOT match-n precede each matching line with the line number-c print only the total count of matched lines
Try some of them and see the different results
For example, the number of lines without the words science or Science is
$ grep -ivc science science.txt
wc (word count)A handy little utility is the wc command, short for word count. To do a word count on science.txt, type
$ wc -w science.txt
To find out how many lines the file has, type
$ wc -l science.txt
| Command | Meaning |
|---|---|
rm file |
remove a file |
rmdir directory |
remove a directory |
cat file |
display a file |
less file |
display a file a page at a time |
head file |
display the first few lines of a file |
tail file |
display the last few lines of a file |
grep 'keyword' file |
search a file for keywords |
wc file |
count number of lines/words/characters in file |
We have already seen one use of the cat command to write the contents of a file to the screen.
Now type cat without specifying a file to read
$ cat
Then type a few words on the keyboard and press the [Return] key.
Finally hold the [Ctrl] key down and press d (written as ^D for short) to end the input.
If you run the cat command without specifying a file to read, it reads the standard input (the keyboard), and on receiving the ‘end of file’ (^D), copies it to the standard output (the screen).
In UNIX, we can redirect both the input and the output of commands.
We use the > symbol to redirect the output of a command. For example, to create a file called list1 containing a list of fruit, type
$ cat > list1
Then type in the names of some fruit. Press [Return] after each one.
pear banana apple ^D
(this means press [Ctrl] and [d] to stop)
The cat command reads the standard input (the keyboard) and the > redirects the output, which normally goes to the screen, into a file called list1
To read the contents of the file, type
$ cat list1
Using this method, create another file called list2 containing the following fruit:
orange plum mango grapefruit
Read the contents of list2
The form >> appends standard output to a file. So to add more items to the file list1, type
$ cat >> list1
Then type in the names of more fruit
peach grape orange ^D
(Ctrl-D to stop)
To read the contents of the file, type
$ cat list1
You should now have two files. One contains six fruit, the other contains four fruit.
We will now use the cat command to join (concatenate) list1 and list2 into a new file called biglist. Write
$ cat list1 list2 > biglist
What this is doing is reading the contents of list1 and list2 in turn, then outputing the text to the file biglist
To read the contents of the new file, type
$ cat biglist
We use the < symbol to redirect the input of a command.
The command sort alphabetically or numerically sorts a list. Type
$ sort
Write the names of some animals. Press [Return] after each one.
dog cat bird ape ^D
(control d to stop)
sortThe output will be
ape bird cat dog
Using < you can redirect the input to come from a file rather than the keyboard. For example, to sort the list of fruit, type
$ sort < biglist
and the sorted list will be output to the screen.
To output the sorted list to a file, type,
$ sort < biglist > slist
Use cat to read the contents of the file slist
To see who is on the system with you, type
$ who
One method to get a sorted list of names is to type,
$ who > names.txt $ sort < names.txt
This is a bit slow and you have to remember to remove the temporary file names.txt when you have finished
What you really want to do is connect the output of the who command directly to the input of the sort command
This is exactly what pipes do
The symbol for a pipe is the vertical bar |
For example, typing
$ who | sort
will give the same result as above, but quicker and cleaner.
To find out how many users are logged on, type
$ who | wc -l
Using pipes, display all lines of list1 and list2 containing the letter ‘p’, and sort the result.
| Command | Meaning |
|---|---|
command > file |
redirect standard output to a file |
command >> file |
append standard output to a file |
command < file |
redirect standard input from a file |
command1 | command2 |
pipe the output of command1 to the input of command2 |
cat file1 file2 > file0 |
concatenate file1 and file2 to file0 |
sort |
sort data |
who |
list users currently logged in |
This class is a derived work from http://www.ee.surrey.ac.uk/Teaching/Unix/
M.Stonebank@surrey.ac.uk, © 9th October 2000

Licensed under a Creative Commons License