我常用的LINUX命令

类别:软件工程 点击:0 评论:0 推荐:

############################################################################
#
#     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 'root'@'localhost' = 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 <BS> X
:set ww=h,l,b,s
inoremap <ESC> <ESC>:w %<CR>
noremap <ESC> :w %<CR>
map <Space> ^F
set ww=h,l,b,s
colorscheme murphy
noremap <F1> :!python %<CR>
inoremap ( ()<ESC>i
inoremap [ []<ESC>i
inoremap { {}<ESC>i
inoremap ' ''<ESC>i
inoremap " ""<ESC>i
inoremap $_S $_SERVER['']<ESC>hi
inoremap $_G $_GET['']<ESC>hi
inoremap $_P $_POST['']<ESC>hi
inoremap $_R $_REQUEST['']<ESC>hi
inoremap $_C $_COOKIE['']<ESC>hi
# change multiline text with the (visually) selected in vim
vlhy:%s?<td\_p\{-}td>?\=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 XMODIFIERS=@im=Chinput
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 &
<Ctr><Alt><F7>

# mount an iso file as virtual cdrom
mount -o iocharset=gb2312
mount -t msdos
mount -t iso9660 -o loop ./my.iso /mnt/iso
# mount and display Unicode file names
mount -t iso9660 -o loop codepage=cp950 iocharset=cp950 ./my.iso /mnt/iso
# mount shared dir over samba
mount.smb //host/sharename /mnt/directory/ -o username=guest,password=xxxxx,fmask=0,dmask=0,rw
mount -t smbfs -o username=guest //hostname/sharefile /path/to

# fetch all mails and do not delete the old ones from a remote mail server
fetchmail -u [email protected] -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 www.8617.cn http://www.8617.cn

# 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
<Ctrl><Alt><Del>
# scroll terminal output up/down
<Shift><PgUp>
<Shift><PgDown>
# change to the previous/next X-server resolution
<Ctrl><Alt><->
<Ctrl><Alt><+>
# kill the window I am going to click
<Ctrl><Alt><Esc>
# kill the current X-windows server
<Ctrl><Alt><BkSpc>
# send [End-of-File] to the current process or log out
<Ctrl>d
# stop the transfer to the terminal.
<Ctrl>s
# resume the transfer to the terminal (when the terminal stops responding)
<Ctrl>q
# send the current process to the background.
<Ctrl>z
# walk through windows
<Alt><Tab>
<Alt><Shift><Tab>
# walk through desktops
<Ctrl><Tab>
<Ctrl><Shift><Tab>
# show the table of processes, kill any or send other signals to them
<Ctrl><Esc>
# access the K-menu, equivalent to MS Windows Start menu
<Alt><F1>
# emulate the mouse using the arrow keys on the keyboard
<Alt><F12>
# drag (any part of) a window to move it
<Alt><LeftMouseButton>
# take a snapshot of the current window into the clipboard
<Alt><PrintScreen>
# take a snapshot of the entire desktop into the clipboard
<Ctrl><Alt><PrintScreen>
# lock the desktop
<Ctrl><Alt><l>
# toggle hide/show the desktop
# (great to hide the Solitaire game when your boss walks in)
<Ctrl><Alt><d>

# kernel level key combinations
# meant for debugging purposes and in an emergency (mostly developers)
<Alt><SysRq><command_key>
# 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
<Alt><SysRq><k>
# send the TERM signal to all running processes except init, exit after confirm
<Alt><SysRq><e>
# send KILL signal to all processes except init (powerful than <Alt><SysRq><e>
#   but some process may exit abnormally)
<Alt><SysRq><i>
# send the KILL signal to all processes, including init
<Alt><SysRq><l>
# run an emergency sync (cache write) on all mounted filesystems
# (to prevent data loss)
<Alt><SysRq><s>
# remount all mounted filesystems as read-only (like <Alt><SysRq><s>,
# but, if successful, fsck won't check all filesystems after reboot)
<Alt><SysRq><u>
# turn off keyboard raw mode
# (useful when X session hangs: afterward, <CTRL><ALT><DEL>)
<Alt><SysRq><r>
# reboot immediately without syncing or unmounting your disks
<Alt><SysRq><b>
# shut the system off
<Alt><SysRq><o>
# dump the current registers and flags to your console
<Alt><SysRq><p>
# dump a list of current tasks and their information to your console
<Alt><SysRq><t>
# dump memory info to your console
<Alt><SysRq><m>
# set the console log level
<Alt>SysRq><digit>
# display help
<Alt><SysRq><h> # also, any other unsupported <Alt><SysRq><key>

本文地址:http://com.8s8s.com/it/it31694.htm