Help - Search - Members - Calendar
Full Version: Help with linux commands
Linuxhelp > In The Community > General Discussion
bbmaster123
hey,
so I am taking an introductory course to linux, and I'm having trouble with one of my labs. I cant find the attach file button so I'll just paste the instructions here.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ULI101 Lab 03 - Unix Pathnames / Directory Structure

Pathnames in Unix/Linux are divided into two types . The first is the absolute pathname, which always starts with the / (forward slash), commonly named the root. The second type of pathname is the relative pathname, which is aptly named, for it is relative to your current working directory location. It is important for the user to be able to create and manipulate the file structure by using both absolute and relative pathnames.
Note:
Most beginners have more difficulty understanding and becoming proficient with relative pathnames than absolute.
Keep that in mind and practice relative pathnames as much as possible.

Let's take a look at a sample of an absolute pathname to create a directory off of your home directory named seneca.
Since we are using an absolute pathname to create the seneca directory, we know that the pathname must start with the /, or root. Hence, the command line:

username@matrix:~> mkdir /home/username/seneca (where "username" is your Matrix login ID).

If you want to make the same directory in your home directory using a relative pathname you would not start with the slash, or root, but would simply name the file, assuming that your current working directory is already your home directory. Hence, the command line:

username@matrix:~> mkdir seneca
Practical Application

Create the directory tree structure shown below using relative pathnames in your matrix account's home directory. Use the touch command to create empty files matching the filenames displayed within the directories. You can detect a directory if the name appears in blue - all regular files appear in green or black.
Note:
If the Labs directory still exists from your previous work, you do not need to create that directory.



Verify that your directory structure is correct by using the tree command.
Examine the tree diagram that is shown and verify you have correctly created the above structure before continuing this lab.
File System Navigation

To move around in a directory tree you use the cd command with absolute or relative pathnames. Using the directory tree structure shown above, let's take a look at how to navigate the entire tree. (You will need to replace username with your own login name).
Note:
Issuing the cd command without a pathname argument will always take you back to your home directory, regardless of your current location

To move to the seneca directory using an absolute pathname:

cd /home/username/Labs/lab4a/seneca

To do the same operation using a relative path:

cd Labs/lab4a/seneca
Note:
The above relative path assumes that your present working directory is your home (/home/your_username/)directory.

If you wish to go up within a directory structure using a relative path you will need to use a special relative pathname - .. (double period), which represents the parent directory. Consequently, the ../.. path represents the parent of the parent directory and so on.
Note:
All directories on a Unix/Linux file system have a parent directory except the root directory

For example, if your current location is library, to move to the newnham directory you would use the following relative pathname command:

$ cd ..

(If you examine the library directory you will notice that newnham is the parent of library.)

As another example, if your current location is security, to move to the cns directory you would use the following relative pathname command
:
$ cd ../../s@y/cns

(The first set of ..'s moves you to the newnham directory, the second set of ..'s moves you to the root. Then you simply declare the path down to your location.)

Note:
Some beginners incorrectly assume that all relative pathnames start with the .. path.
Although such approach may work some of the time, it shows a lack of understanding of relative pathnames and leads to inefficient work habits.

Consider this: if your present working directory were newnham, and you would like to change it to security using a relative pathname, the correct answer would be: cd security
A successful, but inefficient alternative could be: cd ../newnham/security

Before continuing with this lab make sure you execute the following command successfully:

uli101.lab03

The above script will verify that your directory structure has been created correctly and offer suggestions in case of problems.
Make sure to correct all reported errors before proceeding.
bbmaster123
Pathname Exercise

Perform the following operations, writing down your commands as you go.

Use relative parthames for questions 1-12.

1. Make sure you are in your home directory.

Command line used:__________________________________

2. Move to lab4a using a relative pathname.

Command line used:__________________________________

3. Move to the security directory using a relative pathname.

Command line used:__________________________________

4. Move to the newnham directory using a relative pathname.

Command line used:__________________________________

5. Move to your home directory using a relative pathname.
(don't use the tilde (~) for this move)

Command line used:__________________________________

6. Move to the seneca directory:

Command line used:__________________________________

7. While in seneca , using a relative pathname, make a copy of the file named parking (from the security directory) and name it parking2 and place it in your current directory.

Command line used:_____________________________________________________
(verify you were successful by issuing a tree or ls command.)

8. Still in seneca , using a relative pathname, rename the file named annex (from the richmondhill directory) to annex2 , leaving it in its present location.

Command line used:_____________________________________________________
(verify you were successful by issuing an appropriate command.)

9. Still in seneca , using a relative pathname, move to the s@y directory.

Command line used:_____________________________________________________
(verify you were successful by issuing an appropriate command.)

10. Now in the s@y directory, using a relative pathname, move the file outline.doc to the lab4a directory.

Command line used:_____________________________________________________
(verify you were successful by issuing an appropriate command.)

11. Still in the s@y directory, using a relative pathname, delete the faculty directory.

Command line used:_____________________________________________________
(verify you were successful by issuing an appropriate command.)

12. Still in the s@y directory, using a relative pathname, make a new empty regular file named dir_practice inside the library2 directory.

Command line used:_____________________________________________________
(verify you were successful by issuing an appropriate command.)

At this point in the lab you have likely noticed that we have been working exclusively with relative pathnames.
However, it is important to also practice the absolute pathnames.

For the following questions, answer the questions similar to questions 1 - 12, but use absolute pathnames. Do this on paper, (DO NOT issue the commands on your matrix account)

13. Move to your home directory using an absolute pathname.

Command line used:__________________________________

14. Move to the security directory using an absolute pathname.

Command line used:__________________________________

15. Using absolute pathnames, rename the file named annex (from the richmondhill directory) to annex2, leaving it in its present location.

Command line used:_____________________________________________________

16. Using absolute pathnames, move the file outline.doc to the lab4a directory.

Command line used:_____________________________________________________

17. Using an absolute pathname, delete the faculty directory.

Command line used:_____________________________________________________

18. Using an absolute pathname, make a new empty regular file named dir_practice inside the library2 directory.

Command line used:_____________________________________________________
bbmaster123
Lab Submission

In order to receive a mark for this lab you will need to submit your work results electronically.
To submit your lab, do the following steps:
a) Using vi create a file called uli101.032.ans located in your Labs directory
cool.gif Copy all your answers (above commands) into this file, using the following format for your answers:
1. Your answer
2. Your answer

up to ...

18. Your answer
c) Save your answers and execute the following command: uli101.lab03

The above script will offer suggestions in case of problems and record your submission once all answers are correct.
Conclusion

This lab has covered the creation and navigation of directories and files using both absolute pathnames and relative pathnames. To strengthen the knowledge you have gained from this lab, make sure to always think of the alternative method when manipulating files and directories. If you only use one method you will find yourself to be very weak in the other and this will affect your test scores.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
See now what happens is you run the uli101.lab03 command and it runs a script that checks you answer file for correctness and then submits the answers if they are correct, otherwise it tells you to do them over. Right now, 1-3 are correct, but it says questions 4-18 are incorrect. here are my answers so far:
1.cd
2.cd /Labs/lab4a
3.cd newnham/security
4.cd..
5.cd /home
6.cd Labs/lab4a/seneca
7.~/Labs/lab4a/newnham/security/parking parking2
8.mv ~/Lab/lab4a/richmondhill/annex annex2
9.cd ~/Labs/lab4a/s@y
10.mv ~/Labs/lab4a/s@y/cty/outline.doc ~Labs/lab4a
11.rm -r ~/Labs/lab4a/faculty
12.touch ~/Labs/lab4a/newnham/library2/dir_practice
13.cd
14.cd Labs/lab4a/newnham/security
15.mv /Labs/lab4a/richmondhill/annex annex2
16.mv /Labs/lab4a/s@y/cty/outline.doc /Labs/lab4a
17.rm -r /Labs/lab4a/faculty
18.touch /Labs/lab4a/newnham/library2/dir_practice
So my question is, can anyone verify that number 4 is correct/incorrect? it would be greatly aprreciated
michaelk
We are not here to do your homework for you but will assist if you with specific help.

cd .. (there is a space in between cd ...) The .. is a short cut to move up a directory level i.e if the current working directory is /home/username/stuff then after the command was executed your current working directory is /home/username.

The cd command without options will always move you back to the home directory.

Make sure you keep track of where you are in the tree structure.
bbmaster123
sorry, I wasn't asking for you to do my homework tongue.gif I just posted everything just incase. I hadn't realized there's a space between cd and ..
thanks!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.