unix linux
Download
Skip this Video
Download Presentation
Unix/Linux

Loading in 2 Seconds...

play fullscreen
1 / 36

Unix/Linux - PowerPoint PPT Presentation


  • 196 Views
  • Uploaded on

Unix/Linux. Contents. Unix file system introduction Unix Common commands useful tips sharing snoop tool / tcpdump Set env. variables trouble shooting/diagnose (solaris) Diff b/w Linux and unix. Unix system structure. / (root). lib. tmp. bin. var. dev. lib. usr. root. boot.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Unix/Linux' - winter


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
contents
Contents
  • Unix file system introduction
  • Unix Common commands
  • useful tips sharing
  • snoop tool / tcpdump
  • Set env. variables
  • trouble shooting/diagnose (solaris)
  • Diff b/w Linux and unix
unix file system hierarchy

/ (root)

lib

tmp

bin

var

dev

lib

usr

root

boot

src

etc

scott

lib

alice

n321

man

mail

bin

sbin

local

bin

sbin

bob

home

public_html

share

UNIX File system Hierarchy
unix common commands
Unix common commands
  • Files commands grep,find,tail,ln,diff,tar/gzip,chmod,chown
  • System commands

df,du,ifconfig,netstat,route,mount/umount,swap

  • Process commands

ps,top,kill,bg,nohup,crontab

grep egrep fgrep display lines that match
grep/egrep/fgrep–display lines that match
  • grep [options] regexp [files...]

e.g.

grep \'^\.\' myfile.txt

grep –i “exception” */*

find . |xargs grep -i “exception" #

ls –al|grep ‘^d’ # List the directory in currect path:

  • fgrep --It does not use regular expressions; instead, it does direct string comparison to find matching lines of text in the input.
  • egrep --Search a file for a pattern using full regular expressions
find find files matching a type or pattern
find--find files matching a type or pattern
  • find directory [options] [actions] [...]
  • e.g.
  • find . -name hello -print #
  • find . –mtime +7 –print # list the files modified 7days ago
  • find . –size +2000m –print #list the files larger than 2000m
  • find /tmp –user b123 –print#print the files belong to b123 user under tmp.
  • find . -name "*.php" –exec/ok rm {} \;# find and remove this php files

or find . –name “*.php” |xargs rm

tail ln diff
tail/ln/diff
  • tail --display the last few lines (or parts) of a file.

tail [options] file

e.g

tail –f filename #display last 10 lines

tail –5f filename # display last 5 lines

  • ln--link the source_file to the target

ln [options] source target

  • diff --compare the two files and display the differences (text files only)

diff file1 file2

file archiving compression tar gzip gunzip
File Archiving, Compression--- Tar/gzip/gunzip
  • tar [options] [directory file]

gzip [options] file

gunzip[options] file

  • Extract from an archive

gunzip backup.tar.gz

or tar -xvf backup.tar

  • Create an archive:

tar -cvf backup.tar /etc #backup.tar

gzip -q backup.tar #backup.tar.zip

  • tar –tf backup.tar #list the files in archive
chmod chown chgrp
chmod/chown/chgrp
  • chmod --- change file permissions

chmod nnn [argument list] numeric mode

chmod [who]op[perm] [argument list] symbolic mode

chmod u+xrw file

chmod g+x file

chmod o-rw file

chmod 750 file

  • chown change the ownership of a file

chown[options] user[:group] file

  • chgrp change the group of the file
df du
df,du
  • df --summarize disk block and file usage

df [options] [resource]

Common Options

-l local file systems only

-k report in kilobytes

  • du report disk space in use

du [options] [directory or file]

ps top kill nohup
ps,top,kill, nohup
  • ps --Show status of active processes

ps –ef|grep ems

  • Kill --terminate a process

kill [-signal] processID

kill –l #displays the available kill signals

kill -9 processID #kill the processId of process

  • Top/topas/prstat --display all running processes
  • nohup --Runs a command even if the session is disconnected or the user logs out

nohup find -name \'*\' -size +1000k > log.txt

crontab
crontab
  • Crontab -- List of files that you want to run on a regular schedule.

crontab –l ; crontab -e

  • All crontab files are maintained in the /var/spool/cron/crontabs in solaris.
  • These first five fields are separated by spaces and indicate when the command will be executed.

10,20 3 * * 0 /usr/sbin/log/adm

slide15

ifconfig--allows the operating system to setup network interfaces and allow the user to view information about the configured network interfaces

  • ifconfig eth0 # View the network settings on the first Ethernet adapter installed in the computer.
  • ifconfig –a #display into on all network interfaces on server, active or inactive.
  • ifconfig eth0 down #If eth0 exists would take it down causing it cannot send or receive any information.
  • ifconfig eth0 up #If eth0 exists and in the down state would return it back to the up state allowing to to send and receive information.
  • ifconfig eth0 192.168.1.102 netmask 255.255.255.0 broadcast 192.168.1.255 #Assign eth0 with the above values for IP, netmask and broadcast address.
netstat shows network status
netstat -- Shows network status.
  • netstat #Displays generic net statistics of the host you are currently connected to.
  • netstat –an #Shows all connections to the server including the source and destination ips and ports if you have proper permissions.
  • netstat –rn #Displays routing table for all ips bound to the server.
  • netstat -an |grep :80 |wc –l #Display the amount of active connections on port 80. Removing the pipe and wc command would display each connection.
  • netstat –natp #Display active Internet connections.
route show manipulate the ip routing table
route -- Show / manipulate the IP routing table
  • route –n #Shows routing table for all IPs bound to the server. (linux)
  • route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0 #adds a route to the network 192.56.76.x via "eth0". The Class C netmask modifier is not really necessary here because 192.* is a Class C IP address. The word "dev" can be omitted here.
  • route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0 #This is an obscure one documented so people know how to do it. This sets all of the class D (multicast) IP routes to go via eth0". This is the correct normal configuration line with a multicasting kernel.
mount umount swap
mount/umount,swap
  • Mount --- mount a partition

mount -F hsfs -o ro /dev/dsk/c0t6d0s0 /cdrom

mount -F pcfs /dev/diskette0 /floppy

mount /dev/dsk/c0t0d0s0 /tmp/xxx

  • umount -- Unmount a partition

umount /cdrom

  • swap

mkfile 10G /home/swapfile

/usr/sbin/swap -a /home/swapfile

/usr/sbin/swap –l

/usr/sbin/swap –d /home/swapfile

rm -rf /home/swapfile

redirection
Redirection <, >, >>,|,;
  • Pipe | :The output of the first command is sent as the input to the second command, and so on,

who | more

  • ; Grouping commands

%pwd; cal 1 2000; date

  • >> append the results of the command to the existing file.
  • > The results of the command will be sent to the specified file
set env variables
Set env. variables
  • .profile

/etc/profile /root/.bash_profile /home/abc/.bash_profile

  • Commands set –local variable

env –global variable

  • add variables to .profile

MOT_NSM_HOME=/opt/EMS

export MOT_NSM_HOME

  • Re-logon, the variable will take effect.
other useful commands tips
Other useful commands tips
  • converts Unix text file line to Dos

unix2dos : sed –e ‘s/$/\r/’ file1 > file2

dos2unix : sed –e ‘s/.$//’ file1 > file2

  • How to remove ^M in the file
  • # cat test.dat | tr -d \'\015\' > test.out
  • or #dos2unix test.dat test.out
  • watch –n N command(linux) #
  • init 0 ~6
  • init 0 shutdown server
  • init 6 restart server
  • vi filename1 filename2 …

:n #edit next file

:e# # edit prev file

:1,$s/ABC/abc/g #abc to replace ABC in file

snoop solaris xcapturing and inspecting network packets
Snoop(solaris) –xcapturing and Inspecting Network Packets
  • to see what happens when one system uses the ping command to communicate with another system.
  • %snoop sys41 sys42

sys41 -> sys42 ICMP Echo request

sys42 -> sys41 ICMP Echo reply

  • Use the -a option to enable audible clicks, which notify you of any network traffic.

%snoop -a dhcp

  • shows how to turn on audible clicks for all network traffic related to a Dynamic Host Configuration Protocol (DHCP) boot.
touble shooting diagnose 1
Touble shooting/diagnose (1)
  • 1.  How to setup solaris network. We usually meet the following problem

1.1 how to config the IP,gateway, router,netmask, both dynamicly and staticly?

Please add a file named S* in /etc/rc2.d/,such as S99router

The content of this file is a command to exec

1.2 how to add multi virtual IP to a single interface?

    • #ifconfig bge0:100 plumb
    • #ifconfig bge0:100 11.14.33.100 netmask 255.255.255.0 up
    • #ifconfig bge0:100 unplumb

1.3 how to disable certain network interface for test?

    • ifconfig eth0 down
touble shooting diagnose 2
Touble shooting/diagnose (2)
  • 2. root user can\'t telnet on a remote client.

Edit /etc/default/login and comment out “CONSOLE=/dev/console”

  • 3. root user can\'t ftp on a remote client

Edit /etc/ftpd/ftpusers and comment out “root”

  • 4. how to monitor the performance of the Solaris/Linux, including MEM,CPU,disk I/O, network I/O
touble shooting diagnose 3
Touble shooting/diagnose (3)
  • 5. Certain Solaris command cannot be used

    1) Check disk space to confirm whether there is the capacity of any filesystem is 100% #df –h

    2) Check the permission of some important directories. The directories must exist and have “x” permission./usr, /etc/ssh, /bin, /usr/bin

  • 6. forget the root passwd

#boot cdrom -s #mount /dev/dsk/c0t0d0s0 /mnt #cd /mnt/etc #vi shadow #umount /mnt 

touble shooting diagnose 4
Touble shooting/diagnose (4)
  • 7. If we meet system issues, such as the whole system can\'t boot. how to sovle? and how to collect the important saloris info(explorer)
  • 8. Why some user can\'t excute command cron and at to schedule a task?
  • 9. what\'s the difference between halt/reboot/shutdown/init #(# refers to a run level). what\'s the right step to reboot a system?
touble shooting diagnose 5
Touble shooting/diagnose (5)
  • 10. how to kill a service in solaris 10? (SMF related)

Please use “svcs disable “, not the “kill -9”

  • 11. how to delete temp file effectively? the following two commands are useful for programmers to delete certain files

    #find $HOME/. -name *.txt -ok rm {} \

     #find . \( -name a.out -o -name \'*.o\' -o -name \'core\' \) -exec rm {} \

  • 12. what\'s the difference between the two command "#./set_env" and "#. ./set_env"?
    • The parent shell can get the env set by the child shell
touble shooting diagnose 6
Touble shooting/diagnose (6)
  • 13. Nov 20 15:25:04 unix /usr/lib/snmp/snmpdx: [ID 702911 daemon.error] unable to get my IP address: gethostbyname(unix) failed [h_errno: host not found(1)]
    • Please add the hostname to hosts file
    • #nodename

unix

    • #vi /etc/hosts127.0.0.1       localhost       unix    loghost
  • 14. Nov 20 15:36:32 unix ip: [ID 482227 kern.notice] ip_arp_done: init failed
    • Don’t use the interface name as the hostname
touble shooting diagnose 7
Touble shooting/diagnose (7)
  • 15. Nov 20 15:37:21 unix sendmail[318]: [ID 702911 mail.crit] My unqualified host name (localhost) unknown; sleeping for retry
    • You should edit /etc/hosts like this, please note the FQDN and loghost

192.168.224.251 outer   outer.c204.comloghost

    • svcs disable /network/smtp:sendmail
touble shooting diagnose 8
Touble shooting/diagnose (8)
  • 16. When use “crontab -e” to add a cronjob, we can’t see the content of the cron table

#EDITOR=vi

#export EDITOR

  • 17. When connect via console, and edit a file with vi, we can only see part of the file

$ TERM=VT100

$ export TERM

diff b w linux and unix
Diff b/w linux and unix
  • Linux –free and open source, just kernel, based on UNIX standards, runs on many hardware platforms.
  • Unix --compete operating system, commercial application (if you wanted to buy one) typically costs much more for a commercial UNIX , a typical UNIX is proprietary-hardware-bonded.
the linux proc file system
The Linux Proc File System
  • The proc file system does not store data, rather, its contents are computed on demand according to user file I/O requests
  • Proc is organized in virtual directories and subdirectories, provide hardware information, such as /proc/cpuinfo, /proc/meminfo, and /proc/interrupts. The files under /proc/sys are related to kernel configuration parameters.
  • The /proc special directory provides full detailed information about the inner workings of Linux and lets you fine-tune many aspects of its configuration. If you spend some time learning all the possibilities of this directory, you\'ll be able to get a more perfect Linux box.
linux versions study website
Linux versions/study website
  • Redhat http://www.redhat.com
  • Fedora (cover many features of windows) http://fedora.redhat.com
  • 红旗LINUX (China) htt://www.redflag-linux.com
  • SUSE Linux http://www.opensuse.org
  • Mandrake Linux http://www.mandriva.com
ad