Linux Shell:Linux系统信息查看命令大全

系统

# uname -a # 查看内核/操作系统/CPU信息# head -n 1 /etc/issue # 查看操作系统版本# cat /proc/cpuinfo # 查看CPU信息# hostname # 查看计算机名# lspci -tv # 列出所有PCI设备# lsusb -tv # 列出所有USB设备# lsmod # 列出加载的内核模块# env # 查看环境变量

资源

# free -m # 查看内存使用量和交换区使用量# df -h # 查看各分区使用情况# du -sh <目录名> # 查看指定目录的大小# grep MemTotal /proc/meminfo # 查看内存总量# grep MemFree /proc/meminfo # 查看空闲内存量# uptime # 查看系统运行时间、用户数、负载# cat /proc/loadavg # 查看系统负载

磁盘和分区

# mount | column -t # 查看挂接的分区状态# fdisk -l # 查看所有分区# swapon -s # 查看所有交换分区# hdparm -i /dev/hda # 查看磁盘参数(仅适用于IDE设备)# dmesg | grep IDE # 查看启动时IDE设备检测状况

网络

# ifconfig # 查看所有网络接口的属性# iptables -L # 查看防火墙设置# route -n # 查看路由表# netstat -lntp # 查看所有监听端口# netstat -antp # 查看所有已经建立的连接# netstat -s # 查看网络统计信息

进程

# ps -ef # 查看所有进程# top # 实时显示进程状态

用户

# w # 查看活动用户# id <用户名> # 查看指定用户信息# last # 查看用户登录日志# cut -d: -f1 /etc/passwd # 查看系统所有用户# cut -d: -f1 /etc/group # 查看系统所有组# crontab -l # 查看当前用户的计划任务

服务

# chkconfig –list # 列出所有系统服务# chkconfig –list | grep on # 列出所有启动的系统服务

程序

# rpm -qa # 查看所有安装的软件包

linux常见命令的列表系统命令

apropos whatis 显示和word相关的命令。 参见线程安全man -t man | ps2pdf – > man.pdf 生成一个PDF格式的帮助文件which command 显示命令的完整路径名time command 计算命令运行的时间time cat 开始计时. Ctrl-d停止。参见swnice info 运行一个低优先级命令(这里是info)renice 19 -p $$ 使脚本运行于低优先级。用于非交互任务。

目录操作

cd – 回到前一目录cd 回到用户目录(cd dir && command) 进入目录dir,执行命令command然后回到当前目录pushd . 将当前目录压入栈,以后你可以使用popd回到此目录

文件搜索

alias l=’ls -l –color=auto’ 单字符文件列表命令ls -lrt 按日期显示文件. 参见newestls /usr/bin | pr -T9 -W$COLUMNS 在当前终端宽度上打印9列输出find -name ‘*.[ch]’ | xargs grep -E ‘expr’ 在当前目录及其子目录下所有.c和.h文件中寻找’expr’. 参见findrepofind -type f -print0 | xargs -r0 grep -F ‘example’ 在当前目录及其子目录中的常规文件中查找字符串’example’find -maxdepth 1 -type f | xargs grep -F ‘example’ 在当前目录下查找字符串’example’find -maxdepth 1 -type d | while read dir; do echo $dir; echo cmd2; done 对每一个找到的文件执行多个命令(使用while循环)find -type f ! -perm -444 寻找所有不可读的文件(对网站有用)find -type d ! -perm -111 寻找不可访问的目录(对网站有用)locate -r ‘file[^/]*\.txt’ 使用locate 查找所有符合*file*.txt的文件look reference 在(有序)字典中快速查找grep –color reference /usr/share/dict/words 使字典中匹配的正则表达式高亮

归档 and compression

gpg -c file 文件加密gpg file.gpg 文件解密tar -c dir/ | bzip2 > dir.tar.bz2 将目录dir/压缩打包bzip2 -dc dir.tar.bz2 | tar -x 展开压缩包 (对tar.gz文件使用gzip而不是bzip2)tar -c dir/ | gzip | gpg -c | ssh user@remote ‘dd of=dir.tar.gz.gpg’ 目录dir/压缩打包并放到远程机器上find dir/ -name ‘*.txt’ | tar -c –files-from=- | bzip2 > dir_txt.tar.bz2 将目录dir/及其子目录下所有.txt文件打包find dir/ -name ‘*.txt’ | xargs cp -a –target-directory=dir_txt/ –parents 将目录dir/及其子目录下所有.txt按照目录结构拷贝到dir_txt/( tar -c /dir/to/copy ) | ( cd /where/to/ && tar -x -p ) 拷贝目录copy/到目录/where/to/并保持文件属性( cd /dir/to/copy && tar -c . ) | ( cd /where/to/ && tar -x -p ) 拷贝目录copy/下的所有文件到目录/where/to/并保持文件属性( tar -c /dir/to/copy ) | ssh -C user@remote ‘cd /where/to/ && tar -x -p’ 拷贝目录copy/到远程目录/where/to/并保持文件属性dd bs=1M if=/dev/sda | gzip | ssh user@remote ‘dd of=sda.gz’ 将整个硬盘备份到远程机器上

rsync (使用 –dry-run选项进行测试)

rsync -P rsync://rsync.server.com/path/to/file file 只获取diffs.当下载有问题时可以作多次rsync –bwlimit=1000 fromfile tofile 有速度限制的本地拷贝,对I/O有利rsync -az -e ssh –delete ~/public_html/ remote.com:’~/public_html’ 镜像网站(使用压缩和加密)rsync -auz -e ssh remote:/dir/ . && rsync -auz -e ssh . remote:/dir/ 同步当前目录和远程目录

ssh (安全 Shell)

ssh $USER@$HOST command 在$Host主机上以$User用户运行命令(默认命令为Shell)ssh -f -Y $USER@$HOSTNAME xeyes 在名为$HOSTNAME的主机上以$USER用户运行GUI命令scp -p -r $USER@$HOST: file dir/ 拷贝到$HOST主机$USER’用户的目录下ssh -g -L 8080:localhost:80 root@$HOST 由本地主机的8080端口转发到$HOST主机的80端口ssh -R 1434:imap:143 root@$HOST 由主机的1434端口转发到imap的143端口

wget (多用途下载工具)

(cd cmdline && wget -nd -pHEKk ) 在当前目录中下载指定网页及其相关的文件使其可完全浏览wget -c 继续上次未完的下载wget -r -nd -np -l1 -A ‘*.jpg’ 批量下载文件到当前目录中wget ftp://remote/file[1-9].iso/ 下载FTP站上的整个目录wget -q -O- | grep ‘a href’ | head 直接处理输出echo ‘wget url’ | at 01:00 在下午一点钟下载指定文件到当前目录wget –limit-rate=20k url 限制下载速度(这里限制到20KB/s)wget -nv –spider –force-html -i bookmarks.html 检查文件中的链接是否存在wget –mirror 更新网站的本地拷贝(可以方便地用于cron)

网络(ifconfig, route, mii-tool, nslookup 命令皆已过时)因为你的喜爱会挡也挡不住地流露出来。

Linux Shell:Linux系统信息查看命令大全

相关文章:

你感兴趣的文章:

标签云: