unix for librarians

Post on 24-Jun-2015

265 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Workshop

TRANSCRIPT

Unix for Librarians

Ravi Mynampatysearchguy@hbs.edu

About me

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

Workshop Goals

● Remember the roaring 90's?

● Geared towards beginners

● Lifetime guarantee!

What is Unix?

Multi-user

Multi-tasking

Hierarchical filesystem

Everything is a file

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.

Let's get started

These slides:- Slideshare

Use your own shell or

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

A brief note about shells

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

echo $0

How do I get in/out?

login: searchguyPassword:Authentication successful

Logout> exit, logout

id, whoami

passwd

Where am I?hostname

uname -a

pwd

cd

ls

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)

What's around me?

cat

less is better than more

Documentation/Locations

man

apropos

which

whereis

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?

Who's around?

who

finger

w

last

Directories

mkdir new_dir

cd dir_name

pwd

your home dir

Filescp old_file new_file

mv old_file new_file

grep search_str filename

head filename

tail filename

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?

Files

sort filename

uniq filename

dos2unix oldfile newfile

find path -name '*html'

wc filename

cut: selected fields from each line

File compression

gzip filename

gunzip filename.gz

zcat filename.gz

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

Hidden Files

ls -a

.profile

.cshrc

.login

.aliases

. and ..

File/Directory permissions

ls -l

-rwxr-xr-x

-u, g, o

chmod 775 filenamechmod g+w filename

Linking

ln old_file new_file

ln -s old_file new_file

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?

Editing files

vi

emacs

...

What did I do?!

[and can I do it again?]

history

!!

!13

I/O Redirection, Pipes

>

<

>>

|

xargs

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

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

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]

Processes

psps -ups -eps -auxww

top

Dealing with processes

kill pid

bg a process: command &

jobs

fg job_number

nice

Remotely

scp

rsync

sftp

ping

traceroute

ifconfig

Automation

at

cron

There's plenty more...

But for now...

...thanks for attending!

searchguy@hbs.edu

top related