linux基本命令操作(一)
常用系统命令:
[root@localhost ~]# uname //查看内核信息//
Linux
[root@localhost ~]# uname -r //只显示内核版本//
2.6.18-348.el5
[root@localhost ~]# uname -a //显示主机名、内核、硬件平台等全部信息a--all//
Linux localhost.localdomain 2.6.18-348.el5 #1 SMP Wed Nov 28 21:22:00 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# hostname //查看主机的完整名称,包括主机名称、所在域的名称//
localhost.localdomain
[root@localhost ~]# ifconfig //查看主机的IP地址等参数,默认查看所有网卡,也可以指定某一特定的网卡//
eth0 Linkencap:Ethernet HWaddr00:0C:29:BB:9C:DF
inetaddr:192.168.75.133 Bcast:192.168.75.255 Mask:255.255.255.0
inet6addr: fe80::20c:29ff:febb:9cdf/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:954 errors:0 dropped:0 overruns:0 frame:0
TXpackets:127 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:93244 (91.0 KiB) TX bytes:15194(14.8 KiB)
lo Link encap:Local Loopback
inetaddr:127.0.0.1 Mask:255.0.0.0
inet6addr: ::1/128 Scope:Host
UPLOOPBACK RUNNING MTU:16436 Metric:1
……
[root@localhost ~]# ifconfig eth0 //查看某个特定网卡的网络参数,顺序是从0开始//
eth0 Link encap:Ethernet HWaddr 00:0C:29:BB:9C:DF
inetaddr:192.168.75.133 Bcast:192.168.75.255 Mask:255.255.255.0
inet6addr: fe80::20c:29ff:febb:9cdf/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:955 errors:0 dropped:0 overruns:0 frame:0
TXpackets:127 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:93487 (91.2 KiB) TX bytes:15194(14.8 KiB)
[root@localhost ~]# cat /proc/cpuinfo //查看CPU信息//
processor : 0
vendor_id :GenuineIntel
cpu family : 6
model :58
model name : Intel(R) Core(TM)i3-3240 CPU @ 3.40GHz
stepping : 9
cpu MHz :3392.319
cache size :3072 KB
……
[root@localhostmnt]# free-m //查看内存和SWAP相关信息//
total used free shared buffers cached
Mem: 999 959 40 0 79 517
-/+ buffers/cache: 362 637
Swap: 2047 0 2047
[root@localhost ~]# cat /proc/meminfo //查看内存信息//
MemTotal: 1023848 kB
MemFree: 292092 kB
Buffers: 51084 kB
Cached: 412676 kB
SwapCached: 0 kB
Active: 278592 kB
Inactive: 360312 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 1023848 kB
LowFree: 292092 kB
SwapTotal: 2096472 kB
SwapFree: 2096472 kB
......
· cd命令的使用:
[root@localhost /]# cd /etc/pki/CA/private //切换至private目录//
[root@localhost private]# pwd
/etc/pki/CA/private
[root@localhost private]# pwd
/etc/pki/CA/private
[root@localhost private]# cd . //切换,但仍然在当前目录//
[root@localhost private]# pwd //查看当前工作目录//
/etc/pki/CA/private
[root@localhost private]# cd .. //切换至上一级目录//
[root@localhost CA]# pwd
/etc/pki/CA
[root@localhost CA]# cd // 直接默认情况下返回至根目录下的家目录//
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd /etc/pki/CA/private/
[root@localhost private]# pwd
/etc/pki/CA/private
[root@localhost private]# cd ..
[root@localhost CA]# pwd
/etc/pki/CA
[root@localhost CA]# cd ../../ //切换至上两级目录//
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd - //返回上一次的目录,从哪里来回那里去//
/etc/pki/CA
[root@localhost CA]# pwd
/etc/pki/CA
[root@localhost CA]# cd ~ //返回至用户root的家目录//
[root@localhost ~]# ]pwd
bash: ]pwd: command not found
[root@localhost ~]# pwd
/root
· ls命令的使用:
[root@localhost /]# cd /boot/
[root@localhost boot]# pwd
/boot
[root@localhost boot]# ls //列表查看目录内容//
config-2.6.18-348.el5 lost+found vmlinuz-2.6.18-348.el5
grub symvers-2.6.18-348.el5.gz
initrd-2.6.18-348.el5.img System.map-2.6.18-348.el5
[root@localhost boot]# ls -;
ls: -: 没有那个文件或目录
[root@localhost boot]# ls -l //以长格式显示目录内容,会显示文件和目录的属性//
总计 6316
-rw-r--r-- 1 root root 67857 2012-11-29 config-2.6.18-348.el5
drwxr-xr-x 2 root root 1024 2013-07-10 grub
-rw------- 1 root root 2820190 2013-07-23initrd-2.6.18-348.el5.img
drwx------ 2 root root 12288 2013-07-10 lost+found
......
[root@localhost boot]# ls -a //显示“.”和“..”,这就是为什么cd可以切换至本目录和上一级目录的原因,仍然显示隐藏文件<这一点和-A相同>
. initrd-2.6.18-348.el5.img vmlinuz-2.6.18-348.el5
.. lost+found .vmlinuz-2.6.18-348.el5.hmac
config-2.6.18-348.el5 symvers-2.6.18-348.el5.gz
grub System.map-2.6.18-348.el5
[root@localhost boot]# ls -A //显示隐藏文件(以“.”开头的文件)//
config-2.6.18-348.el5 symvers-2.6.18-348.el5.gz
grub System.map-2.6.18-348.el5
initrd-2.6.18-348.el5.img vmlinuz-2.6.18-348.el5
lost+found .vmlinuz-2.6.18-348.el5.hmac
[root@localhost boot]# ls -l
总计 6316
-rw-r--r-- 1 root root 67857 2012-11-29 config-2.6.18-348.el5
drwxr-xr-x 2 root root 1024 2013-07-10 grub
-rw------- 1 root root 2820190 2013-07-23initrd-2.6.18-348.el5.img
drwx------ 2 root root 12288 2013-07-10 lost+found
-rw-r--r-- 1 root root 118626 2012-11-29 symvers-2.6.18-348.el5.gz
-rw-r--r-- 1 root root 1282424 2012-11-29System.map-2.6.18-348.el5
-rw-r--r-- 1 root root 2125660 2012-11-29vmlinuz-2.6.18-348.el5
[root@localhost boot]# ls -lh //提供易读的容量单位//
总计 6.2M
-rw-r--r-- 1 root root 67K 2012-11-29 config-2.6.18-348.el5
drwxr-xr-x 2 root root 1.0K 2013-07-10 grub
-rw------- 1 root root 2.7M 2013-07-23initrd-2.6.18-348.el5.img
drwx------ 2 root root 12K 2013-07-10 lost+found
......
[root@localhost boot]# ls -l -d
drwxr-xr-x 4 root root 1024 2013-07-10 .
[root@localhost boot]# ls -ld //显示目录本身的属性//
drwxr-xr-x 4 root root 1024 2013-07-10 .
[root@localhost boot]# ls -l
总计 6316
-rw-r--r-- 1 root root 67857 2012-11-29 config-2.6.18-348.el5
drwxr-xr-x 2 root root 1024 2013-07-10 grub
-rw------- 1 root root 2820190 2013-07-23initrd-2.6.18-348.el5.img
......
[root@localhost boot]# ls -ld
drwxr-xr-x 4 root root 1024 2013-07-10 .
[root@localhost boot]# ld -ld/boot
ld: cannot find -ld/boot
......
总计 6.2M
-rw-r--r-- 1 root root 67K 2012-11-29 config-2.6.18-348.el5
drwxr-xr-x 2 root root 1.0K 2013-07-10 grub
......
[root@localhost boot]# ls -R //递归显示内容,当前目录下的子目录也同样显示出来//
.:(当前目录)
config-2.6.18-348.el5 lost+found vmlinuz-2.6.18-348.el5
grub symvers-2.6.18-348.el5.gz
initrd-2.6.18-348.el5.img System.map-2.6.18-348.el5
./grub:(该目录下的grub目录)
device.map grub.conf minix_stage1_5 stage2
e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5
fat_stage1_5 jfs_stage1_5 splash.xpm.gz vstafs_stage1_5
ffs_stage1_5 menu.lst stage1 xfs_stage1_5
./lost+found:
[root@localhost boot]# ls -lR //多个选项可以叠用,递归和长格式(包含属性)
.:
总计 6316
-rw-r--r-- 1 root root 67857 2012-11-29 config-2.6.18-348.el5
drwxr-xr-x 2 root root 1024 2013-07-10 grub
-rw------- 1 root root 2820190 2013-07-23initrd-2.6.18-348.el5.img
drwx------ 2 root root 12288 2013-07-10 lost+found
-rw-r--r-- 1 root root 118626 2012-11-29 symvers-2.6.18-348.el5.gz
-rw-r--r-- 1 root root 1282424 2012-11-29System.map-2.6.18-348.el5
-rw-r--r-- 1 root root 2125660 2012-11-29vmlinuz-2.6.18-348.el5
./grub:
总计 235
-rw-r--r-- 1 root root 63 2013-07-10 device.map
-rw-r--r-- 1 root root 7584 2013-07-10 e2fs_stage1_5
-rw-r--r-- 1 root root 7456 2013-07-10 fat_stage1_5
-rw-r--r-- 1 root root 6720 2013-07-10 ffs_stage1_5
-rw------- 1 root root 598 2013-07-10 grub.conf
-rw-r--r-- 1 root root 6720 2013-07-10 iso9660_stage1_5
-rw-r--r-- 1 root root 8224 2013-07-10 jfs_stage1_5
……
./lost+found:
总计 0
· ls命令的匹配字符:
[root@localhost boot]#cd /opt
[root@localhost opt]# ls
rh
[root@localhost opt]# touch file1.txt //创建文本文件file1.txt//
[root@localhost opt]# touch file2.txt
[root@localhost opt]# touch file3.txt
[root@localhost opt]# touch file12.txt
[root@localhost opt]# touch file123.txt
[root@localhost opt]# touch filea.txt fileb.txt filec.txt
[root@localhost opt]# touch fileab.txt
[root@localhost opt]# touch fileabc.txt
[root@localhost opt]# ls
file123.txt file1.txt file3.txt fileab.txt fileb.txt rh
file12.txt file2.txt fileabc.txt filea.txt filec.txt
[root@localhost opt]# ls file* //“*”匹配任意多个字符,即通配符,表示以file开头,无论后面是什么//
file123.txt file1.txt file3.txt fileab.txt fileb.txt
file12.txt file2.txt fileabc.txt filea.txt filec.txt
[root@localhost opt]# ls file?.txt //“?”匹配任意单个字符//
file1.txt file2.txt file3.txt filea.txt fileb.txt filec.txt
[root@localhost opt]# ls file??.txt
file12.txt fileab.txt
[root@localhost opt]# ls file???.txt
file123.txt fileabc.txt
[root@localhost opt]# ls file??.????
ls: file??.????: 没有那个文件或目录
[root@localhost opt]# ls file1.txt
file1.txt
][root@localhost opt]# ls file[a-b].txt //匹配连续多个字符中的一个//
filea.txt fileb.txt
[root@localhost opt]# ls file[a-b][a-c].txt
fileab.txt
[root@localhost opt]# ls file[1-3][a-c].txt
ls: file[1-3][a-c].txt: 没有那个文件或目录
[root@localhost opt]# ls file[1-3][1-3][1-3].txt
file123.txt
[root@localhost opt]# ls file[0-9][0-9].txt
file12.txt
[root@localhost opt]# lsfile{a,ab,12,123,abc,ac}.txt //匹配不连续的多组字符,一一匹配,对应的就罗列出来,没有的会提示没有改文件或目录//
ls: fileac.txt: 没有那个文件或目录
file123.txt file12.txt fileabc.txt fileab.txt filea.txt
[root@localhost opt]# ls file[9-0][2-1].txt //[]顺序必须从小到大,不能反向
ls: file[9-0][2-1].txt: 没有那个文件或目录
[root@localhost opt]# ls file[2-0][2-0].txt
ls: file[2-0][2-0].txt: 没有那个文件或目录
[root@localhost opt]# ls file[0-2][0-2].txt
file12.txt
[root@localhost opt]# ls file??.???
file12.txt fileab.txt
[root@localhost opt]# ls file?????
file1.txt file2.txt file3.txt filea.txt fileb.txt filec.txt
[root@localhost opt]# ls file??.???
file12.txt fileab.txt
本文出自 “点点滴滴” 博客,请务必保留此出处http://9118437.blog.51cto.com/9108437/1530935
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。