Top Banner
1 Day 3 Directories Files Moving & Copying
28

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.

Dec 26, 2015

Download

Documents

Lee Flynn
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 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.

1

Day 3

Directories

Files

Moving & Copying

Page 2: 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.

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.

Page 3: 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.

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.

Page 4: 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.

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

Page 5: 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.

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 /

Page 6: 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.

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

Page 7: 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.

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

/

Page 8: 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.

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.

Page 9: 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.

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.

Page 10: 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.

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”

Page 11: 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.

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.

Page 12: 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.

12

Viewing a file

• So now that you can get to any directory, how do you read a file in that directory?– more <filename>– 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.

Page 13: 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.

13

Exercise

• You should have a file in your directory called “readme”

• View what is in that file.

Page 14: 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.

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.

Page 15: 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.

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

Page 16: 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.

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.

Page 17: 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.

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 .

Page 18: 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.

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 /

Page 19: 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.

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.

Page 20: 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.

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 <directoryname> ~enda

Page 21: 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.

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.

Page 22: 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.

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.

Page 23: 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.

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

Page 24: 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.

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.

Page 25: 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.

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.

Page 26: 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.

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.

Page 27: 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.

27

Exercise

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

Page 28: 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.

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.