Labs‎ > ‎Linux Labs‎ > ‎

Linux Lab 03 - Using the File System

In this lab you will practice moving around the Linux file system.  You'll practice creating, copying, moving, renaming and deleting data.

Copying, Moving, and Renaming Data

The first thing we need to do is create the directory structure for this lab.  We'll run a script to create the structure which stored in google drive.  You can download the script using a web browser, or you can type the command wget http://goo.gl/23fj6O && mv 23fj6O lab3.sh from the shell.  Either way you need to have a file named lab3.sh in your home directory.  When you have the script in place, run it by typing sh lab3.sh

Let's see what the script did for us.  Type in ls and press enter to see a list of the files and directories in your home directory.  You'll see a new directory named "lab3".  Change your current working directory to lab3 by typing cd lab3 and press enter.  Type ls and press enter to list the contents of the lab3 directory.  You'll see four directories in lab3.  List the contents of the Documents directory in lab3 by typing ls Documents and press enter.  Don't forget you can use the tab key to autocomplete directory names.  You'll see a bunch of documents listed in the Documents directory.

In lab3 we see a directory named "DeleteMe".  Delete the directory by typing rm DeleteMe and pressing enter.  Notice the error when you type this command.  It couldn't delete it because it's a directory.  Let's try typing rm -ir DeleteMe and pressing enter.  The r option will delete recursively which will allow us to delete the directory.  The i option will make the deleting interactive, or ask you if you want to delete each file.  We'll be asked if we want to descend into the directory, type y for yes.  Then you will be asked if you want to delete a file named ImportantDoc.  We DO NOT want to delete this file so type n for no on the next two questions.

Before we can delete the DeleteMe directory we need to move ImportantDoc to the Documents directory.  Type mv DeleteMe/ImportantDoc Documents and press enter.  After that try and delete the directory again using the command rm -ir DeleteMe and pressing enter.  Type y to answer yes to the question.

Do the same thing for the directory named "Delete Me Too".  Make sure you save the file named "Chapter 5.txt" to ~/lab3/Documents/Homework.

Our next task will be to rename the directory named "RenameMe".  Before we can rename it we need to find out what kind of data is in the directory.  Type ls RenameMe and hit enter.  When you do you'll see MP3 files, or music files listed.  We'll rename the directory to "Music" by typing mv RenameMe Music and pressing enter.  Notice there is no rename command, in order to rename we move the data to the new name.

Now that we've done all this work in ~/lab3 we'll make a backup of the data.  Type in cp -r ~/lab3 ~/backup and press enter.  Then type ls -RF ~/backup to verify the data copied.  The backup directory didn't exist, so the cp command created it.

Creating Files and Directories

We're going to create some new directories and files using the mkdir and touch commands.  The mkdir command is used to make directories, and the touch command is used to create files.  Using these command create the directories and files listed below.  All directories end with a forward slash.  When you're done download http://goo.gl/23fj6O into the Downloads directory using wget.

~/lab3a/
├── Documents/
│   ├── Final Project.txt
│   ├── Forms/
│   ├── Network Docs/
│   │   ├── Elementary School.txt
│   │   ├── High School.txt
│   │   └── Middle School.txt
│   └── Taxes/
│       ├── 2005.txt
│       ├── 2006.txt
│       ├── 2007.txt
│       ├── 2008.txt
│       ├── 2009.txt
│       ├── 2010.txt
│       ├── 2011.txt
│       ├── 2012.txt
│       ├── 2013.txt
│       ├── 2014.txt
│       └── 2015.txt
├── Downloads/
├── Music/
└── Video/

Type in ls -RF ~/lab3a > ~/lab3a.txt and press enter to send the directory listing to the lab3a.txt file.  You will use this file later when you answer the lab questions.

Finding Files

We're going to switch back to the lab3 directory for this part of the lab.  We're going to change our working directory to the Labs directory by typing cd ~/lab3/Documents/Labs and pressing enter.  Display a listing of the files in the Labs directory by typing ls and press enter.

Notice lab 6 is missing.  Let's try and find it using the find command, type find ~ -name "Lab 6*" and hit enter.  

Let's use the locate command to find the missing lab.  Before we can use the locate command we have to update the database.  Type sudo updatedb then hit enter.  Now type locate Lab\ 6 and hit enter.

Move "Lab 6.txt" to the Labs directory.  After that type in ls -RF ~/lab3 > ~/lab3.txt and press enter to send the directory listing to the lab3.txt file.  You will use this file later when you answer the lab questions.

Questions

Answer the lab questions.

12 | 3 | 4