Linux命令集锦
ls –help或man ls查看帮助文件*代表0或多个字符 ?代表1个字符
[gxlinux@localhost ~]$ pwd #显示当前目录路径
/home/gxlinux
[gxlinux@localhost ~]$ date #显示当前时间
2008年 01月 20日 星期日 23:45:27 cst
[gxlinux@localhost ~]$ df -h #显示硬盘信息
文件系统 容量 已用 可用 已用% 挂载点
/dev/hda6 9.8g 2.6g 6.7g 28% /
/dev/hda5 35g 11g 24g 30% /media/windowsd
tmpfs 378m 0 378m 0% /dev/shm
/dev/hda7 9.5g 173m 8.8g 2% /home
[root@localhost gxlinux]# /sbin/fdisk -l #详细显示硬盘信息
disk /dev/hda: 80.0 gb, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
units = cylinders of 16065 * 512 = 8225280 bytes
device boot start end blocks id system
/dev/hda1 * 1 2611 20972826 7 hpfs/ntfs
/dev/hda2 2612 9729 57175335 f w95 ext'd (lba)
/dev/hda5 2612 7073 35840983+ b w95 fat32
/dev/hda6 7074 8387 10554673+ 83 linux
/dev/hda7 8388 9661 10233373+ 83 linux
/dev/hda8 9662 9729 546178+ 82 linux swap / solaris
[gxlinux@localhost ~]$ du -h 11.jpg #查看文件大小
132k 11.jpg
[gxlinux@localhost ~]$ uname -a #查看系统信息
linux localhost.localdomain 2.6.18-1.2798.fc6 #1 smp mon oct 16 14:37:32 edt 2006 i686 i686 i386 gnu/linux
[gxlinux@localhost ~]$ man ls #查看ls的帮助文件,下同
[gxlinux@localhost ~]$ ls –help
[gxlinux@localhost ~]$ mkdir new #创建文件夹
[gxlinux@localhost ~]$ rm -r new #删除文件夹
[gxlinux@localhost ~]$ touch new #创建新文件
[gxlinux@localhost ~]$ rm -i new #提示删除文件
rm:是否删除 一般空文件 “new”? y
[gxlinux@localhost ~]$ ls #查看当前目录下的文件及文件夹
11.jpg desktop stadick 命令.odt 挂载.odt
[gxlinux@localhost ~]$ ls -a #查看目录下全部文件及文件夹
. desktop .gtkrc-1.2-gnome2 .redhat
.. .dmrc .iceauthority .scim
11.jpg .eggcups .lesshst stadick
.adobe .esd_auth .macromedia .thumbnails
.bash_history .gconf .metacity .trash
.bash_logout .gconfd .mozilla .wapi
.bash_profile .gnome .nautilus .wine
.bashrc .gnome2 . .xsession-errors
.beagle .gnome2_private .purple 命令.odt
.chewing .gstreamer-0.10 .recently-used 挂载.odt
.config .gtk-bookmarks .recently-used.xbel
[gxlinux@localhost ~]$ ls -l #查看文件权限
总计 176
-rw-r--r-- 1 gxlinux gxlinux 126927 01-20 23:43 11.jpg
drwxr-xr-x 2 gxlinux gxlinux 4096 01-20 22:09 desktop
drwxr-xr-x 2 gxlinux gxlinux 4096 01-20 22:37 stadick
-rw------- 1 gxlinux gxlinux 8143 01-20 23:50 命令.odt
-rw-r--r-- 1 gxlinux gxlinux 9433 01-20 23:49 挂载.odt
[gxlinux@localhost ~]$ ls -1 #分行查看
11.jpg
desktop
stadick
命令.odt
挂载.odt
[gxlinux@localhost ~]$ clear #清空屏幕
[gxlinux@localhost ~]$ cp 11.jpg stadick #将文件复制到目录下
[gxlinux@localhost ~]$ ls stadick
11.jpg
[gxlinux@localhost ~]$ mv 11.jpg 22.jpg #将文件改名
[gxlinux@localhost ~]$ ls
22.jpg desktop stadick 命令.odt 挂载.odt
[gxlinux@localhost ~]$ mv 22.jpg stadick #移动文件到目录下
[gxlinux@localhost ~]$ ls
desktop stadick 命令.odt 挂载.odt
[gxlinux@localhost ~]$ ls stadick
11.jpg 22.jpg
[gxlinux@localhost ~]$ cat>new.txt #创建文件,输入完毕回车,ctrl+d退出
gxlinux
[gxlinux@localhost ~]$ cat new.txt #查看文件内容
gxlinux
[gxlinux@localhost ~]$ cat new.txt>new2.txt #新建文件,将前一个文件内容写入新文件中
[gxlinux@localhost ~]$ cat new2.txt
gxlinux
[gxlinux@localhost ~]$ cat new.txt>>new2.txt #将前一个文件内容附加到后一个文件当中
[gxlinux@localhost ~]$ cat new2.txt
gxlinux
gxlinux
[gxlinux@localhost ~]$ cat new2.txt -n #分行查看
1 gxlinux
2 gxlinux
[gxlinux@localhost ~]$ w #查看当前在线用户,下同
^[[3~ 00:04:59 up 34 min, 2 users, load average: 0.02, 0.11, 0.26
user tty from login@ idle jcpu pcpu what
gxlinux pts/1 :0.0 23:44 0.00s 0.18s 0.02s w
gxlinux pts/2 :0.0 23:46 17.00s 0.19s 0.19s bash
[gxlinux@localhost ~]$ who
gxlinux pts/1 2008-01-20 23:44 (:0.0)
gxlinux pts/2 2008-01-20 23:46 (:0.0)
[gxlinux@localhost ~]$ finger
login name tty idle login time office office phone
gxlinux gxlinux pts/1 jan 20 23:44 (:0.0)
gxlinux gxlinux pts/2 jan 20 23:46 (:0.0)
[gxlinux@localhost ~]$ ls -l new.txt #查看该文件的权限
-rwxrw---- 1 root gxlinux 8 01-20 23:59 new.txt
[gxlinux@localhost ~]$ chmod u-x,g-w,o+r new.txt #改变权限(仔细查看一下变化)
chmod: 更改 “new.txt” 的权限: 不允许的操作
[gxlinux@localhost ~]$ su #切换用户到root
口令:
[root@localhost gxlinux]# chmod u-x,g-w,o+r new.txt #u用户g组员o其它
[root@localhost gxlinux]# ls -l new.txt
-rw-r--r-- 1 root gxlinux 8 01-20 23:59 new.txt
[root@localhost gxlinux]# chown gxlinux new.txt #改变所有者
[root@localhost gxlinux]# ls -l new.txt
-rw-r--r-- 1 gxlinux gxlinux 8 01-20 23:59 new.txt
[root@localhost gxlinux]# chown -r gxlinux /usr/java #同时改变子目录的权限
[root@localhost usr]# chmod a+s java
[root@localhost gxlinux]# su gxlinux #切换用户到
[gxlinux@localhost ~]$
[gxlinux@localhost ~]$ cal 9 1752 #查看某年某月
九月 1752
日 一 二 三 四 五 六
1 2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
[gxlinux@localhost ~]$ sleep 10;echo "hello" #休息10秒,然后输出文字;单行多条命令
hello
[gxlinux@localhost ~]$ cat > old.txt
gxlinux linux
linus you
[gxlinux@localhost ~]$ wc old.txt #查看 行数/单词数/字符数
2 4 24 old.txt
[gxlinux@localhost ~]$ bc #一个简单计算器
bc 1.06
copyright 1991-1994, 1997, 1998, 2000 free software foundation, inc.
this is free software with absolutely no warranty.
for details type `warranty'.
3+4-2
5
3*4/2
6
quit
[gxlinux@localhost zip]$ date
2008年 01月 21日 星期一 16:03:21 cst
[gxlinux@localhost zip]$ at 1605 #在指定时间内执行任务
at> echo "hello"
at> <eot>
job 1 at 2008-01-21 16:05
[gxlinux@localhost zip]$ atq #查看当前任务
1 2008-01-21 16:05 a gxlinux
[gxlinux@localhost zip]$ mail #任务执行完毕,会提示你
mail version 8.1 6/6/93. type ? for help.
"/var/spool/mail/gxlinux": 1 message 1 new
[gxlinux@localhost zip]$ at 1610
at> echo "hello"
at> <eot>
job 2 at 2008-01-21 16:10
[gxlinux@localhost zip]$ atq
2 2008-01-21 16:10 a gxlinux
[gxlinux@localhost zip]$ atrm 2 #取消任务
[gxlinux@localhost zip]$ atq
[gxlinux@localhost zip]$ cat>cmd #写一个可执行文件来执行
echo "hello"
[gxlinux@localhost zip]$ at -f cmd 1610 mon +0 week
job 3 at 2008-01-28 16:10
[gxlinux@localhost zip]$ at -f cmd 1610 thu +1 week #一周后的周四执行命令
job 4 at 2008-01-31 16:10
[gxlinux@localhost zip]$ ls
zip1 zip2 zip3 zip4 zip.txt
[gxlinux@localhost zip]$ tar -cvf zip.tar * #将目录下所有文件打包
zip1
zip2
zip3
zip4
zip.txt
[gxlinux@localhost zip]$ touch zip1.txt
[gxlinux@localhost zip]$ tar -rvf zip.tar zip1.txt #将该文件加入到包文件中
zip1.txt
[gxlinux@localhost zip]$ ls
zip.tar
[gxlinux@localhost zip]$ tar -xvf zip.tar #解压缩包文件
zip1
zip2
zip3
zip4
zip.txt
zip1.txt
[gxlinux@localhost subzip]$ zip -m zip4.zip zip4 #将文件打包,并删除原文件
adding: zip4 (stored 0%)
[gxlinux@localhost zip]$ zip -j zip.zip * #忽略子目录
adding: zip1 (deflated 93%)
adding: zip1.txt (stored 0%)
adding: zip1.zip (stored 0%)
adding: zip2 (deflated 97%)
adding: zip3 (deflated 91%)
adding: zip.tar (deflated 98%)
adding: zip.txt (deflated 69%)
[gxlinux@localhost zip]$ zip -r zip.zip * #将子目录也打包
updating: zip1 (deflated 93%)
updating: zip1.txt (stored 0%)
updating: zip1.zip (stored 0%)
updating: zip2 (deflated 97%)
updating: zip3 (deflated 91%)
updating: zip.tar (deflated 98%)
updating: zip.txt (deflated 69%)
adding: subzip/ (stored 0%)
adding: subzip/zip4.zip (stored 0%)
[gxlinux@localhost zip]$ zip -9 lv.zip * #数字越大,压缩率大
[gxlinux@localhost zip]$ zip -@ ziptxt.zip #打包多个文件
zip.txt
zip1.txt
adding: zip.txt (deflated 69%)
adding: zip1.txt (deflated 77%)