1 day 18 bash and the.files. 2 the.files ls shows you the files in your directory –or at least...

12
1 Day 18 Bash and the .files

Upload: diana-wells

Post on 18-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

1

Day 18

Bash and the .files

Page 2: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

2

The .files• ls shows you the files in your directory

– Or at least most of them.– Some files are hidden.

• Try: ls –a– This will show you ALL files.

• Notice that any file which began with a “.” was omitted unless you give ls the –a flag.

Page 3: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

3

Why?• The Dot files are configuration files.

• Many programs you run need to store preferences and other information.– This is usually stored in a file called .programname

• Example– Each time you use vi to edit a file, it keep an autosave of

the file in a file called .filename.swp– If you get kicked off the server, when you go back it will

tell you that you can recover most of the changes you had made before you logged out. These are in the .swp file.

Page 4: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

4

The .bash_history• Each command you type is being stored in a history

file.– This is why you can use the up and down arrows to get to

previous commands you typed.

• Look at your .bash_history

Page 5: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

5

The .profile and .bashrc• The . profile is probably the most important file

– On this particular version of Unix, its configured to just call .bashrc and let it do all the work.

• .bashrc– It sets up the environment you use each time you log into

Unix.– It sets some important shell variables

• PATH• PS1

• A lot of your settings come from the fact that .bashrc then calls /etc/profile which is a system wide default profile.

Page 6: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

6

Fortune• Want to get your day off to the right start.

• Make your shell give you your fortune each time you log in.– There is a program called

• fortune

– Which each time its run, it gives you a “witty” comment.– Edit your .bashrc and add to the end the command

fortune.

Page 7: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

7

Rerun .bashrc• You can make Unix pretend that you are just

logging in again.– This is only useful if you have made changes to

your .bashrc file– Execute:

. .bashrc

Page 8: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

8

$PATH• This lists all directories which Unix will look in

each time you enter a command.

• Type: – echo $PATH

• See where all programs you run are.– which more

• Would show you which directory the program “more” is in. This directory is in your path, which is why you can run it.

Page 9: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

9

Adding to your path.• Imagine you have a directory called scripts in your

home directory.– export PATH=$PATH:/home/enda/scripts

• Would add it to your path. Now any script you create and put in that directory, can be run from ANY directory you are in. – You no longer have to be in the directory where the

script is, to run it.

Page 10: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

10

$PS1• $PS1 is a variable which stores your prompt.• Now your prompt looks something like:

– enda@kahuna:~ >

• Bash has special characters you can put in the prompt:– \d -Date– \H -Hostname– \t - Current time (Also \T and \@)– \u - Current user– \w - Current working directory (pwd)

• For more options see man bash

Page 11: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

11

Change your prompt:• Make your prompt look like this:

• kahuna – 12:27:30 >

• Remember to make this a permanent change, put it into your .bashrc file.

Page 12: 1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This

12

Seeing all variables• We know we can create variables:

– read x– x=17

• We know there are some magic default variables:– $PATH, $PS1 etc.

• How do we see a list of all variables and what they are currently set to?– set