查看linux系统信息
arch
uname -m
uname -r
dmidecode -q
hdparm -i /dev/hda
hdparm -tT /dev/sda
cat /proc/cpuinfo
cat /proc/interrupts
cat /proc/meminfo
cat /proc/swaps
cat /proc/version
cat /proc/net/dev
cat /proc/mounts
lspci -tv
lsusb -tv
date 显示系统日期
cal 2007
date 041217002007.00
clock -w
关机 (关机、重启、登出 )
shutdown -h now
init 0
telinit 0
shutdown -h hours:minutes &
shutdown -c
shutdown -r now
reboot
logout
文件和目录
cd /home
cd ..
cd .. /..
cd
cd ~user1
cd -
pwd
ls
ls -F
ls -l
ls -a
ls *[ 0-9] *
tree
lstree
mkdir dir1
mkdir dir1 dir2
mkdir -p /tmp/dir1/dir2
rm -f file1
rmdir dir1
rm -rf dir1
rm -rf dir1 dir2
mv dir1 new_dir
cp file1 file2
cp dir/* .
cp -a /tmp/dir1 .
cp -a dir1 dir2
ln -s file1 lnk1
ln file1 lnk1
touch -t 0712250000 file1
file file1 outputs the mime type of the file as text
iconv -l
iconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding.
find . -maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; batch resize files in the current directory and send them to a thumbnails directory ( requires convert from Imagemagick)
文件搜索
find / -name file1
find / -user user1
find /home/user1 -name \*.bin
find /usr/bin -type f -atime +100
find /usr/bin -type f -mtime -10
find / -name \*.rpm -exec chmod 755 '{}' \;
find / -xdev -name \*.rpm
locate \*.ps
whereis halt
which halt
挂载文件系统
mount /dev/hda2 /mnt/hda2
umount /dev/hda2
fuser -km /mnt/hda2
umount -n /mnt/hda2
mount /dev/fd0 /mnt/floppy
mount /dev/cdrom /mnt/cdrom
mount /dev/hdc /mnt/cdrecorder
mount /dev/hdb /mnt/cdrecorder
mount -o loop file.iso /mnt/cdrom
mount -t vfat /dev/hda5 /mnt/hda5
mount /dev/sda1 /mnt/usbdisk
mount -t smbfs -o username= user,password= pass //WinClient/share /mnt/share
磁盘空间相关
df -h
ls -lSr | more
du -sh dir1
du -sk * | sort -rn
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n
dpkg-query -W -f= '${Installed-Size;10} t${Package} n' | sort -k1,1n
用户和群组
groupadd group_name
groupdel group_name
groupmod -n new_group_name old_group_name
useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1
useradd user1
userdel -r user1
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1
passwd
passwd user1
chage -E 2005-12-31 user1
pwck
grpck
newgrp group_name
文件权限
使用 "+" 设置权限,使用 "-" 用于取消
ls -lh
ls /tmp | pr -T5 -W$COLUMNS
chmod ugo+rwx directory1
chmod go-rwx directory1
chown user1 file1
chown -R user1 directory1
chgrp group1 file1
chown user1:group1 file1
find / -perm -u+s
chmod u+s /bin/file1
chmod u-s /bin/file1
chmod g+s /home/public
chmod g-s /home/public
chmod o+t /home/public
chmod o-t /home/public
文件的特殊属性
- 使用 "+" 设置权限,使用 "-" 用于取消
chattr +a file1
chattr +c file1
chattr +d file1
chattr +i file1
chattr +s file1
chattr +S file1
chattr +u file1
lsattr
打包和压缩文件
bunzip2 file1.bz2
bzip2 file1
gunzip file1.gz
gzip file1
gzip -9 file1
rar a file1.rar test_file
rar a file1.rar file1 file2 dir1
rar x file1.rar
unrar x file1.rar
tar -cvf archive.tar file1
tar -cvf archive.tar file1 file2 dir1
tar -tf archive.tar
tar -xvf archive.tar
tar -xvf archive.tar -C /tmp
tar -cvfj archive.tar.bz2 dir1
tar -jxvf archive.tar.bz2
tar -cvfz archive.tar.gz dir1
tar -zxvf archive.tar.gz
zip file1.zip file1
zip -r file1.zip file1 file2 dir1
unzip file1.zip
YUM(Fedora, RedHat及类似系统)
yum install package_name
yum localinstall package_name.rpm
yum update package_name.rpm
yum update package_name
yum remove package_name
yum list
yum search package_name
yum clean packages
yum clean headers
yum clean all
查看文件内容
cat file1
tac file1
more file1
less file1
head -2 file1
tail -2 file1
tail -f /var/log/messages
文本处理
cat file1 file2 .. . | command < > file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT
cat file1 | command( sed, grep, awk, grep, etc.. .) > result.txt
cat file1 | command( sed, grep, awk, grep, etc.. .) >> result.txt
grep Aug /var/log/messages
grep ^Aug /var/log/messages
grep [ 0-9] /var/log/messages
grep Aug -R /var/log/*
sed 's/stringa1/stringa2/g' example.txt
sed '/^$/d' example.txt
sed '/ *#/d; /^$/d' example.txt
echo 'esempio' | tr '[:lower:]' '[:upper:]'
sed -e '1d' result.txt
sed -n '/stringa1/p'
sed -e 's/ *$//' example.txt
sed -e 's/stringa1//g' example.txt
sed -n '1,5p;5q' example.txt
sed -n '5p;5q' example.txt
sed -e 's/00*/0/g' example.txt
cat -n file1
cat example.txt | awk 'NR%2==1'
echo a b c | awk '{print $1 }'
echo a b c | awk '{print $1 ,$3 }'
paste file1 file2
paste -d '+' file1 file2
sort file1 file2
sort file1 file2 | uniq
sort file1 file2 | uniq -u
sort file1 file2 | uniq -d
comm -1 file1 file2
comm -2 file1 file2
comm -3 file1 file2
字符设置和文件格式转换
dos2unix filedos.txt fileunix.txt
unix2dos fileunix.txt filedos.txt
recode .. HTML < page.txt > page.html
recode -l | more
备份
dump -0aj -f /tmp/home0.bak /home
dump -1aj -f /tmp/home0.bak /home
restore -if /tmp/home0.bak
rsync -rogpav --delete /home /tmp
rsync -rogpav -e ssh --delete /home ip_address:/tmp
rsync -az -e ssh --delete ip_addr:/home/public /home/local
rsync -az -e ssh --delete /home/local ip_addr:/home/public
dd bs= 1M if= /dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz'
dd if= /dev/sda of= /tmp/file1
tar -Puf backup.tar /home/user 执行一次对 '/home/user'
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p'
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p'
tar cf - . | ( cd /tmp/backup ; tar xf - )
find /home/user1 -name '*.txt' | xargs cp -av --target-directory= /home/backup/ --parents
find /var/log -name '*.log' | tar cv --files-from= - | bzip2 > log.tar.bz2
dd if= /dev/hda of= /dev/fd0 bs= 512 count= 1
dd if= /dev/fd0 of= /dev/hda bs= 512 count= 1
网络 - (以太网和WIFI无线)
ifconfig eth0
ifup eth0
ifdown eth0
ifconfig eth0 192.168.1.1 netmask 255.255.255.0
ifconfig eth0 promisc
dhclient eth0
route -n
route add -net 0/0 gw IP_Gateway
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1
route del 0/0 gw IP_gateway
hostname
host www.example.com
nslookup www.example.com
ip link show
mii-tool
ethtool
netstat -tupl
tcpdump tcp port 80