Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative...

87
Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution Lice See http://software-carpentry.org/license.html for more informati The Unix Shell

Transcript of Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative...

Page 1: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories

Copyright © Software Carpentry 2010

This work is licensed under the Creative Commons Attribution License

See http://software-carpentry.org/license.html for more information.

The Unix Shell

Page 2: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Communicate

with each other

Interact

with us

Run

Programs

Store

Data

Page 3: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Communicate

with each other

Interact

with us

Run

Programs

Store

Datashell

Page 4: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Store

Datashell

Page 5: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Store

Datashell

file system

Page 6: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Store

Datashell

file system

files

Page 7: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Store

Datashell

file system

files directories

Page 8: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Store

Datashell

file system

files directories

Use the shell

to view and change

the file system

Page 9: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Store

Datashell

file system

files directories

Use the shell

to run commands

to view what's in

the file system

Page 10: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login:

Page 11: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: computer prompt in bold

Page 12: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: computer prompt in bold

explanatory text in blue

Page 13: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad user input in green

Page 14: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ******** password

Page 15: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ shell prompt

Page 16: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ shell prompt

like Python's >>> and …

Page 17: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami check user ID

Page 18: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami check user ID

shell finds the whoami program

Page 19: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami check user ID

shell finds the whoami program

runs it

Page 20: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vladcheck user ID

shell finds the whoami program

runs it

prints its output

Page 21: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$

check user ID

shell finds the whoami program

runs it

prints its output

displays a new prompt

Page 22: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd what is the working directory

Page 23: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd what is the working directory

the directory used when no other

directory is explicitly specified

Page 24: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

Page 25: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

root

Page 26: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

/

root

Page 27: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

/

root

Page 28: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

bin

/

root

Page 29: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

bin data

/

root

Page 30: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

bin data users

/

root

Page 31: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

bin data users tmp

/

root

Page 32: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

bin data users tmp

/

root

Page 33: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

bin data users tmp

/

root

imhotep larry vlad

Page 34: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

bin data users tmp

/

root

imhotep larry vlad

Page 35: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

bin data users tmp

/

root

imhotep larry vlad

Page 36: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$

bin data users tmp

/

root

imhotep larry vlad

Page 37: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$ ls stands for "listing"

Page 38: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$ ls stands for "listing"

sadly more memorable than

most command names

Page 39: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$ ls

bin data mail music

notes.txt papers pizza.cfg solar

solar.pdf swc

$

Page 40: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$ ls -F

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$

an argument or flag modifying

the command's behavior

Page 41: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

login: vlad

password: ********

$ whoami

vlad

$ pwd

/users/vlad

$ ls -F

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$

adds a trailing '/' to

directory names

Page 42: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ ls -F

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

vlad

bin musicmail papersdata

solar

notes.txt

pizza.cfg solar.pdf swc

Page 43: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ ls -F

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

By convention, use filename extension to indicate file type

Page 44: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ ls -F

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

By convention, use filename extension to indicate file type

.txt for text, .pdf for PDF, .cfg for configuration file, etc.

Page 45: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ ls -F

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

By convention, use filename extension to indicate file type

.txt for text, .pdf for PDF, .cfg for configuration file, etc.

But this is only a convention, not a guarantee

Page 46: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ ls –F data

Page 47: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ ls –F data

amino_acids.txt elements/ morse.txt

pdb/ planets.txt sunspot.txt

$

Page 48: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

vlad

data

a relative path

$ ls –F data

amino_acids.txt elements/ morse.txt

pdb/ planets.txt sunspot.txt

$

Page 49: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

vlad

data

a relative path

relative to

current working directory

$ ls –F data

amino_acids.txt elements/ morse.txt

pdb/ planets.txt sunspot.txt

$

Page 50: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ ls –F /data

access.log backup/ hardware.cfg

network.cfg

$

Page 51: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

an absolute path

$ ls –F /data

access.log backup/ hardware.cfg

network.cfg

$

Page 52: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

an absolute path

leading '/' means "from root"

$ ls –F /data

access.log backup/ hardware.cfg

network.cfg

$

Page 53: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

bin data users tmp

/

imhotep larry vlad

an absolute path

leading '/' means "from root"

so it always refers to

this directory

$ ls –F /data

access.log backup/ hardware.cfg

network.cfg

$

Page 54: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad

$

Page 55: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$

Page 56: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ cd data

Page 57: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ cd data change directory

Page 58: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

change directory

actually doesn't change the directory

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ cd data

Page 59: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

change directory

actually doesn't change the directory

changes the shell's idea of

which directory we are in

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ cd data

Page 60: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ cd data

$ pwd

/users/vlad/data

$

Page 61: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ cd data

$ pwd

/users/vlad/data

$ ls

amino_acids.txt elements/ morse.txt

pdb/ planets.txt sunspot.txt

$

Page 62: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

because we're now "in"

this directory

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ cd data

$ pwd

/users/vlad/data

$ ls

amino_acids.txt elements/ morse.txt

pdb/ planets.txt sunspot.txt

$

Page 63: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$

Page 64: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$ cd ..

Page 65: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$ cd .. the directory above the current one

Page 66: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$ cd .. the directory above the current one

its parent directory

Page 67: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$ cd ..

$ pwd

/users/vlad

$

Page 68: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$ cd ..

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$

Page 69: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$ cd ..

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ ls -F -a

./ ../ bin/ data/

mail/ music/ notes.txt papers/

pizza.cfg solar/ solar.pdf swc/

Page 70: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$ cd ..

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ ls -F -a

./ ../ bin/ data/

mail/ music/ notes.txt papers/

pizza.cfg solar/ solar.pdf swc/

"show all"

Page 71: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$ cd ..

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ ls -F -a

./ ../ bin/ data/

mail/ music/ notes.txt papers/

pizza.cfg solar/ solar.pdf swc/

parent directory

Page 72: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$ cd ..

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ ls -F -a

./ ../ bin/ data/

mail/ music/ notes.txt papers/

pizza.cfg solar/ solar.pdf swc/

parent directory

/users

Page 73: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

$ pwd

/users/vlad/data

$ cd ..

$ pwd

/users/vlad

$ ls

bin/ data/ mail/ music/

notes.txt papers/ pizza.cfg solar/

solar.pdf swc/

$ ls -F -a

./ ../ bin/ data/

mail/ music/ notes.txt papers/

pizza.cfg solar/ solar.pdf swc/

this directory

itself

Page 74: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

Page 75: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Page 76: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Drive letter

Page 77: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Drive letter

Each drive is a separate file system

Page 78: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Backslash \ as separator

Page 79: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Backslash \ as separator

Unix uses \ to escape special characters

in names like my\ files.txt

Page 80: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Case insensitive

Page 81: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Case insensitive

c:\users\vlad C:\USERS\VLAD C:\uSeRs\VlAd

Page 82: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Cygwin: /cygdrive/c/Users/vlad

Map drive letters to "directories"

Page 83: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Cygwin: /cygdrive/c/Users/vlad

Map drive letters to "directories"

And use / instead of \

Page 84: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Cygwin: /cygdrive/c/Users/vlad

Map drive letters to "directories"

And use / instead of \

But still case insensitive

Page 85: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

Things are different on Windows

C:\Users\vlad

Cygwin: /cygdrive/c/Users/vlad

Map drive letters to "directories"

And use / instead of \

But still case insensitive

Can't put backup.txt and Backup.txt in a directory

Page 86: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

Files and Directories Introduction

pwd print working directory

cd change working directory

ls listing

. current directory

.. parent directory

Page 87: Files and Directories Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See .

August 2010

created by

Greg Wilson

Copyright © Software Carpentry 2010

This work is licensed under the Creative Commons Attribution License

See http://software-carpentry.org/license.html for more information.