Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Day 3 Directories Files Moving & Copying. 2 Case Sensitive First thing to learn about UNIX is that everything is case sensitive. Thus the files: –enda.

Similar presentations


Presentation on theme: "1 Day 3 Directories Files Moving & Copying. 2 Case Sensitive First thing to learn about UNIX is that everything is case sensitive. Thus the files: –enda."— Presentation transcript:

1 1 Day 3 Directories Files Moving & Copying

2 2 Case Sensitive First thing to learn about UNIX is that everything is case sensitive. Thus the files: –enda –Enda –ENDA Are all different files. Be careful to type the right one. –This applies to commands also.

3 3 What is a Directory There must be some way to organize a bunch of files. Perhaps we would want them sorted into folders. In windows “My Computer” has the “C Drive” in it. In there, you can see many folders. In UNIX, a similar organizational structure exists.

4 4 What directory am I in? In windows you can tell which directory you are in by looking at the directory tree at the left You might say that this user is in the Directory: C:\Documents and Settings\enda\Desktop

5 5 Unix Directories To find out which directory you are in you can type: –pwd This will return something like: –/home/enda Notice that in UNIX directories are separated by / where as in dos they are separated by \ –Also note that no drive “C:\” appears in the directory listing. Everything in unix starts at /

6 6 Moving around To move into another directory you type: –cd bob This would move you into a directory called bob which is under the current directory –cd.. This would move you back one directory from where you are now –cd / This will take you all the way to the top of the file system

7 7 Example: enda@kahuna:~ > pwd /home/enda enda@kahuna:~ > cd html enda@kahuna:~/html > pwd /home/enda/html enda@kahuna:~/html > cd.. enda@kahuna:~ > pwd /home/enda enda@kahuna:~ >cd / enda@kahuna:~ >pwd /

8 8 How do you know what’s here? How did I know “html” was a directory? Type: –ls In any directory this will give you a LIST of all files and directories which are in the your current directory –On this particular telnet client, with this particular setup, directories will show up in blue. We will see more reliable ways to tell if something is a directory later.

9 9 Exercise Move around a little using, pwd and cd Attempt to get into the directory: /usr/bin/games See if you can get there in one command from anywhere. See if you can get there bit by bit from wherever you are.

10 10 Phone Home If you just type: –cd No matter where you were, it will take you home. You can also type: –cd ~enda The weird ~ is called tilde and is typically located above the ` character on your keyboard. –In general the ~ means “home directory of the person mentioned next”

11 11 Directory Permissions Sometimes you will try to cd somewhere, and you will be told “Permission Denied” –e.g. Try to type this: cd /etc/rc.d –This is because the person who owns this directory has chosen not to let people into it. You can configure the permissions on your files. We’ll look at that in a few days.

12 12 Viewing a file So now that you can get to any directory, how do you read a file in that directory? –more –e.g. more readme More will show you the contents of the file, one page at a time on the screen. –You hit the space bar to move to the next page. –You can hit q to quit.

13 13 Exercise You should have a file in your directory called “readme” View what is in that file.

14 14 File and Directory Names On a UNIX system, names should not contain spaces. –It is possible to have spaces, however it makes life more complicated. We’ll look at that in a few weeks. There is no special file ending you should use like DOS or Windows. –In DOS.exe means it’s a program..txt means it’s a text file. –In unix the ending is unimportant. You don’t even have to have one.

15 15 Renaming Lets imagine you don’t like the name “readme” for the file you just looked at. How would you change it to “helpful.information” –mv readme helpful.information mv stands for “move”. Notice that the new file name has a dot in it, which doesn’t mean anything here. You could call it: –help.full.information.for.me

16 16 Moving a file into a directory Lets imagine we are currently in the directory: –/home/enda In here there is a directory called: –html And a file called: –new.stuff How do we get new.stuff into the directory html: –mv new.stuff html We can use ls and cd to verify that.

17 17 Oops…get it back How do we get that file back in the directory it started? –cd html –mv new.stuff.. OR –mv html/new.stuff ~enda OR –mv html/new.stuff /home/enda OR –mv html/new.stuff.

18 18 Dots…dots…dots So, a single dot means. “The directory I am currently in” –So what does this do: mv stuff. A double dot (..) means “The directory just above where I am now”. –You could have more than one like this: mv stuff../../.. This would move “stuff” back 3 directories towards /

19 19 Copying What if you don’t want to actually remove the original file, instead you just want your own copy. –cp e.g. Let’s imagine you want a copy of my readme –cp ~enda/readme. –This does not remove the file from my directory, but does give you a copy of it.

20 20 Moving/Coping directories Moving –Works exactly the same as if it were a single file Copying –If you wish to copy the directory AND ALL files in it: cp –R ~enda

21 21 Making new directories You can make a new directory with the command: –mkdir newdirectory –This will create a new directory under the current directory.

22 22 Wild cards What if you want to copy all files which start with an “s” in this directory: –cp s* destination Or perhaps all files which end with “x” –cp *x destination Or, files which start with “s” AND end with “x” –cp s*x destination Or all FILES in this directory –cp * destination –Note you don’t have to do *.* like in DOS.

23 23 Exercise Make the following directory structure in your home directory: –MyFiles 1601 –Homeworks –Quizzes 2611 –Homeworks –Quizzes Put a copy of the readme file in my directory (~enda) into each of your Homeworks directories

24 24 Exercises Copy all of the “How-to” files which start with the letter V into your 1601/Quizzes directory. –The how-to’s are located in /usr/doc/howto/en When you have completed that, move any of them which have the letter “q” in their file name into the 1601/Homework directory –Don’t do this by hand, have the computer figure it out with the right command.

25 25 Exercise We have decided to quit 2611, move all files from the 2611 directory into the 1601 directory. –Be sure the Homeworks end up in the Homeworks directory –Be sure the Quizzes end up in the Quizzes directory.

26 26 Deleting Be careful what you delete –There is no recycle bin, once its gone, its gone. To remove a file type: –rm readme To remove a directory: –rmdir html –However the directory must be empty first, first cd into it, rm *, and then cd.., now you can remove it.

27 27 Exercise Delete all files which start with VM in your 1601/Quizzes directory

28 28 Remember man is your friend If you can’t remember how to do something, man can probably tell you how: –man ls –man cd –man more –man mv –man cp Many of these commands have interesting options which can do special things. The man page will tell you.


Download ppt "1 Day 3 Directories Files Moving & Copying. 2 Case Sensitive First thing to learn about UNIX is that everything is case sensitive. Thus the files: –enda."

Similar presentations


Ads by Google