BC3203

Introduction to Unix Notes

Entering Commands

Let’s see what this command does

ls -l -h ~/

Which bit is the command, the options, the argument

The ls command

This command is the equivalent of a Finder window or a windows explorer window. Instead of navigating with the mouse we do it with text.

  1. What does it do?
  2. Without options
  3. Without arguments
  4. What is the -l option?
  5. What is the -h option?

Other commands for navigating the filesystem

pwd
mkdir test
ls
cd test
pwd

Making directories and copying files

The mkdir command can be used to create a directory

mkdir test
ls

The touch command can be used to create an empty file.

touch afile
ls

To copy afile into test we use the cp (Copy) command

cp afile test/
ls 
ls test

Or we could move mv the file (Careful)

mv afile test/
ls 
ls test

Absolute and relative paths

cd
pwd
cd /home/iracooke

Equivalent to

cd /
cd home
cd iracooke

Special paths

cd ..
cd ~

Inspecting contents of a file

First we need a file with something in it!

We can use the fortune command to generate some text

fortune

Each time you run it will produce something different

fortune
fortune
touch fortunes.txt
for i in $(seq 10);do echo "Fortune $i" >> fortunes.txt; fortune >> fortunes.txt;done
head fortunes.txt
tail fortunes.txt
grep 'Fortune' fortunes.txt
wc fortunes.txt

Pipes

head fortunes.txt | wc
head fortunes.txt