Top Banner
Linux Commands & Tools v1.3 j3ffyang at gmail
26

Linux Common Command

Aug 27, 2014

Download

Software

Jeff Yang

Common command on Linux for operation and maintenance
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Linux Common Command

Linux Commands & Tools

v1.3

j3ffyang at gmail

Page 2: Linux Common Command

Environment Setting

BaSH, Bourne Again SHell (Linux default), vs. Korn Shell (on AIX)

Current envenv

System wide/ global/etc/bashrc -> aliases and functions (read always, login-shell and non-login-shell)/etc/profile -> env (read when login- shell)

User base~/.bashrc (/etc/bashrc read first, then ~/.bashrc)~/.profile

/etc/skel -> system level files copied to /home/user when created

Page 3: Linux Common Command

Environment Setting

Objective: Run WAS_installdir/bin/setupCmdLine.sh correctly

Solution:#!/bin/sh (symlinked to /bin/bash)source /file (run in current shell). file.sh (same as above)./file.sh (run in child shell process)

pstree

Page 4: Linux Common Command

Hardware Specification

Objective: How fast is CPU? How big is RAM? SWAP size?

Solution:cat /proc/cpuinfocat /proc/meminfocat /proc/swaps

Page 5: Linux Common Command

System Specification

Objective: How to partition harddisk before installing WebSphere Commerce?

Solution:/boot 100MB/ 10GSWAP =<2 x RAM (usually 1~ 1.2G if RAM=1G)

http://www.redhat.com/docs/manuals/enterprise/RHEL­4­Manual/pdf/rhel­ig­x8664­multi­en.pdf­> page 28

Page 6: Linux Common Command

Kernel - Messaging

Objective: Optimize kernel for DB2.

Solution:Display kernel parameteripcs ­l

Display kernel parameterEditing /etc/sysctl.conf

kernel.msgmni = 512kernel.sem=250  128000  32 1024

Activating kernel parameterssysctl ­p

http://www­106.ibm.com/developerworks/linux/library/l­ss3­db2/

Page 7: Linux Common Command

System Management

Objective: Want to how the file system being used?

Solution:du -cks $(ls -l | grep '^d' | awk '{print $9}') | sort -nrdu -ksh

Page 8: Linux Common Command

System Startup

Objective: Switch between X startup and command line startup.Change the runlevel.

Solution:cat /etc/inittab | grep “id”

Page 9: Linux Common Command

System Mgmt - fuser

Objective: Which process holds up the file?

Solution:fuserpid

[root@sevenj root]# fuser /var/log/messages/var/log/messages: 3292

User[root@sevenj root]# fuser -u /var/log/messages/var/log/messages: 3292(root)

Terminate the processes that using filefuser -kimuv /path/filefuser -kxuc /path/file (on AIX)

Port[root@sevenj root]# fuser 22/tcp22/tcp: 3470

Page 10: Linux Common Command

System Mgmt - lsof

Objective: Which program is running over a port?

Solution:lsof – LiSt Open File

Which application is using port 22?lsof -i:22[root@summerpalace /]# lsof -i:22COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEsshd 3803 root 3u IPv4 3387 TCP *:ssh(LISTEN)sshd 30328 root 4u IPv4 2616339 TCP summerpalace.torolab.ibm.com:ssh->9.26.190.11:33875 (ESTABLISHED)

Page 11: Linux Common Command

System Mgmt – lsof (cont'd)

What files are opened by PID?

[root@summerpalace /]# lsof -p 3803COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEsshd 3803 root cwd DIR 3,2 4096 2 /sshd 3803 root rtd DIR 3,2 4096 2 /sshd 3803 root txt REG 3,2 280184 551800 /usr/sbin/sshdsshd 3803 root mem REG 3,2 51924 535486 /lib/libnss_files-2.3.2.sosshd 3803 root mem REG 3,2 1563240 1054615 /lib/tls/libc-2.3.2.sosshd 3803 root mem REG 3,2 5572 292096 /usr/kerberos/lib/libcom_err.so.3.0sshd 3803 root mem REG 3,2 63880 292106 /usr/kerberos/lib/libk5crypto.so.3.0sshd 3803 root mem REG 3,2 385220 292116 /usr/kerberos/lib/libkrb5.so.3.1sshd 3803 root mem REG 3,2 971612 535528 /lib/libcrypto.so.0.9.7asshd 3803 root mem REG 3,2 91368 535470 /lib/libnsl-2.3.2.sosshd 3803 root mem REG 3,2 52584 1216870 /usr/lib/libz.so.1.1.4sshd 3803 root mem REG 3,2 12564 535504 /lib/libutil-2.3.2.sosshd 3803 root mem REG 3,2 76468 535498 /lib/libresolv-2.3.2.sosshd 3803 root mem REG 3,2 14728 535466 /lib/libdl-2.3.2.sosshd 3803 root mem REG 3,2 30448 535533 /lib/libpam.so.0.75sshd 3803 root mem REG 3,2 28452 1216947 /usr/lib/libwrap.so.0.7.6sshd 3803 root mem REG 3,2 106532 535453 /lib/ld-2.3.2.sosshd 3803 root 0u CHR 1,3 66540 /dev/nullsshd 3803 root 1u CHR 1,3 66540 /dev/nullsshd 3803 root 2u CHR 1,3 66540 /dev/nullsshd 3803 root 3u IPv4 3387 TCP *:ssh (LISTEN)

Page 12: Linux Common Command

System Mgmt – lsof (cont'd)

What application is holding a dir and files under that dir?

[root@summerpalace /]# lsof +d /var/logCOMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEsyslogd 3676 root 2w REG 3,2 1393576 780963 /var/log/messagessyslogd 3676 root 3w REG 3,2 925 780964 /var/log/securesyslogd 3676 root 4w REG 3,2 430 781130 /var/log/maillogsyslogd 3676 root 5w REG 3,2 10246 781139 /var/log/cronsyslogd 3676 root 6w REG 3,2 0 781134 /var/log/spoolersyslogd 3676 root 7w REG 3,2 0 781138 /var/log/boot.log

Page 13: Linux Common Command

System Mgmt – SWAP

Objective: Want to change SWAP size?

Solution:

mkswap /dev/hdaXsyncswapon /dev/hdaX

cat /proc/swaps

Page 14: Linux Common Command

System Mgmt – mkfs

Objective: Create a file system?

Solution:

fdisk -lfdisk /dev/hda

mkfs -t ext3 /dev/hdaXmkfs /dev/hdaXtune2fs -j /dev/hdaX (Convert ext2 to ext3. Journaled.)

mount /dev/hdaX /mount/point

Edit /etc/fstab/dev/hdaX /mount/point ext3 defaults 1 2

Page 15: Linux Common Command

File - compression

Objective: Compress/ Uncompress? The archive formats?

Solution:Compresszip *.zipjar *.jar (same as zip)tar -czvf *.tar.gzbzip2 *.bz2gzip *.gz / *.Zrar (http://www.rarlab.com/)

Uncompressunzipjar -xvftar -xzvfbunzip2gunzip

Page 16: Linux Common Command

File - editor

Objective: Edit the file?

Solution:vikate (Similar to UltraEdit. Install kdebase*.rpm)jedit (http://jedit.org)emacsed

Page 17: Linux Common Command

Network

Objective: Get the DHCP IP+ Register hostname in DNSSolution:

/etc/sysconfig/networkdhclient ethX /dhclient.conf (man dhclient.conf -> sample)

YaST or YaST2 (Yet another Setup Tools)/etc/hosts

Edit /etc/sysconfig/network-scripts/ifcfg-ethXAdd DHCP_HOSTNAME=<your_hostname>

Verification:hostname -s / -dnslookup / host / dig

Page 18: Linux Common Command

Network - netstat

Objective: Network status.

Solution: TCP/IPnetstat -pant

netstat -pat

Page 19: Linux Common Command

Network – http/ftp

Objective: Run ftp client in command line?

Solution:

wget -t3 -c -r -l 10 http://domain.org

-t= retry, -c= continue, -r= recursive, -l= depth (level of subdirectories)

Page 20: Linux Common Command

Performance - Process

Objective: The running processes' status?

Solution: How much the CPU usage?ps auxwww | sort +2 -rps -ef | sort +3 -r | head -n 5

How much the MEM usage?ps auxwww | sort +3 -r

The process tree.pstree

Page 21: Linux Common Command

Performance – Manage Srvc

Objective: Turn on / off the unnecessary services.

Solution: List all available services.chkconfig --listchkconfig –-list | grep 3:on

Check on / out services. eg.chkconfig iptables on | offchkconfig –level 2345 iptables on

less /etc/init.d/iptablesls /etc/rc.d/rc3.d

Stop a service. eg./etc/init.d/sshd start | stop

Page 22: Linux Common Command

Performance - Memory

Objective: System memory usuage.Solution:

vmstat <interval> <length>eg.

vmstat 1 10

[root@summerpalace root]# vmstat 1 10procs memory swap io system cpu r b swpd free buff cache si so bi bo in cs us sy id wa 1 0 0 146512 107140 616064 0 0 4 17 105 30 0 0 99 0 0 0 0 146428 107140 616064 0 0 0 148 130 76 0 4 96 0

r: The number of processes waiting for run time.si / so: Swap in/ outbi / bo: Blocks in/ outus: User timesy: System timeid: Idle

Reference: What's block and character device?http://www.uwsg.iu.edu/usail/concepts/filesystems/everything­is­a­file.html

Page 23: Linux Common Command

Performance - top

Objective: Overall system performance.

Solution:

top

s – interval in secondM – sort by memoryP – sort by CPU

Page 24: Linux Common Command

RPM

Objective: Manage the packages

Solutions: RPM = RedHat Package Manager. Used by RedHat, SuSE and Mandrake. Debian dpkg converter is available.

Install / Updaterpm -Uvh package.rpm (vs. -ivh)rpm -Uvh package.rpm --nodepsrpm -Uvh –-aid package.rpm (require rpmdb-*.rpm installed)

Uninstallrpm -e package_namerpm -e –-allmatches package (man rpm, search allmatches)

RPM DB Rebuilddb_verify /var/lib/rpm/Packagesrpmdb --rebuilddb

Page 25: Linux Common Command

RPM (cont'd)

Solutions:

Find an RPMrpm -qa | grep -i package_name

Which rpm does a file belong to?rpm -qf /path/file

The pre- requisite of an RPM?rpm -q –-requires mozilla

Where is the RPM installed?rpm -qil mozilla

Check RPM's changelogrpm -qi mozilla

Page 26: Linux Common Command

MultiMedia :-)

Objective: Have fun in work with Linux :-)Solution:

xmms (Play MP3)grip (Rip wave to MP3)

Make ISO file for burning discmkisofs -r -o file.iso /path/files

Test to mountmount -t iso9660 -o ro,loop=/dev/loop0 file.iso /mnt/tmp

Scan CD writercdrecrd -scanbus

Write ISO to disccdrecord -v speed=8 dev=0,0,0 -data file.iso

GUI CD write -> http://www.xcdroast.org/xcdroast