CentOS常用命令小结
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>下面,就来介绍这些CentOS常用命令。 <br><br><strong>一:使用CentOS常用命令查看cpu </strong><br><br>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode6" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
more /proc/cpuinfo | grep "model name" <br>
grep "model name" /proc/cpuinfo <br>
# grep "CPU" /proc/cpuinfo <br>
model name : Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz <br>
model name : Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz </div>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如果觉得需要看的更加舒服 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>grep "model name" /proc/cpuinfo | cut -f2 -d: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><strong style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>二:使用CentOS常用命令查看内存 </strong><br>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode7" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
grep MemTotal /proc/meminfo <br>
grep MemTotal /proc/meminfo | cut -f2 -d: <br>
free -m |grep "Mem" | awk '{print $2}' </div>
<p>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>三:使用CentOS常用命令查看cpu是32位还是64位</strong><br>
查看CPU位数(32 or 64)<br>
getconf LONG_BIT</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>四:使用CentOS常用命令查看当前linux的版本</strong><br>
more /etc/redhat-release<br>
cat /etc/redhat-release</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>五:使用CentOS常用命令查看内核版本</strong><br>
uname -r<br>
uname -a</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>六:使用CentOS常用命令查看当前时间</strong><br>
date上面已经介绍如何同步时间了</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>七:使用CentOS常用命令查看硬盘和分区</strong><br>
df -h<br>
fdisk -l<br>
也可以查看分区<br>
du -sh<br>
可以看到全部占用的空间<br>
du /etc -sh<br>
可以看到这个目录的大小</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>八:使用CentOS常用命令查看安装的软件包</strong><br>
查看系统安装的时候装的软件包<br>
cat -n /root/install.log<br>
more /root/install.log | wc -l<br>
查看现在已经安装了那些软件包<br>
rpm -qa<br>
rpm -qa | wc -l<br>
yum list installed | wc -l<br>
不过很奇怪,我通过rpm,和yum这两种方式查询的安装软件包,数量并不一样。没有找到原因。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>九:使用CentOS常用命令查看键盘布局</strong><br>
cat /etc/sysconfig/keyboard<br>
cat /etc/sysconfig/keyboard | grep KEYTABLE | cut -f2 -d=</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>十:使用CentOS常用命令查看selinux情况</strong><br>
sestatus<br>
sestatus | cut -f2 -d:<br>
cat /etc/sysconfig/selinux</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>十一:使用CentOS常用命令查看ip,mac地址</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode8" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
在ifcfg-eth0 文件里你可以看到mac,网关等信息。 <br>
ifconfig <br>
cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR <br>
cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR | cut -f2 -d= <br>
ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6- <br>
ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' <br>
查看网关 <br>
cat /etc/sysconfig/network <br>
查看dns <br>
cat /etc/resolv.conf </div>
<p>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>十二:使用CentOS常用命令查看默认语言</strong><br>
echo $LANG $LANGUAGE<br>
cat /etc/sysconfig/i18n</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>十三:使用CentOS常用命令查看所属时区和是否使用UTC时间</strong><br>
cat /etc/sysconfig/clock</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>十四:使用CentOS常用命令查看主机名</strong><br>
hostname<br>
cat /etc/sysconfig/network<br>
修改主机名就是修改这个文件,同时最好也把host文件也修改。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>十五:使用CentOS常用命令查看开机运行时间</strong><br>
uptime<br>
09:44:45 up 67 days, 23:32, ...<br>
看来刚才确实是网段的问题,我的机器还是67天前开机的。<br>
#系统资源使用情况</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode9" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
vmstat 1 -S m <br>
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ <br>
r b swpd free buff cache si so bi bo in cs us sy id wa st <br>
0 0 0 233 199 778 0 0 4 25 1 1 3 0 96 0 0 <br>
0 0 0 233 199 778 0 0 0 0 1029 856 13 1 86 0 0 </div>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>在众多的Linux终端命令中,我们应该分类来介绍一下,这里先说文件目录类、驱动挂载类、程序安装类、压缩解压类、进程控制类,这里所有的 Linux终端命令都会被经常的使用到,熟悉这些命令工作中应该能轻松许多。</span></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>一、文件目录类</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
1.建立目录:mkdir 目录名<br>
2.删除空目录:rmdir 目录名<br>
3.无条件删除子目录: rm -rf 目录名<br>
4.改变当前目录:cd 目录名 (进入用户home目录:cd ~;进入上一级目录:cd -)<br>
5.查看自己所在目录:pwd<br>
6.查看当前目录大小:du<br>
7.显示目录文件列表:ls -l (-a:增加显示隐含目录)<br>
其中:蓝:目录;绿:可执行文件;红:压缩文件;浅蓝:链接文件;灰:其他文件;红底白字:错误的链接文件<br>
8.浏览文件:more 文件名.txt;less 文件名.txt<br>
9.复制文件: cp 源文件 目标文件 (-r:包含目录)<br>
10.查找文件:(1)find (2)locate 命令名<br>
11.链接:(1)建立hard链接:ln 来源文件 链接文件(-d:创建目录链接);(2)建立符号链接:ln -s 来源文件 链接文件</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>二.驱动挂载类</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
1.检查硬盘使用情况:df -T -h<br>
2.检查磁盘分区:fdisk -l<br>
3.挂载软硬光区:mount -t /dev/fdx|hdax /mnt/目录名<br>
其中::modos--FAT16;vfat--FAT32;ntfs--NTFS;光驱--iso9660<br>
支持中文名:mount -o iocharset=x /dev/hdax /mnt/目录名(其中:x=cp936或<br>
挂载光驱:mount -t auto /dev/cdrom /mnt/cdrom<br>
挂载ISO文件:mount -t iso9660 -o loop xxx.iso /path<br>
4.解除挂载:umount /mnt/目录名<br>
解除所有挂载:umount -a<br>
5.建立文件系统:mkfs -t /dev/hdxx。其中:ftype:ext2、ext3、swap等</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>三.程序安装类</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
1.RPM包安装:(1)安装 rpm -ivh somesoft.rpm<br>
(2)反安装(卸载) rpm -e somefost.rpm<br>
(3)查询 rpm -q somefost 或 rpm -qpi somefost.rpm(其中:p未安装;i包含的信息)<br>
(4)查询安装后位置:rpm -ql somefost.rpm<br>
(5)升级安装:rpm -Uvh somesoft.rpm<br>
(6)强制安装:rpm -ivh --nodeps somesoft.rpm 或 rpm -ivh --nodeps --force somesoft.rpm<br>
2.源代码包安装:<br>
查阅README<br>
基本用法 <br>
(1)配置:解压目录下 ./configure<br>
(2)编译:解压目录下 make<br>
(3)安装:解压目录下 make install</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
3.src.rpm的安装</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>四.压缩解压类</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
tar命令:tar [-cxtzjvfpPN] 文件与目录 ….<br>
tar命令参数:<br>
-c :建立一个压缩文件的参数指令(create 的意思);<br>
-x :解开一个压缩文件的参数指令!<br>
-t :查看 tarfile 里面的文件!<br>
特别注意,在参数的下达中, c/x/t 仅能存在一个!不可同时存在!<br>
因为不可能同时压缩与解压缩。<br>
-z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?<br>
-j :是否同时具有 bzip2 的属性?亦即是否需要用 bzip2 压缩?<br>
-v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!<br>
-f :使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!<br>
例如使用『 tar -zcvfP tfile sfile』就是错误的写法,要写成<br>
『 tar -zcvPf tfile sfile』才对喔!<br>
-p :使用原文件的原来属性(属性不会依据使用者而变)<br>
-P :可以使用绝对路径来压缩!<br>
-N :比后面接的日期(yyyy/mm/dd)还要新的才会被打包进新建的文件中!<br>
–exclude FILE:在压缩的过程中,不要将 FILE 打包!</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
范例:<br>
范例一:将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar<br>
# tar -cvf /tmp/etc.tar /etc<==仅打包,不压缩! tar -cvf 目标文件 源文件 (以下同)例如:tar -cvf a.txt.tar a.txt<br>
# tar -zcvf /tmp/etc.tar.gz /etc<==打包后,以 gzip 压缩<br>
# tar -jcvf /tmp/etc.tar.bz2 /etc<==打包后,以 bzip2 压缩<br>
# 特别注意,在参数 f 之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。<br>
# 如果加 z 参数,则以 .tar.gz 或 .tgz 来代表 gzip 压缩过的 tar file ~<br>
# 如果加 j 参数,则以 .tar.bz2 来作为附档名啊~<br>
# 上述指令在执行的时候,会显示一个警告讯息:<br>
# 『tar: Removing leading `/” from member names』那是关於绝对路径的特殊设定。<br>
<br>
范例二:查阅上述 /tmp/etc.tar.gz 文件内有哪些文件?<br>
# tar -ztvf /tmp/etc.tar.gz<br>
# 由於我们使用 gzip 压缩,所以要查阅该 tar file 内的文件时,<br>
# 就得要加上 z 这个参数了!这很重要的!<br>
<br>
范例三:将 /tmp/etc.tar.gz 文件解压缩在 /usr/local/src 底下<br>
# cd /usr/local/src<br>
# tar -zxvf /tmp/etc.tar.gz<br>
# 在预设的情况下,我们可以将压缩档在任何地方解开的!以这个范例来说,<br>
# 我先将工作目录变换到 /usr/local/src 底下,并且解开 /tmp/etc.tar.gz ,<br>
# 则解开的目录会在 /usr/local/src/etc 呢!另外,如果您进入 /usr/local/src/etc<br>
# 则会发现,该目录下的文件属性与 /etc/ 可能会有所不同喔!<br>
<br>
范例四:在 /tmp 底下,我只想要将 /tmp/etc.tar.gz 内的 etc/passwd 解开而已<br>
# cd /tmp<br>
# tar -zxvf /tmp/etc.tar.gz etc/passwd<br>
# 我可以透过 tar -ztvf 来查阅 tarfile 内的文件名称,如果单只要一个文件,<br>
# 就可以透过这个方式来下达!注意到! etc.tar.gz 内的根目录 / 是被拿掉了!<br>
<br>
范例五:将 /etc/ 内的所有文件备份下来,并且保存其权限!<br>
# tar -zxvpf /tmp/etc.tar.gz /etc<br>
# 这个 -p 的属性是很重要的,尤其是当您要保留原本文件的属性时!<br>
<br>
范例六:在 /home 当中,比 2005/06/01 新的文件才备份<br>
# tar -N “2005/06/01″ -zcvf home.tar.gz /home<br>
<br>
范例七:我要备份 /home, /etc ,但不要 /home/dmtsai<br>
# tar –exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc<br>
<br>
范例八:将 /etc/ 打包后直接解开在 /tmp 底下,而不产生文件!<br>
# cd /tmp<br>
# tar -cvf - /etc | tar -xvf -<br>
# 这个动作有点像是 cp -r /etc /tmp 啦~依旧是有其有用途的!<br>
# 要注意的地方在於输出档变成 - 而输入档也变成 - ,又有一个 | 存在~<br>
# 这分别代表 standard output, standard input 与管线命令啦!<br>
<br><strong>五.进程控制类</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
1.列出当前进程ID:ps -auxw<br>
2.终止进程:(1)终止单一进程:kill 进程ID号<br>
(2)终止该程序所有进程:Killall 程序名<br>
(3)终止X-Window程序:xkill<br>
3.查看资源占用情况:(1)top (2)free (3)dmesg<br>
4.查看环境变量值:env<br>
5.重启:(1)reboot (2)Ctrl Alt Del (3)init 6<br>
6.关机:(1)shutdown -h now (2)halt (3)init 0<br>
7.切换桌面:switchdesk gnome|KDE|...</p>
頁:
[1]