Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2551575
  • 博文数量: 709
  • 博客积分: 12251
  • 博客等级: 上将
  • 技术积分: 7905
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-17 00:00
个人简介

实现有价值的IT服务

文章存档

2012年(7)

2011年(147)

2009年(3)

2008年(5)

2007年(74)

2006年(431)

2005年(42)

分类: 系统运维

2006-04-13 15:31:04

--转自CSDN上 jerryfleming 的 Blog
 

############################################################################
#
#     Useful Linux Commands
#  ----------------------------------------------------------------------
#   Jerry Fleming, 2004-09-13
#
############################################################################

# show system load in ascii art
tload
# simple watcher
swatch
# send process to bg like C-Z does
suspend
# execute a command by someone else
sudo
# change to another user(default: super user)
su
# change to another group
newgrp
# process information
procinfo
#show uid and gid
id
# gnu interactive tools process status
gitps

# tar ball size restricted
tar cvzpf - mytarfile.tar.gz | split -d -b 500m
cat x* > mytarfile.tar.gz

# save man page and info to file
man tcsh | col -b > tcsh.txt
info tcsh -o tcsh.txt -s

# join two files
cat file1 file2 | sort | uniq # (unique) lines in both files
cat file1 file2 | sort | uniq -d # (duplicated) lines in both files
cat file1 file2 | sort | uniq -u  # lines only in one file

# show system info
cat /proc/cpuinfo # CPU (i.e. vendor, Mhz, flags like mmx)
cat /proc/interrupts # interruptions
cat /proc/ioports # ioports
cat /proc/meminfo # mem used, free, swap size
cat /proc/partitions # all partitions on all devices
cat /proc/pci # PCI devices
cat /proc/swaps # all swaps
cat /proc/version # equal to: uname -r
uname -a

# shwo (and kill) processes using filename
fuser filename
fuser -k filename

# show netbios name of a host
nbtscan -r 192.168.1.0/24
# show ip of host with netbios name
nmblookup 192.168.0.1
# send a message to win host (Messenger service on NT and WinPopup on '98)
smbclient -M NETBIOS
# useful on linux and windows
netstat -nap


# who am i
echo $LOGNAME
echo $USER
id
whoami
who am i
logname

# change properties of a file
chattr
setfacl

# show the size of a dir
du -sh dirname

# reh hat version info
cat /proc/version
cat /etc/redhat-release
cat /etc/issue

# what is running on port 22
lsof -i :22

# rename a host
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/hosts
/etc/sysconfig/network

# show the size of pwd
du --max-depth=0 -h
# calculate the sum of first column in myfile
gawk 'BEGIN{sum=0;} sum = sum+ $1; END{print sum;}' myfile

# mysqldump synopsis
mysqldump -Q -p --opt -B aiqing avo geofuture leidi17 lizi17 phpmyadmin qiti swy 新COM > dbdump
mysqldump -Q -p --opt -B fiveone > fiveonedump
mysqldump -Q -p --opt -B newcom > newcomdump
mysqldump -Q -p --opt -B mysql > mysqldump
# update a database from update log files
ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
# update a MySQL server from the binary log
mysqlbinlog log-file | mysql -h server_name
# mysql charset and collation
mysql> SET PASSWORD FOR = OLD_PASSWORD('jerry');
query("SET character_set_results = big5") ;
query("SET collation_connection = big5_chinese_ci ");
query("SET character_set_client = big5 ");
query("SET character_set_connection = big5 ");
mysql> SET character-set-client = x;
mysql> SET character-set-results = x;
mysql> SET character-set-connection = x;


# to encode one script do:
php -q encoder.php -f input.php -o output.php

# to encode directory do:
php -q encoder.php -rcf input_dir -o output_dir

# eigth modes of operation for tar
create extract list append update concatenate delete compare

# copy contents of a dir from one disk to another
cd sourcedir; tar -cf - . | (cd targetdir; tar -xf -)

# write raw data of kernel image to a floppy
dd if=babylinux.img of=/dev/fd0
cat babylinux.img >/dev/fd0

# set default editor ~/.muttrc
set editor="vi -c ':0;/^$'"

# set bash command line to vi mode
set -o vi

# set vim macros
:map X
:set ww=h,l,b,s
inoremap :w %
noremap :w %
map ^F
set ww=h,l,b,s
colorscheme murphy
noremap :!python %
inoremap ( ()i
inoremap [ []i
inoremap { {}i
inoremap ' ''i
inoremap " ""i
inoremap $_S $_SERVER['']hi
inoremap $_G $_GET['']hi
inoremap $_P $_POST['']hi
inoremap $_R $_REQUEST['']hi
inoremap $_C $_COOKIE['']hi
# change multiline text with the (visually) selected in vim
vlhy:%s??\=getreg('"')?g
# change absolute path to be relatvie w/ vim
%s/(href\=|src\=)\"([^#/(mail|http)])/\1="\2/gc


# start chinese input method IME
export LC_ALL=zh_CN.GB2312
export
chinput &
# change default IME
im-switch -m xim

# start X server
X&
# start X term on display 0
xauth add :0 . `mcookie`
xterm -display :0 &
-ak mail.5117.com

# convert image
convert -draw "image Over 10,20 0,0 logo.gif" 256.gif 256.jpg

# make a mirror of 8617.cn
wget -F --tries=30 -nd -P8617 -E -k -m -p -D

# change the color of command line (add to .bashrc)
PS1="\[\e[33;41m\][\u@devserver \w]\[\e[32;40m\]\[\e[01m\]#\[\e[0m\]"
# also works, but first command line maybe shortened to 70% of the screen width
PS1="\e[33;41m[\u@ \w]\e[32;40m\e[01m#\e[0m"

# pack a whole dir
tar cvfz xx.tar.gz ./* --exclude=dir1 --exclude=dir2
tar cvf - ./* | gzip -qc > back.tgz

# restore mysql db from a dump file
mysql -p < db.dump

# decoding error for chinese in Linux 8.0
export LC_ALL=en_US
export LANG=C

# control vsftpd
/etc/rc.d/init.d/xinetd restart

# a simple editor like WPS driven by hot keys ( ^KH for help)
joe

# Midnight Commander, like Norton Commander in DOS
# hot keys at screen bottom of the (diplayed as 1, 2 etc) stards for F1, F2 etc
mc

# a powerful ftp client, supporting wild cat and download of a whole dir
# anonymous login:
ncftp xxx.xxx.xxx.xxx

# a ftp tool with bash like job control, command completion and more
lftp

# an powerful email client
pine

# get version info of kernel
uname -a
guname # in X

# screenshot for text terminal
cat /dev/vcsX >screenshot # X stands for the no. of terminal (?)
script screen.log  # exit to stop

# run a command immune to hangups, with output to a non-tty
nohup command &

# make the shell a login shell with su
su - root

# print the name of the terminal
fgconsole
tty

# display brief info on a bash built-in command
help command

w
who
rwho -a
whoami
ftpwho

last
lastb

# show the amount of time since the last reboot
uptime

# check what distribution you are using
# (displayed on login, therefore it functions like /etc/motd )
cat /etc/issue

# (mnemonic: disk free) print disk info about all the filesystems
df -h # in human-readable form
# (mnemonic: disk usage) print detailed disk usage
du / -bh | more # for each subdirectory under PWD in human legible form

# show cpu info stored in /proc/cpu
cat /proc/cpuinfo
# list the interrupts in use (maybe useful before setting up new hardware)
cat /proc/interrupts
# Linux version and other info
cat /proc/version
# show the types of filesystems currently in use
cat /proc/filesystems
# show the setup of printers
cat /etc/printcap |more

# show the current user environment (in full)
set|more

# print kernel messages
# (so-called kernel ring buffer in /var/log/dmesg after bootup)
dmesg | less

# display all the configurable Linux kernel parameters.
sysctl -a |more

# lock a local (text mode) terminal.
vlock

# html editor in X ternimal
bluefish

# spell check an ASCII text file
# AbiWord, WordPerfect, StarOffice come with as-you-type spellchecking
aspell
ispell filename

# look up the dictionary on your system (/usr/share/dict/words) for thermo*
look thermo

which
whereis
whatis

# start another X-window session on the display 1 (default opened on display 0)
startx -- :1 &

# receive files using the Zmodem, Ymodem, or Xmodem protocol
rx

unarj e filename.arj
lha e filename.lha
uudecode -o outputfile filename
ar -x my_archive.a file1 file2

# run any command when the system load is low, CTRL-D to end
# (if logout, the process will keep running and the result will be emailed)
batch

# kill programs by name
killall program_name

# check and control the printers (? to see the list of available commands)
lpc
# show the content of the printer queue
lpq
# remove a printing job
lprm job_number

# execute my_command repeatedly at 60-second intervals (default to 2 seconds)
watch -n 60 my_command

linuxconf
netconf # a subset of linuxconf
mouseconf

# automatically determines and configures hardware
# (disable it if having mysterious problems with your mouse)
kudzu

# set the timezone for your system.
# UTC, Coordinated Universal Time, once called GMT, Greenwich Mean Time
# timestamps of files are always in UTC and displayed locally with time zone
timeconfig

# set linux system date and time to 2000-12-31 23:57
date 123123572000
# set your computer hardware clock from the current linux system time
setclock

# list files opened on your system
lsof

# tune up your parallel ports
tunelp

ntsysv
tksysv # X-based
# a tool to check/enable/disable system services
/sbin/chkconfig --level 123456 kudzu off
# to list all the services started/stopped under all runlevels, I use:
chkconfig --list | more
service --status-all
service wu-ftpd start
service smb restart

# check and fix the symbolic links
symlinks -r -cds /

# re-create the bindings and the cache for the loader of dynamic libraries ld
#   usually after an installation (automatically done in bootup)
ldconfig

# (mnemonic: make node) manually create a device file
mknod /dev/fd0 b 2 0
# restore the "audio" device that somehow screwed up
/dev/MAKEDEV audio

# hard drive partitioning utility, menu-based, easier than fdisk
cfdisk /dev/hda

# list the partition tables (including extended partitions) for all drives
sfdisk -l -x |more

# a partition manipulation Linux (ext2), and DOS (FAT and FAT32)
# (creation, destroying, moving, copying, shrinking, and extending)
parted /dev/hda

# perform a low-level formatting of a floppy, high density
# then make a Linux filesystem (-t ext2), checking/marking bad blocks (-c )
# making the filesystem is an equivalent to the high-level formatting
fdformat /dev/fd0H1440 # default 1440 kB, see ls /dev/fd0
mkfs -c -t ext2 /dev/fd0

# check a high-density floppy for bad blocks, does not modify the floppy
badblocks /dev/fd01440 1440
# umount it so that the data is not erased!
umount /dev/hda8
badblocks -n /dev/hda8
# mount back
mount /dev/hda8
# marks badblock
e2fsck -c /dev/hda8

init 1 # switch linux to single user mode, same as below
linux sigle # for grub prompt
# check and repair a filesystem (in runlevel 1)
fsck -t ext2 /dev/hda2

# adjust the tuneable parameter of an ext2 filesystem to ext3
tune2fs -j /dev/hda2

# (mnemonic: data duplicator, like DISKCOPY for DOS)
# create an image of a floppy to floppy_image in pwd
dd if=/dev/fd0H1440 of=floppy_image
# copy floppy_image to another floppy disk
dd if=floppy_image of=/dev/fd0H1440

mkbootdisk --device /dev/fd0 2.4.2-3

userdel user_name
groupadd group_name
chgrp friends my_file
chmod g=rw,o= my_file
usermod
groupmod
userconf

# change the your information as displayed by finger
# (mnemonic: change full name)
chfn

# set the password expiry for login_name (mnemonic: change age)
chage -M 100 login_name

quota username
setquota username
quotaon /dev/hda
quotaoff /dev/hda

# run command with su
sudo /sbin/shutdown -h now

# verify the integrity of the password and group files.
pwck
grpck

rpm -ivh package_name-version.platform.rpm

route -n
host host_to_find
nslookup host_to_find
dig ip_to_find
traceroute host_to_trace
mtr host_to_trace

# status of a networked MS Windows host (with an NetBIOS name
nmblookup -A ip_address # like nbtstat for DOS

echo 1 > /proc/sys/net/ipv4/ip_forward
ipfwadm-wrapper -F -p deny
ipfwadm-wrapper -F -a m -S xxx.xxx.xxx.0/24 -D 0.0.0.0/0
ipchains -L
iptables -L
ifconfig
netstat | more

nmap ip_number

# eject or close other removable media, defaults to cdrom
eject -vn -t /dev/sda4

# read the content of a file for you
festival --tts my_file.txt

# give me a description of an image file my_picture,
#   format, type, class, size in pixels, number of colours, size in bytes, etc
identify -verbose my_picture

# restore a screwed-up terminal to default (remove funny chars after cat)
reset
# reboot

# scroll terminal output up/down


# change to the previous/next X-server resolution
<->
<+>
# kill the window I am going to click

# kill the current X-windows server

# send [End-of-File] to the current process or log out
d
# stop the transfer to the terminal.
s
# resume the transfer to the terminal (when the terminal stops responding)
q
# send the current process to the background.
z
# walk through windows


# walk through desktops


# show the table of processes, kill any or send other signals to them

# access the K-menu, equivalent to MS Windows Start menu

# emulate the mouse using the arrow keys on the keyboard

# drag (any part of) a window to move it

# take a snapshot of the current window into the clipboard

# take a snapshot of the entire desktop into the clipboard

# lock the desktop

# toggle hide/show the desktop
# (great to hide the Solitaire game when your boss walks in)

# kernel level key combinations
# meant for debugging purposes and in an emergency (mostly developers)

# enabled/disabled by setting the relevant kernel variable to 1/0
echo "1" > /proc/sys/kernel/sysrq
# kill all processes, including X, known as Secure Access Key SAK

# send the TERM signal to all running processes except init, exit after confirm

# send KILL signal to all processes except init (powerful than
#   but some process may exit abnormally)

# send the KILL signal to all processes, including init

# run an emergency sync (cache write) on all mounted filesystems
# (to prevent data loss)

# remount all mounted filesystems as read-only (like ,
# but, if successful, fsck won't check all filesystems after reboot)

# turn off keyboard raw mode
# (useful when X session hangs: afterward, )

# reboot immediately without syncing or unmounting your disks

# shut the system off

# dump the current registers and flags to your console


# dump a list of current tasks and their information to your console

# dump memory info to your console

# set the console log level
SysRq>
# display help
# also, any other unsupported

阅读(2031) | 评论(0) | 转发(0) |
0

上一篇:Java -- jvm

下一篇:程序與資源管理

给主人留下些什么吧!~~