Unix Project 1

What You Need

Basic Unix knowledge as covered here:

http://www.ee.surrey.ac.uk/Teaching/Unix/index.html"

Preparing your Directory

Execute these commands, as shown below.
cd
mkdir temp
cd temp
pwd

Notice your full working directory--it will be different from mine.

Making a File

Execute this command:
nano foo
This opens the Nano text editor. Type in the four lines of shown below.

Notice the two lines of text at the bottom of the window. Nano uses these to tell you what's happening.

Press Ctrl and tap X.

The message at the bottom changes, as shown below.

Tap Y to save the file, and then press Enter to agree to the unchanged filename.

File and Folder Manipulation

Execute these commands, as shown below.
cp foo foo2
cp foo foo3
mkdir a
cp foo a
cd a
pwd
ls -l
You end up in a subdirectory named a containing only one file, as shown below.

Relative Paths

You can change files in other directories by prefixing a filename with a path that gets to the file you want.

.. is the path that goes Up, one directory above your current working directory.

. is the name of your current working directory.

Execute these commands, as shown below.

pwd
ls
ls ..
mv ../foo2 .
ls
You end up in a subdirectory named two files, as shown below.

Challenge

List the files in the temp directory you created at the start of this project.

A file is missing from that directory.

Put it back with one command from your current working directory.

Grep

Execute these commands, as shown below.
cd
cd temp
ls

You should see three items, as shown above.

Execute these commands, as shown below.

grep cat foo
grep e foo

The first grep shows lines containing "cat", and the second shows lines containing "e".

Permissions

Execute these commands, as shown below.
ls
ls -l

The first command shows the names of files and directories in the current working directory.

The second command shows a list in long form, showing the permissions at the start of each line.

"d" means the item is a directory, and "-" means it is a file.

The next nine characters show the permissions for the owner, group, and others.

Redirection

Execute these commands, as shown below.
ls
ls > bar
cat bar
echo 1
echo 1 > bar2
cat bar2

See how output that was going to the screen, stdout, is redirected to a file with >.

> empties a file before inserting new text.

>> is used to append to a file.

Execute these commands, as shown below.

cat bar
cat bar > bar3
cat bar >> bar3
cat bar3

You ended up with two copies of the contents of bar in bar3. Execute these commands, as shown below.

echo 1 > bar3
cat bar3

Now bar3 contains only one line again, because we used > instead of >>

Challenge

Do all this without changing your working directory.
  1. Make a subdirectory named "b"
  2. Copy foo into b
  3. Insert the contents of foo into a file named "copy" inside the b subdirectory
  4. Append the contents of bar to the "copy" file in the "b" subdirectory
  5. Move the "copy" file back to your working directory
  6. cat the "copy" file. It should look like the image below.

Pipes

Execute this command:
ps -ax

A long list of running processes scrolls past.

To stop it from scrolling out of sight, use this command:

ps -ax | less

Now the list appears one page at a time. To go to the next page, press the SPACEBAR.

Execute this command:

ps -ax | grep apple

You see the processes containing "apple", as shown above.

Execute this command:

ps -ax | wc -l

You see a count of the running processes, as shown above.

Challenges

Solve these all with a single line of bash code:


Last revised: 3-2-15 12:52 pm