unix for librarians

34
Unix for Librarians Ravi Mynampaty [email protected]

Upload: ravi-mynampaty

Post on 24-Jun-2015

270 views

Category:

Technology


2 download

DESCRIPTION

Workshop

TRANSCRIPT

Page 1: Unix for Librarians

Unix for Librarians

Ravi [email protected]

Page 2: Unix for Librarians

About me

Just a hustler making a living by pretending to know more about search than he actually does...

Page 3: Unix for Librarians

Workshop Goals

● Remember the roaring 90's?

● Geared towards beginners

● Lifetime guarantee!

Page 4: Unix for Librarians

What is Unix?

Multi-user

Multi-tasking

Hierarchical filesystem

Everything is a file

Page 5: Unix for Librarians

Philosophy

Doug McIlroy:● Write programs that do one thing and do it

well. ● Write programs to work together. ● Write programs to handle text streams,

because that is a universal interface.

Page 6: Unix for Librarians

Let's get started

These slides:- Slideshare

Use your own shell or

Go here:http://bellard.org/jslinux/

Page 7: Unix for Librarians

A brief note about shells

Many flavorsBourne (sh)Korn (ksh)Bourne-again (bash)C-shell (csh)tcsh

echo $0

Page 8: Unix for Librarians

How do I get in/out?

login: searchguyPassword:Authentication successful

Logout> exit, logout

id, whoami

passwd

Page 9: Unix for Librarians

Where am I?hostname

uname -a

pwd

cd

ls

Page 10: Unix for Librarians

Exercise

Login to JS shell

1. Who are you logged in as?2. What is the name of the machine?3. What is the OS? and version?4. What dir are you working in?5. Change dir to /bin

a. Look at a listing of all files in that dirb. are there any that begin with 'z' (just eyeball it for

now)

Page 11: Unix for Librarians

What's around me?

cat

less is better than more

Page 12: Unix for Librarians

Documentation/Locations

man

apropos

which

whereis

Page 13: Unix for Librarians

Exercise

1. Examine the /etc/passwd filea. what are a couple of ways of doing this?

2. Where is the "less" utility located on the filesystem?

Page 14: Unix for Librarians

Who's around?

who

finger

w

last

Page 15: Unix for Librarians

Directories

mkdir new_dir

cd dir_name

pwd

your home dir

Page 16: Unix for Librarians

Filescp old_file new_file

mv old_file new_file

grep search_str filename

head filename

tail filename

Page 17: Unix for Librarians

Exercise

1. Navigate to /etc/ directory2. Take the file named "passwd"

a. Make 4 copies in /var/tmp/b. Name them as follows:

i. passwd1, passwd2, passwd3, passwd43. Search for the string "daemon" in any one of

the 4 filesa. How many instances did you find?

Page 18: Unix for Librarians

Files

sort filename

uniq filename

dos2unix oldfile newfile

find path -name '*html'

wc filename

cut: selected fields from each line

Page 19: Unix for Librarians

File compression

gzip filename

gunzip filename.gz

zcat filename.gz

tar cvf all.tar file1 file2 file3 ...tar tvftar xvf

Page 20: Unix for Librarians

Hidden Files

ls -a

.profile

.cshrc

.login

.aliases

. and ..

Page 21: Unix for Librarians

File/Directory permissions

ls -l

-rwxr-xr-x

-u, g, o

chmod 775 filenamechmod g+w filename

Page 22: Unix for Librarians

Linking

ln old_file new_file

ln -s old_file new_file

Page 23: Unix for Librarians

Exercise: Linking

1. Navigate to /var/tmp2. Create a hardlink to the passwd3 file3. Create a symlink to the passwd4 fileWhat do you see?

1. Delete passwd3 and passwd4What do you notice?

Page 24: Unix for Librarians

Editing files

vi

emacs

...

Page 25: Unix for Librarians

What did I do?!

[and can I do it again?]

history

!!

!13

Page 26: Unix for Librarians

I/O Redirection, Pipes

>

<

>>

|

xargs

Page 27: Unix for Librarians

Exercise: I/O, Redirection

command arg1 arg2 ... > filename

● cat > io.txtUnix is great, much better than many other os'smakes me very productiveCONTROL-D

● cat < io.txt● In /var/tmp merge all passwd* files into one

Page 28: Unix for Librarians

Exercise: Pipes

● Your merged file in /var/tmp○ find the uniq lines○ sort the file○ now let's pipe it!

● sort filename | uniq

● find . -name 'pass*' | xargs grep -i nobody

Page 29: Unix for Librarians

More on pipes...history | perl -pe 's/^ +[0-9]+//' | sort | uniq -c | sort -nr | head

"Top 200" list of directory sizes (under /dir-name - in KB) sorted by largest:du -dk /dir-name | sort -rn | head -200 > report.txt

List of requesting IP's from a web server log, sorted by most frequent first:cut -f1 -d\ access.log | sort | uniq -c | sort -rn

[df: free disk blocks, du: disk usage]

Page 30: Unix for Librarians

Processes

psps -ups -eps -auxww

top

Page 31: Unix for Librarians

Dealing with processes

kill pid

bg a process: command &

jobs

fg job_number

nice

Page 32: Unix for Librarians

Remotely

scp

rsync

sftp

ping

traceroute

ifconfig

Page 33: Unix for Librarians

Automation

at

cron

Page 34: Unix for Librarians

There's plenty more...

But for now...

...thanks for attending!

[email protected]