LINUX基础命令注释_linux命令行注释
LINUX基础命令注释由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“linux命令行注释”。
第一章 基础命令
[root@CCIE /]# adduser
增加一个系统用户 useradd 与 adduser 是一样的命令,都是增加一个用户。[root@CCIE /]# useradd ccna [root@CCIE /]# adduser ccnp
当前用户,主机名,当前目录。超级用户为#,一般用户为$ [root@CCIE ~]# 当前账户路径。~表示用户 home 目录.root 的 home 为/root
增加一个用户 ccne 并将其增加到 root 组中。注意-g 是将一个用户放到什么组中。[root@CCIE /]# useradd-g root ccne [root@CCIE home]# ls-l 总计 16 drwx------3 ccie ccie 4096 08-20 00:01 ccie drwx------3 ccna ccna 4096 08-20 16:22 ccna drwx------3 ccne root 4096 08-20 16:23 ccne drwx------3 ccnp ccnp 4096 08-20 16:22 ccnp
增加一个系统用户 ccie 注意-r [root@CCIE /]# useradd-r ccie
增加一个系统用户 aa 并批定目录为/home/aa [root@CCIE /]# useradd-d /home/aa aa
更改删除用户
[root@CCIE ~]# userdel 用户名
记录用户密码
[root@CCIE ~]# more /etc/pawd
默认密码存放在[root@CCIE ~]# vi /etc/shadow
组管理
[root@CCIE ~]# vi /etc/group arpm 电源管理 笔记本没有用电池
[root@CCIE /]# apm No APM support in kernel
指定,选项和参用空格格开 [root@CCIE /]# ls-l |le
许多选项前加--[root@CCIE /]# ls--help Man 的数字 1 表示用户指令。5 表示文件帮助 [root@CCIE /]# man 1 pawd [root@CCIE /]# man 5 pawd
显示剩余电量
[root@CCIE /]# apm-m
显示当前系统体系结构 [root@CCIE /]# arch i686
将程序放在后台
[root@CCIE home]# bg
切换目录
[root@CCIE home]# cd [root@CCIE ~]# cd..[root@CCIE /]# cd.[root@CCIE /]# cd [root@CCIE ~]#
设置自己的 finger 消息。[root@CCIE ~]# chfn [root@CCIE ~]# chfn Changing finger information for root.Name [chfn]: Office []: Office Phone []: Home Phone []:
Finger information not changed.查看可用的 shell [root@CCIE ~]# chsh-l /bin/sh /bin/bash
/sbin/nologin /bin/tcsh /bin/csh /bin/ksh /bin/zsh
改变当前的 shell [root@CCIE ~]# chsh Changing shell for root.New shell [/bin/bash]:
通过-s 也可以改变当前的 shell [root@CCIE /]# chsh-s /bin/bash Changing shell for root.Shell changed.[root@CCIE /]# chsh Changing shell for root.New shell [/bin/bash]:
创建一个文件 touch [root@CCIE wa]# touch ccie [root@CCIE wa]# ls a b ccie
清除当前的屏幕
[root@CCIE ~]# clear
显示当前的时间
[root@CCIE /]# date 2008 年 08 月 20 日 星期三 17:05:07 CST
显示当前的文字
[root@CCIE /]# echo [root@CCIE /]# echo hello hello
删除一个文件 rm [root@CCIE wa]# rm ccie rm: remove regular empty file `ccie'? y [root@CCIE wa]# ls a b
移动并重命名 mv [root@CCIE wa]# mv ccie ccnp
[root@CCIE wa]# ls a b ccnp
考贝一个文件到另外一文件 cp [root@CCIE ccie]# cp vi /home/ccnp 以/开头是绝对路径,没有/的是相对路径。由实际位置定。Cd 回到 home 目录。Cd..回到根目录。Cd 回到上一级目录。[root@CCIE ~]# cd / [root@CCIE /]# cd [root@CCIE ~]#
执行命令后退出
[root@CCIE ~]# exec [root@CCIE ~]# exec ls
删除一个新的空的目录 rmdir [root@CCIE home]# rmdir ccnp
强制删除一个有文件的文件夹 rm-rf [root@CCIE home]# rm-rf ccnp
退出命令
[root@CCIE ~]# exit
显示系统完整信息
[root@CCIE ~]# uname-a Linux CCIE 2.6.9-5.EL #1 Wed Jan 5 19:22:18 EST 2005 i686 i686 i386 GNU/Linux
显示主机名
[root@CCIE ~]# hostname CCIE
显示主机名地位置
[root@CCIE home]# more /etc/sysconfig/network NETWORKING=yes HOSTNAME=CCIE
更改主机名
[root@CCIE ~]# vi /etc/sysconfig/network
列出执行过的指令 [root@CCIE ~]# fc-l
将后台的任务拉到前台
[root@CCIE /]# fg-bash: fg: current: no such jo
查看虚拟终端的数目 [root@CCIE /]# fgconsole 1 [root@CCIE /]#
Linux 中所有的设备都文件
[root@CCIE dev]# ls-l |le brw-rw----块文件 可以随时读写,硬盘光盘。B 表示
crw-rw----字符文件 比如串口 c 表示。
查看登录用户的消息
[root@CCIE /]# finger-l Login: root Name: chfn Directory: /root Shell: /bin/bash On since Wed Aug 20 16:04(CST)on tty1 1 hour 5 minutes idle On since Wed Aug 20 17:08(CST)on pts/0 from 192.168.1.101 No mail.No Plan.显示指定的用户信息
[root@CCIE /]# finger-m ccie
Login: ccie
Directory: /home/ccie
Never logged in.No mail.No Plan
Name:(nul)
Shell: /bin/bash
显示内存的消息
[root@CCIE /]# free total Mem: 255596-/+ buffers/cache: Swap: 522104
free shared buffers used cached
251476 4120 0 47612 153872 49992 205604
0 522104
以总和的消息显示内存消息 [root@CCIE /]# free-t
total Mem: 255596-/+ buffers/cache: Swap: 522104
used free shared
0
buffers
35784
cached
160576
250064 5532
53704 201892
0 522104
Total: 777700 250064 527636
每 4 秒显示一次
[root@CCIE /]# free-sused free total Mem: 255596 252008 3588-/+ buffers/cache: 60000 195596 Swap: 522104 0 522104
shared
0
buffers
18112
cached
173896 显示信号
[root@CCIE /]# fuser-l HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS UNUSED
Vi 编辑器
Vi 是一个可视化编辑器,也就是说你所做的改动能直接的看到结果。Vi 有两种模式,命令 模式可以删除,查找等 编辑模式主要是用来编辑文件。用esc 退回来命令模式 打开一个文件 vi 文件名
[root@CCIE ccie]# ls a a.tar inittab [root@CCIE ccie]# vi a 命令参数 保存文件 : w 没有改动退出 :q 有改动退出 : wq 保存改动退出 : q!不保存改动退出。:e 文件名,打开别的文件工始编辑。
编辑 命令参数
i 在当前位子进入到编辑模式 I 光标到行首进到入编辑模式 a 光标退后一格进到编辑模式 A 光示退到行尾进到编辑模式
O《小> 在光标所在行新一行进到编辑模式 O 在光标所在行新起上一行进到编辑模式 S 删除光标所在字进到编辑模式 S 删除光标所在行进到编辑模式
删除命令 X 删除一个字 Nx 删除 n 个字 Dd 删除当前行 Dw 删除到尾
剪贴
Yy 光标所在行复制 Yw 光标所在词复制
Nyw 光标所在位后 n 个词复制 P 贴在光标位之右 小 p P 贴在光标位之左 大 p
取消上一个动用 U 取消上一个更新 U 取消所有的更动 Ctrl + r 重新更改 E:!放弃更新重新更改
显示进程
[root@CCIE /]# fuser-a /root /root:
4897c 查看 cpu 信息
[root@CCIE /]# cat /proc/cpuinfo
查看输入输出信
[root@CCIE /]# cat /proc/ioports
查看系统运行时间
[root@CCIE /]# cat /proc/uptime
查看系统信息
[root@CCIE /]# cat /proc/version
查看 scsi 信息
[root@CCIE /]# cat /proc/scsi
查看 ide 信息
[root@CCIE /]# cat /proc/ide
查看网络信息
[root@CCIE /]# cat /proc/net
查看核心系统参数
[root@CCIE /]# cat /proc/sys
系统日志存放在/var/log 查看核心启动日志
[root@CCIE log]# more /var/log/dmesg
查看系统报错日志
[root@CCIE log]# more /var/log/meages
查看邮件日志
[root@CCIE log]# more /var/log/maillog
直接用指令查看 [root@CCIE /]# dmesg
查看 ftp 日志 用于记录 ftp 服务信息 [root@CCIE /]# cat /var/log/xferlog
查看安全信息日志 记录与系统相关的信息 [root@CCIE /]# more /var/log/secure
查看登录日志
[root@CCIE /]# more /var/log/wtmp 杀死与 root 相关的进程
[root@CCIE /]# fuser-k /root /root: 4897c
查看用户的密码文件
[root@CCIE /]# more /etc/pawd [root@CCIE /]# more /etc/pawd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin news:x:9:13:news:/etc/news: uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin gopher:x:13:30:gopher:/var/gopher:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin dbus:x:81:81:System meage bus:/:/sbin/nologin vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin rpm:x:37:37::/var/lib/rpm:/sbin/nologin haldaemon:x:68:68:HALdaemon:/:/sbin/nologin netdump:x:34:34:NetworkCrash Dump user:/var/crash:/bin/bash
解释
Login name 登录用户名 Pawd 密码 Uid 用户编号 Gid 所在组编号 Full name 用户全名
Home directory 用户主目录 Shell 用户默认的 shell
创建一个 ccie 新组
[root@CCIE /]# groupadd ccie
删除一个 ccie 组
[root@CCIE /]# groupdel ccie
重启 需要账户为 root [root@CCIE ~]# reboot [root@CCIE ~]# shutdown-r now [root@CCIE ~]#init 6
关机 需要账户为 root [root@CCIE ~]# halt [root@CCIE ~]# shutdown-h now [root@CCIE ~]# powerofff [root@CCIE ~]# init 0
关闭系统关关闭电源
[root@CCIE ccie]# halt-p
显示历史命令
[root@CCIE ccie]# history 2 624 history 625 history 2
查看文件类型。
[root@CCIE ccie]# file inittab inittab: ASCII English text
文件类型
-一般文件 D 目录文件 B 块设备文件 C 字符文件 L 链接文件 P 人工管道
文件权限
[root@CCIE home]# ls-l total 32 drwx------2 ccie ccie 4096 Sep 7 10:26 ccie 一个文件总共有 10 种权限属性,第一个表文件类型 2-4 表示用户权限 5-7 组权限 8-10 其 它权限。258 字符控制读权限 369 表示写 4710 表示执行权限 D 表示为目录文件
文件权限分为 r w x 读 写 执行权限。用户权限为 文件所有者 u 文件所属组 g 其它用 户 0
改变权限:只有用户本身与 root 才能修改.将一个文件名改成只有用户才有读写执行 chmod u=rwx 文件名
将 ccie 文件改成只有读的权限
[root@CCIE home]# chmod u=r 文件名 ccie [root@CCIE home]# ls-l total 32 dr--rwxrwx 2 ccie ccie 4096 Sep 7 10:26 ccie drwx------2 wa ccie 4096 Aug 31 15:57 dcj drwx------5 ccie hhh 4096 Aug 19 13:26 redhat drwx------2 500 500 4096 Sep 7 09:39 wa
Chmod =rwx 文件名
U 表示用户本身 g 表示组成员 o 表示其它 a 表示所有的。=表示改后的权限 文件名是要
改的文件的名子。
将文件 ccnp 改为用户与组有执行权限 [root@CCIE home]# chmod ug=x ccnp
数字表示权限 4 读 2 写 1 执行
7=4+2+1 表示读写执行 6 读写 5 读执行 3 写执行
将一个文件 ccnp 给用户组其它读写执行权限, [root@CCIE home]# chmod 777 ccnp [root@CCIE home]# ls-l total 36 dr--rwxrwx 2 ccie ccie 4096 Sep 7 10:26 ccie-rwxrwxrwx 1 root root 0 Sep 7 11:27 ccnp
各个位置上没有权限则为 0 [root@CCIE home]# chmod 707 ccnp [root@CCIE home]# ls-l total 36 dr--rwxrwx 2 ccie ccie 4096 Sep 7 10:26 ccie-rwx---rwx 1 root root 0 Sep 7 11:27 ccnp
Chown 用来改变文件拥用者。
将 ccie 这个文件的用户变 ccie 变成 root [root@CCIE home]# ls-l total 36 dr--rwxrwx 2 ccie ccie 4096 Sep 7 10:26 ccie
[root@CCIE home]# chown root ccie [root@CCIE home]# ls-l total 36 dr--rwxrwx 2 root ccie 4096 Sep 7 10:26 ccie
Chgrp 用来改变所属组。
Chgrp 组名 文件名
文件所有者与 root 用户通过命令来改变所属组。[root@CCIE ccie]# ls-l total 8-rw-r--r--1 root root 1666 Sep 7 09:57 inittab
[root@CCIE ccie]# chgrp ccie inittab
[root@CCIE ccie]# ls-l total 8-rw-r--r--1 root ccie 1666 Sep 7 09:57 inittab
文件名规则:一个文件名最多为255 个字符。以点开头为隐藏文件。
目录在文件类型上用 d 表示
/表示根目录。对于每个用户都有一个当前目录。文件与。文件。
。表示当前目录的一个硬连结。
。表示上一级目录的硬连结。
目录权限:
与文件有相同的权限。读:只可以读取目录内内容 写:执行。有向目录中增加删除权限 执行:进入到目录,调用资料。
如果一个目录只有--x 权限,则无法列出目录内容,但是可以执行等程序。
强制位冒险位
强制位:给一般用户有文件所者相同的权限。
冒险位:一般文件中如果有 w x 则所有的用户都有建立与删除文件能力。但是设置冒险位 后只有文件所有,目录所有与管理员才可能删除文件。
U g 0 分别对应:强制位 Set uid 强制位 set gid 和 sticky 冒险位.设置好以后,强制位会 在 u g 位置上用用一个 s 冒险位会采用 t 表示。强制位在用户 u 中表示为 4 set uid.强制位
在组 g 中表示为 2 set gid 冒险位在其它 0 中表示为 1 sticky.[root@CCIE ccie]# chmod 1777 inittab [root@CCIE ccie]# ls-l total 8-rwxrwxrwt 1 root ccie 1666 Sep 7 09:57 inittab [root@CCIE ccie]# chmod 6777 inittab [root@CCIE ccie]# ls-l total 8-rwsrwsrwx 1 root ccie 1666 Sep 7 09:57 inittab [root@CCIE ccie]# chmod 7777 inittab [root@CCIE ccie]# ls-l total 8-rwsrwsrwt 1 root ccie 1666 Sep 7 09:57 inittab
清除历史命令
[root@CCIE ccie]# history-c [root@CCIE ccie]# history 1 history
显示用户的 id 与所属组的 id [root@CCIE ~]# id uid=0(root)gid=0(root)groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)[root@CCIE ~]# id-g 0 [root@CCIE ~]# id-G 0 1 2 3 4 6 10
[root@CCIE ~]# id root
uid=0(root)gid=0(root)groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
查看文件 a 的信息
[root@CCIE ccie]# info a
根目录下文件类型 /bin 常用指令 /usr/bin 常用指令 /boot 核心启动文件 /dev 设备文件
/etc 服务与配置文件 /home 个人文件 /lib 库文件与驱动 /usr/lib 库文件驱动。/lost+found 孤儿文件。/mnt 常用挂载点
/opt 第三方工具使用目录 /proc 系统信息 /root root 目录
/sbin 系统管理指命令 /tmp 临时文件
/usr 与用户有关的目录 /var 可能会改变的数据。
显示进程间的通信状态 [root@CCIE ccie]# ipcs
------Shared Memory Segments--------key shmid owner perms
bytes
nattch status------Semaphore Arrays--------key semid owner perms
nsems------Meage Queues--------key msqid owner perms used-bytes meages
[root@CCIE ccie]# ipcs-m-t
------Shared Memory Attach/Detach/Change Times--------shmid owner attached detached changed 列出所有的后台进程
[root@CCIE ccie]# jobs [root@CCIE ccie]# jobs-l [root@CCIE ccie]# jobs-p
设备文件的使用
Echo hello > /dev/tty2 在第二个 tty 上显示 hello Cp /dev/fd0 /dev/fd1 考第一个软驱到第二个软驱 Dd if=/dev/hda of=/root/mbr bs=512 count=1 备份第一个硬盘上的 mbr Dd 一个强大的拷贝工具 If= 文件名 Of 目标文件名 Bs=xxx 指定块大小
Count=n 指定复制块的数量
输入重定向
用
输出重定向:将输出的结果放到别的文件中
[root@CCIE ccie]# ls-l >a [root@CCIE ccie]# ls a inittab.txt [root@CCIE ccie]# more a total 12-rw-r--r--1 root root 0 Oct 24 21:53 a---x--x---1 ccie ccie 1666 Oct 24 21:30 inittab
[root@CCIE /]# ls-l >/home/ccie/a 意思:将根目录下的显示输出到 /home/ccie/a 这个文件中。
杀死进程
[root@CCIE ccie]# kill 12345
杀死所有的同名进程
[root@CCIE ccie]# killall 1234
查看最后登陆的用户 [root@CCIE ccie]# last
查看最后登陆的主机 ip 地址
[root@CCIE ccie]# last-n 5-a-i root pts/0 Wed Aug 20 17:08
still logged in 192.168.1.101
root root root root pts/0 pts/0 pts/0 pts/0
Wed Aug 20 17:0717:07(00:00)Wed Aug 20 17:0617:06(00:00)
192.168.1.101 192.168.1.101 192.168.1.101 192.168.1.101 wtmp begins Tue Aug 19 23:53:01 2008
查看登陆失败的相关消息 [root@CCIE ccie]# lastb h:notty 192.168.1.102 Wed Aug 20 00:0023:59(00:00)
btmp begins Tue Aug 19 23:59:09 2008
重新登陆
[root@CCIE ~]# login
显示登陆帐号消息
[root@CCIE ~]# logname Root
查看所有的语言支持
[root@localhost ~]# locale-a
将字体变成中文
[root@localhost /]# LANG=zh_CN.gb2312
语言环境默认情况下
[root@localhost /]# ls /etc/sysconfig/i18n
[root@localhost /]# cat /etc/sysconfig/i18n LANG=“zh_CN.UTF-8” SUPPORTED=“zh_CN.UTF-8:zh_CN:zh” SYSFONT=“latarcyrheb-sun16”
修改地址:
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
配置网络另外一个命令
[root@localhost ~]# netconfig ||neat
显示 linux 的内核模块消息 [root@CCIE /]# lsmod
创建一个字体的文件目录
[root@CCIE ccie]# mkfontdir [root@CCIE ccie]# ls a fonts.dir
查看所有的持载
[root@CCIE ccie]# mount-l /dev/hda1 on / type ext3(rw)[/] proc on /proc type proc(rw)sysfs on /sys type sysfs(rw)devpts on /dev/pts type devpts(rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs(rw)none on /proc/sys/fs/binfmt_misctype binfmt_misc(rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs(rw)
将 u 盘挂载到 mnt/u [root@CCIE ccie]# mount /dev/sda1 /mnt/u
将已存在的设备重新挂载
[root@CCIE ccie]# mount--bind /mnt/usb /mnt/usb1
配置各种服务
[root@CCIE ccie]# ntsysv
因为第次启动都会查新硬件将会耗费一定时间,关闭硬件检测。[root@CCIE ~]# chkconfig kudzu off
关闭 sendmail 服务
[root@CCIE ~]# chkconfig sendmail off
关闭防火墙防服
[root@CCIE ~]# chkconfig iptables off
杀死所有的 tty1 下的进程
[root@CCIE etc]# pkill-t tty1
杀死 http 服务
[root@CCIE ~]# killall httpd
显示特定进程的内存消息 [root@CCIE etc]# ps-a PID TTY TIME CMD 27849 pts/0 00:00:00 bash
27862 pts/0 00:00:00 bash 27917 pts/0 00:00:00 ps [root@CCIE etc]# pmap 27849 27849: bash 00227000 104K r-x--/lib/ld-2.5.so 00241000 4K r-x--/lib/ld-2.5.so 00242000 4K rwx--/lib/ld-2.5.so
显示系统状态
[root@CCIE /]# ps
TIME CMD PID TTY 27395 pts/0 27849 pts/0 27862 pts/0 00:00:00 bash 00:00:00 bash 00:00:00 bash 27927 pts/0 00:00:00 ps 显示指定用户的系统进程
[root@CCIE /]# ps-u root
[root@CCIE /]# ps-t tty1 PID TTY TIME CMD 27913 tty1 00:00:00 mingetty
[root@CCIE /]# ps-efww
以树状图型显示 [root@CCIE /]# pstree
[root@CCIE /]# pstree-u
查密码文件
[root@CCIE /]# pwck /etc/pawd 用户 adm:目录 /var/adm 不存在用户 uucp:目录 /var/spool/uucp 不存在 用户 gopher:目录 /var/gopher 不存在 用户 pcap:目录 /var/arpwatch 不存在 用户 sabayon:目录 /home/sabayon 不存在查看工作目录
[root@CCIE /]# pwd / 系统日志
核心起动日志:些日志写在系统每次启动时,包括核心装入时系统所有的输出数据 [root@CCIE ~]# cat /var/log/dmesg
系统报错日志
[root@CCIE ~]# more /var/log/meages 邮件系统日志
[root@CCIE ~]# more /var/log/maillog ftp 服务日志
[root@CCIE ~]# more /var/log/xferlog 安全信息与网络信息日志
[root@CCIE ~]# more /var/log/secure
登录记录
[root@CCIE ~]# more /var/log/wtmp
将进程号为 10 的进程改为优先级为 2 [root@CCIE /]# renice 2-p 10 10: old priority-5, new priority 2
查看模块
[root@CCIE /]# lsmod
删除一个模块
[root@CCIE /]# lsmod-v hid Usage: lsmod [root@CCIE /]#
光盘弹出
[root@localhost /]# eject
收回
[root@localhost /]# eject-t
挂载 ntfs 分区
[root@CCIE ~]# mount-t ntfs /dev/hda1 /mnt/u
结示当前 screen 作业
[root@CCIE /]# screen-ls There is a screen on: 27989.pts-0.CCIE(Attached)1 Socket in /var/run/screen/S-root.系统马上关机
[root@CCIE /]# shutdown-h now
休眠
[root@CCIE /]# sleep 1m
暂停 shell [root@CCIE /]# suspend
强制暂停 shell [root@CCIE /]# suspend-f
显示系统进程
[root@CCIE /]# top [root@CCIE /]# top-c
显示系统信息
[root@CCIE /]# uname Linux
[root@CCIE /]# uname-a Linux CCIE 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:12 EDT 2008 i686 i686 i386 GNU/Linux [root@CCIE /]# uname-m i686 [root@CCIE /]# uname-n CCIE [root@CCIE /]# uname-r 2.6.18-92.el5 [root@CCIE /]# uname-s Linux [root@CCIE /]# uname-v #1 SMP Tue Apr 29 13:16:12 EDT 2008
显示用户
[root@CCIE /]# users root
显示当前的用户
[root@CCIE /]# w 18:36:47 up 2:36, 2 users, load average: 0.22, 0.05, 0.02 FROM USER TTY LOGIN@ IDLE JCPU PCPU WHATroot tty2 33.00s-bash root pts/1 192.168.1.101:S.0.00s w-s
[root@CCIE /]# w-h
18:36 35.00s 0.07s 0.07s-bash root tty2(C)2003 Red Hat, Inc.┌────────────┤ 时区选择 ├─────────
────┐
│ │
│ │ ↑ │ ? │ ? │ ? │ ? │ ? │ ? │ ↓ │ │
│
│ │
┌──────┐ │ ┌──────┐ │
│ │ 确定 │ │ 取消 │ │ │ └──────┘ └──────┘ │ │ │ │ │
└────────────────────────────
─────────┘
│ 为系统选择时区。│
│ Asia/Qyzylorda │ Asia/Rangoon │ Asia/Riyadh │ Asia/Saigon │ Asia/Sakhalin │ Asia/Samarkand │ Asia/Seoul │ Asia/Shanghai │ │ [*] 系统时钟使用 UTC 设置别名 删除别名
[root@CCIE /]# alias aa=ls 将 aa 用来代替 ls 命令
[root@CCIE /]# aa bin dev home lost+found misc net proc sbin srv tftpboot usr boot etc lib media mnt opt root selinux sys tmp var [root@CCIE /]# unalias aa 取消这个命令的代替 [root@CCIE /]# aa-bash: aa: command not found
显示虚拟内存情况
[root@CCIE /]# vmstat procs-----------memory-------------swap-------io------system-------cpu------r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 2 0 0 160084 8856 52696 0 0 84 23 1010 63 1 9 88 显示磁盘信息
[root@CCIE /]# vmstat-d
持续输出字串 good [root@CCIE /]# yes good
显示头部消息 head [root@CCIE ccie ]# ls-l 总计 8-rw-r--r--1 root ccie 1666 08-20 17:43 a-rw-r--r--1 root root 2 08-20 18:03 fonts.dir [root@CCIE ccie]# head a # # inittab This file describes how the INIT proce should set up # the system in a certain run-level.# Miquel van Smoorenburg, # Author: # Modified for RHS Linux by Marc Ewing and Donnie Barnes #
# Default runlevel.The runlevels used by RHS are: # 0halt(Do NOT set initdefault to this)[root@CCIE ccie]#
将 a 文件一页页显示 [root@CCIE ccie]# le a
将 a 文件显示出来
[root@CCIE ccie]# more a
nano 文件编辑器
[root@CCIE ccie]# ls-l 总计 8-rw-r--r--1 root ccie 1666 08-20 17:43 a-rw-r--r--1 root root 2 08-20 18:03 fonts.dir [root@CCIE ccie]# nano a
# System initialization.si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0 l1:1:wait:/etc/rc.d/rc 1 l2:2:wait:/etc/rc.d/rc 2 l3:3:wait:/etc/rc.d/rc 3 l4:4:wait:/etc/rc.d/rc 4 l5:5:wait:/etc/rc.d/rc 5 l6:6:wait:/etc/rc.d/rc 6
^G Get Help Page
^O WriteOut
[ Read 53 lines ]
^R Read File ^Y Prev
^K Cut
Text ^X Exit ^U UnCut
^C Cur Pos
^J Justify
^W Where Is ^V Next Page Text ^T To Spell 可以看到上面的帮助命令。ctrl +x 关闭文件
在 ftp 中,退出 ftp 程试 [root@CCIE ccie]# bye
建立 ftp 连接
[root@CCIE ccie]# ftp 192.168.1.33 开启 vsftpd 服务先查看 vsftpd 安装情况
[root@CCIE ccie]# rpm-q vsftpd vsftpd-2.0.5-12.el5 [root@CCIE ccie]# service vsftpd restart
关闭 vsftpd:
为 vsftpd 启动 vsftpd:
[确定] [确定] [root@CCIE ccie]# ftp 192.168.1.103 Connected to 192.168.1.103.220(vsFTPd 2.0.5)530 Please login with USER and PASS.530 Please login with USER and PASS.KERBEROS_V4 rejected as an authentication type Name(192.168.1.103:root): ccie 注意这里用户名 331 Please specify the paword.Paword: 密码 230 Login succeful.Remote system type is UNIX.Using binary mode to transfer files.ftp> dir 227 Entering Paive Mode(192,168,1,103,191,93)150 Here comes the directory listing.-rw-r--r--1 0 500 1666 Aug 20 09:43 a-rw-r--r--1 0 0 2 Aug 20 10:03 fonts.dir 226 Directory send OK.可以看到没有限制的账号,可以到根目录下,ftp> cd / 250 Directory succefully changed.ftp> ls 227 Entering Paive Mode(192,168,1,103,231,84)150 Here comes the directory listing.drwxr-xr-x 2 0 0 4096 Aug 20 09:14 bin drwxr-xr-x 3 0 0 4096 Aug 19 15:29 boot drwxr-xr-x 11 0 0 3800 Aug 25 02:30 dev drwxr-xr-x 100 0 0 12288 Aug 25 02:33 etc drwxr-xr-x 5 0 0 4096 Aug 21 06:28 home drwxr-xr-x 14 0 0 4096 Aug 20 09:14 lib drwx------2 0 0 16384 Aug 19 15:18 lost+found drwxr-xr-x 2 0 0 4096 Aug 25 02:30 media drwxr-xr-x 2 0 0 0 Aug 25 02:30 misc drwxr-xr-x 2 0 0 4096 Oct 10 2006 mnt drwxr-xr-x 2 0 0 0 Aug 25 02:30 net drwxr-xr-x 2 0 0 4096 Oct 10 2006 opt dr-xr-xr-x 89 0 0 0 Aug 25 02:29 proc drwxr-x---16 0 0 4096 Aug 20 08:56 root drwxr-xr-x 2 0 0 12288 Aug 20 09:14 sbin drwxr-xr-x 2 0 0 4096 Aug 19 15:20 selinux
drwxr-xr-x 2 0 drwxr-xr-x 11 0 drwxr-xr-x 3 0 drwxrwxrwt 7 0
0 drwxr-xr-x 14 0 drwxr-xr-x 25 0 0 226 Directory send OK.0
0 0
0
4096 Oct 10 2006 srv 0 Aug 25 02:29 sys
4096 Aug 19 15:38 tftpboot 4096 Aug 25 02:33 tmp 4096 Aug 19 15:24 usr 4096 Aug 19 15:42 var get 下载文件
ftp> get a local: a remote: a 227 Entering Paive Mode(192,168,1,103,139,45)150 Opening BINARY mode data connection for a(1666 bytes).226 File send OK.put 上传文件
断开连线 ftp> close 221 Goodbye.重新开启连线 ftp> open(to)192.168.1.103 删除文件
ftp> delete a 250 Delete operation succeful.显示文件类行
[root@CCIE ccie]# file a a: ASCII English text
查找 48 小时修改过的文件
[root@CCIE ccie]# find-atime-2../a
显示文件属性
[root@CCIE ccie]# lsattr a-------------a
以 8 进制显示文件内容 [root@CCIE ccie]# od a
显示文件信息
[root@CCIE ccie]# stat a File: “a” Size: 1666 Blocks: 8 IO Block: 4096 一般文件 Device: 301h/769d Inode: 719548 Links: 1 Acce:(0644/-rw-r--r--)Uid: 0/ root)Gid:(0/ root)(Acce: 2008-08-25 11:07:37.000000000 +0800 Modify: 2008-08-25 10:48:***0 +0800 Change: 2008-08-25 10:48:***0 +0800
显示默认的权限
[root@CCIE ccie]# umask 0022
设置文件权限
[root@CCIE ccie]# umask 111 [root@CCIE ccie]# umask 0111
显示当前分区大小
[root@CCIE ccie]# fdisk-l
Disk /dev/hda: 5368 MB, 5368709120 bytes 255 heads, 63 sectors/track, 652 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot /dev/hda1 * /dev/hda2
Star
t587
End 586 651
Blocks Id System 4707013+ 83 Linux
522112+ 82 Linux swap / Solaris 用 fdisk 分区 hdb [root@CCIE ccie]# fdisk /dev/hdb
a 标记分区 d 删除分区 l 列出分区类型 m 帮助信息 n 新建分区 p 列出分区消息 q 退出但不保存 t 设置分区编号 v 进行分区的检测 w 写回硬盘
查看文件系统并尝试修复 [root@CCIE ccie]# fsck fsck 1.39(29-May-2006)e2fsck 1.39(29-May-2006)/dev/hda1 is mounted.WARNING!!Running e2fsck on a mounted filesystem may cause SEVERE filesystem damage.Do you really want to continue(y/n)?
gzexe 压缩可执行文件
[root@CCIE ccie]# gzexe a a: 51.7% [root@CCIE ccie]# ls a a~ fonts.dir [root@CCIE ccie]# ls-l 总计 12-rw-r--r--1 root root 1201 08-25 11:24 a-rw-r--r--1 root root 1666 08-25 10:48 a~-rw-r--r--1 root root 2 08-20 18:03 fonts.dir
向指定机器发送 arp 请求。
[root@CCIE ccie]# arping 192.168.1.99
显示 arp [root@CCIE ccie]# arp
Flags Mask Addre HWtype HWaddre Iface 192.168.1.101 ether 00:03:0D:69:DE:80 C
eth0
ether 00:1D:60:18:46:54 C 192.168.1.99 eth0 192.168.1.1 ether 00:18:39:A5:10:20 C eth0
dns 查讯
[root@CCIE /]# host www.daodoc.com.g.cn.g.cn.280140 IN 280140 IN 280140 IN 280140 IN
NS NS NS NS
ns3.google.com.ns4.google.com.ns2.google.com.ns1.google.com.;;ADDITIONAL SECTION: ns1.google.com.ns2.google.com.ns3.google.com.ns4.google.com.287943 IN
287943 IN 287943 IN 287943 IN
A
A A A 216.239.32.10 216.239.34.10 216.239.36.10 216.239.38.10 Received 191 bytes from 221.12.33.228#53 in 31 ms
查看网络接口
[root@CCIE /]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:53:1F:EA inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe53:1fea/64Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1492 Metric:1 RX packets:258 errors:0 dropped:0 overruns:0 frame:0
TX packets:279 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:24959(24.3 KiB)TX bytes:35381(34.5 KiB)Interrupt:177 Base addre:0x1080
lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:560(560.0 b)TX bytes:560(560.0 b)
ip 转发功能充许服务器将数据从一个子网转到另一个子网。[root@CCIE /]# more /etc/sysctl.conf # Kernel sysctl configuration file for Red Hat Linux #
# For binary values, 0 is disabled, 1 is enabled.See sysctl(8)and # sysctl.conf(5)for more details.# Controls IP packet forwarding net.ipv4.ip_forward = 0
# Controls source route verification net.ipv4.conf.default.rp_filter= 1
# Do not accept source routing net.ipv4.conf.default.accept_source_route= 0
# Controls the System Request debugging functionality of the kernel kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename.# Useful for debugging multi-threaded applications.kernel.core_uses_pid = 1
通过将 net.ipv4.ip forward=1 来开启。
telnet 默认采用 23 号端口通信
[root@CCIE /]# telnet 192.168.168.125
h 采用 22 号端口通信,比 telnet 更安全。[root@CCIE ~]# h 192.168.168.125 root@192.168.168.125'spaword:
关闭网卡
[root@CCIE /]# ifconfig eth0 down
开启网卡
[root@CCIE /]# ifconfig eth0 up
显示防火墙过滤表
[root@CCIE /]# iptables-t filter-L Chain INPUT(policy ACCEPT)target prot opt source destination
Chain FORWARD(policy ACCEPT)target prot opt source
destination Chain OUTPUT(policy ACCEPT)target prot opt source
destination
禁止 ping 自己的地址
[root@CCIE log]# iptables-A INPUT-p icmp-j DROP
显示高级路由表
[root@CCIE /]# iptables-t mangle-L Chain PREROUTING(policy ACCEPT)target prot opt source destination
Chain INPUT(policy ACCEPT)target
prot opt source destination Chain FORWARD(policy ACCEPT)target prot opt source
destination
Chain OUTPUT(policy ACCEPT)target prot opt source
destination Chain POSTROUTING(policy ACCEPT)target prot opt source
destination
显示转发包过滤表
[root@CCIE /]# iptables-t nat-L Chain PREROUTING(policy ACCEPT)target prot opt source
destination Chain POSTROUTING(policy ACCEPT)target prot opt source destination
Chain OUTPUT(policy ACCEPT)target prot opt source destination 关闭防火墙
[root@CCIE ~]# service iptables stop
开启防火墙
[root@CCIE ~]# service iptables restart
设置 input 的规则 与 input 不合的会部丢弃。[root@CCIE ~]# iptables-P INPUT DROP
设置 output 规则。与 output 不合的会部丢弃 [root@CCIE ~]# iptables-P OUTPUT DROP
设置 forward 规则,与 forward 不合的全部丢弃。
[root@CCIE ~]# iptables-P FORWARD DROP
显示防火墙的设置
[root@CCIE ~]# iptables-save # Generated by iptables-save v1.3.5 on Thu Aug 28 11:44:59 2008 *filter :INPUT ACCEPT [143:10453] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [145:14684]-A INPUT-s 192.168.1.100-j ACCEPT COMMIT # Completed on Thu Aug 28 11:44:59 2008
查看防火墙帮助
[root@CCIE log]# iptables--help |more 清空防火墙
[root@CCIE log]# iptables-F Iptables-a 加一个规则-d 删除一个-i 插入-r 替换-f 清空 查看编号
设置一条新规则,接受来自一个地址的一切包。
[root@CCIE ~]# iptables-A INPUT-s 192.168.1.100-j ACCEPT
设置一条新规则,丢弃来自一个地址的一切包。
[root@CCIE /]# iptables-A INPUT-s 192.168.1.100-j DROP
显示 mangle 表的设置
[root@CCIE /]# iptables-t filter iptables v1.3.5: no command specified Try `iptables-h' or 'iptables--help' for more information.[root@CCIE /]# iptables-save-t mangle # Generated by iptables-save v1.3.5 on Thu Aug 28 12:58:51 2008 *mangle :PREROUTING ACCEPT [0:0] :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] COMMIT # Completed on Thu Aug 28 12:58:51 2008
查看端口号
[root@CCIE /]# more /etc/services
显示 nat 表的设置
[root@CCIE /]# iptables-save-t nat # Generated by iptables-save v1.3.5 on Thu Aug 28 12:59:13 2008 *nat :PREROUTING ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] :OUTPUT ACCEPT [0:0] COMMIT # Completed on Thu Aug 28 12:59:13 2008
配置无线网张设备
[root@CCIE /]# iwconfig lo no wirele extensions.eth0 no wirele extensions.sit0 no wirele extensions.控制终端的写入
[root@CCIE /]# mesg is y
网络诊断工具 [root@CCIE /]# mtr
查看到 www.daodoc.com
0.0% 32.4 31.3 27.3 45.5 3.2 202.108.38.14
查看网络状态
[root@CCIE /]# netstat-a
显示网络统计信息
[root@CCIE /]# netstat-s
显示监听的接口
[root@CCIE /]# netstat-l
dns 查找
[root@CCIE /]# nslookup www.daodoc.com 1: 192.168.1.103(192.168.1.103)1: 172.16.12.126(172.16.12.126)2: 172.16.12.254(172.16.12.254)3: 172.16.1.1(172.16.1.1)4: 221.12.26.33(221.12.26.33)5: 221.12.2.205(221.12.2.205)6: 221.12.2.213(221.12.2.213)7: 221.12.2.149(221.12.2.149)8: 219.158.13.65(219.158.13.65)9: 219.158.11.94(219.158.11.94)10: 219.158.32.226(219.158.32.226)11: 203.208.62.17(203.208.62.17)12: 203.208.35.100(203.208.35.100)reached Resume: pmtu 1492 hops 12 back 14
2.619ms pmtu 1492 1.899ms 1.995ms asymm 4 1.991ms 5.949ms 9.361ms asymm 7 5.049ms
asymm 8
4.734ms
asymm 9 24.994ms asymm 11 23.024ms asymm 12 28.567ms asymm 14 25.885ms
asymm 14 18.932ms [root@CCIE /]# traceroute www.daodoc.com traceroute to www.daodoc.com(203.208.35.101), 30 hops max, 40 byte packets 1 172.16.12.126(172.16.12.126)2.088 ms 2.117 ms 3.910 ms 2 172.16.12.254(172.16.12.254)4.747 ms 3.249 ms 4.053 ms 3 172.16.1.1(172.16.1.1)2.978 ms 5.303 ms 4.158 ms 4 221.12.26.33(221.12.26.33)19.627 ms 17.143 ms 18.069 ms 5 221.12.2.209(221.12.2.209)23.741 ms 20.188 ms 23.686 ms 6 221.12.1.169(221.12.1.169)15.276 ms 16.759 ms 17.186 ms 7 221.12.1.201(221.12.1.201)18.830 ms 19.722 ms 21.721 ms 8 219.158.7.185(219.158.7.185)55.971 ms 56.697 ms 58.162 ms 9 219.158.22.154(219.158.22.154)58.840 ms 52.449 ms 52.919 ms 10 219.158.32.226(219.158.32.226)36.534 ms 40.734 ms 32.857 ms 11 203.208.62.15(203.208.62.15)25.774 ms 28.681 ms 29.240 ms 12 203.208.35.101(203.208.35.101)33.341 ms 35.694 ms 39.274 ms
显示当前终端
[root@CCIE /]# tty /dev/pts/1
显示磁盘的使用情况 [root@CCIE /]# df 文件系统
1K-块 已用 可用 已用% 挂载点
/dev/hda1 4559492 2465836 1858308 58% / tmpfs 127796 0 127796 0% /dev/shm [root@CCIE /]# df-i 文件系统 Inode(I)已用(I)可用(I)已用% 挂载点 /dev/hda1 1177344 107469 1069875 10% / tmpfs 31949 1 31948 1% /dev/shm
[root@CCIE /]# df-t ext3
已用 可用 已用% 挂载点 文件系统 1K-块
/dev/hda1 4559492 2465836 1858308 58% /
关闭硬盘的配额限制 [root@CCIE /]# quotaoff-a
开启硬盘的配额限制
[root@CCIE /]# quotaon-a
显示硬盘的空间限制
[root@CCIE /]# quotastats Kernel quota version: 6.5.1 Number of dquot lookups: 0 Number of dquot drops: 0 Number of dquot reads: 0 Number of dquot writes: 0 Number of quotafile syncs: 22 Number of dquot cache hits: 0 Number of allocated dquots: 0 Number of free dquots: 0 Number of in use dquot entries(user/group): 0
关闭硬盘的软件 raid [root@CCIE /]# rpiastop-a
显示硬盘的使用情况
[root@CCIE /]# repquota-a
显示分区消息
[root@CCIE /]# sfdisk-l
Disk /dev/hda: 10402 cylinders, 16 heads, 63 sectors/track Warning: The partition table looks like it was made for C/H/S=*/255/63(instead of 10402/16/63).For this listing I'll aume that geometry.Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start /dev/hda1 /dev/hda2 /dev/hda3 /dev/hda4
End 585 650--
#cyls #blocks Id System * 0+ 586 0 0 586-4707013+ 83 Linux 65 522112+ 82 Linux swap / Solaris 0 0 0 Empty 0 0 0 Empty 将内存数据写处硬盘
[root@CCIE /]# sync
创建一张启用盘
[root@CCIE /]# mkbootdisk 2.6.18-92.el5 Insert a disk in /dev/fd0.Any information on the disk will be lost.Pre to continue or ^C to abort:
mkisofs 创建一个 iso 文件
[root@CCIE ccie]# mkisofs-o aiso b INFO: UTF-8 character encoding detected by locale settings.Auming UTF-8 encoded filenames on source filesystem, use-input-charset to override.Total translation table size: 0 Total rockridge attributes bytes: 0 Total directory bytes: 0 Path table size(bytes): 10 Max brk space used 0 175 extents written(0 MB)[root@CCIE ccie]# ls aiso b fonts.dir
指定一个分区为交换分区
[root@CCIE ccie]# mkswap-c-vl-L swapnew/dev/hda3
启动图型界面
[root@CCIE ccie]# startx
显示当前设置
[root@CCIE ccie]# xset