Você está na página 1de 17

UNIX For Beginners

What is UNIX ?

Developed in 1969 in a telecom operators lab (AT&T).

In 1973, it was rewritten in C language.

In 1983, SunOS (Later Solaris) was developed by Sun Microsystems.

Today, many variety exsit in market, Solaris has the leading share.

Unix Philosophy: (by Doug Mcllory)

* Write programs that do one thing, and do it well


* Write programs that work together
* Write programs to handle text streams, because that is a universal interface.
Superiorities

* Stability

* Designed for multiple-client

* Advanced security

* Advanced process management (child process, daemons)

* Open-source. (or nearly open-source)


Shell

* Kernel : The kernel is the core of the UNIX operating system. Basically,
the kernel is a large program that is loaded into memory when the machine is
turned on, and it controls the allocation of hardware resources.

* Shell : The shell is a type of program called an interpreter. The shell is a program
that the UNIX kernel runs for you. A program is referred to as a process
while the kernel is running it.

The basic form of a UNIX command is:


commandname [-options] [arguments]
Ex : ls l /tmp

Breaking a shell command : <ctrl C>

Help on usage : man ls


File System
Whats In a Disk?

* Boot Block : Stores Boot Procedures


* Super Block : Contains file system size & status. Inode information ( ls i)
* Inode Table : ls l information + Disk block address
* Storage Block : Data blocks, regular files

* File is a string of bytes attached to a directory inode


Moving Around

ls /usr
ls l /usr
ls al /usr
ls lrt /usr
pwd
cd ../
cd
cd
cd /u*
cd /u*/f*
File Types

- File Type Description


d
l - Indicates a file
ln s s1 t1
d Indicates a plain directory

b A block special file

c A character special file

l A link

m Shared memory

p A named pipe

s A semaphore
File Permissions

Column 1 Columns 2-4 Columns 5-7 Columns 6-8


d r w x r w x r w x
d r w x r w - r - -
- r w x r - - r - -
- r - x - - - - - -

chmod 755 <file>


chmod 777 <file>
ls l /etc/passwd
Basic Commands (I)

Grep : Global Regular Expression Print


Think grep as search

grep x <file>
cat <file> |grep x

grep i <file>
grep h <file>
cat <file> |grep v x

Cp : cp fx ../
cp p fx ../
Mv : mv fx ../
Rm : rm fx
Rmdir : rmdir dx
Mkdir : mkdir dx
Tar : tar cvf file.tar ./dx
tar xvf file.tar .
Compress : compress fx
Uncompress : uncompress fx.Z
Basic Commands (II)

Wc : Word Count
wc l /etc/passwd
wc /etc/passwd
Df : How full is a file system?
df h .
Du : Shows disk usage
du -ks
Find : find /usr -name x -type f print
Head : head -15 /etc/rc
Tail : tail /etc/rc
tail f /etc/rc
Cat : cat fx
More : more fx
Gzip : gzip fx
Gunzip : gunzip fx.gz
Gzcat : gzcat fx.gz
Sort : sort fx > fx2
sort u fx > fx2
Diff : diff <file1> <file2>
Sed : sed n <st1>, <st2>p <file>
Redirecting Input & Output

Every program you run from the shell opens three files:
Standard input, standard output, and standard error.

The standard input file provides a way to send data to a process.


As a default, the standard input is read from the terminal keyboard.
The standard output provides a means for the program to output data.
As a default, the standard output goes to the terminal display screen.
The standard error is where the program reports any errors encountered during execution.
By default, the standard error goes to the terminal display.

A program can be told where to look for input and where to send output,
using input/output redirection.
UNIX uses the "less than" and "greater than" special characters (< and >) to signify
input and output redirection, respectively.

more < /etc/passwd


ls /tmp > ~/ls.out
ls /etc >> fx
sort < /etc/passwd > foo 2> err
Pipelines & Filters

UNIX allows you to connect processes, by letting the standard output of one process
feed into the standard input of another process. That mechanism is called a pipe.

cat file | head -75 | tail -50


cat fx | wc -l
Process Control

ps
ps ef
ps ef |grep bch |wc l

kill <pid>
kill -9 <pid>

Backgroud Job : Process not connected to the terminal


Foreground Job : Process connected to the terminal
HUP (Hangup) Signal Suppressed Job : NOHUP job. Daemons are NOHUP jobs.

ls > fx
ls > fx &
nohup ls > fx &
Execution Environment

The exact behavior of commands issued in the shell


depends upon the execution environment provided by the shell.

printenv
echo $TERM
cat .profile
Very Nice Text Editor

vi fx
More

more file | egrep "(dummy1|dummy2)

(Dizindeki dosyalarn byte olarak toplam)


ls -l | awk '{print s += $5 }' | tail -1

ls -ltr TT*|awk {'print $9'}|cut -c -13|uniq d

(Sfr sizel dosyalar siler)


rm `ls -l |grep " 0 " | awk '{print $9}'`

for k in ls */*/*
do
mv $k $k.gz
done

for a in `ls`
do
b=`echo $a|awk -F">" '{print $1}'`
mv ${b}* $b
done

Você também pode gostar