您的位置:首页 > 运维架构 > Linux

嵌入式入门需要会的几个linux命令和知识

2014-02-20 01:58 471 查看
内容摘自http://www.lx138.com/default.php,整理出来的是比较常用的几个命令其他的用到再查也行

【简单说明】

                      我们进入linux系统后,利用图形界面打开命令行时是自动登录的,如果按alt+ctrl+f2进入命令模式,需要手动登录,

                登陆后系统就是启动一个shell程序,没错,命令行其实就是运行着的一个程序(可以这么认为先)shell有很多种,比如最常见的bash cshell 等等。无论哪种 一般会出现一个提示 符,然后等待输入,这就是我们登陆成功后跳出来等待我们输入的那个东东。当我们输入命令的时候,由于命令其实也分为2种,一种是shell内部的功 能比如下面的cd 命令,而另一种就是命令本身也是一个程序。就如同我们写的hello
world。。。所以shell接收了我们的输入之后。如果是内部功能就直接由当前shell    执行,如果是程序(无论是命令,还是用户写的程序,都是一个性质) shell就fork(创建新进程的系统调用 )一个新进程,然后让这个进程运行命令程序,自己等待他结束。命令运行结束后,shell继续回到等待用户输入的状态。

【一些快捷键】

                ctrl + c    : 终止当前命令或者程序的运行 

                ctrl + d   : 发送文件结束符号

                ctrl + alt + f2  : 进入2号终端,同理 f3是3号终端。。特殊的是f7 是回到图形界面

【常用进程的控制】

               命令 A | 命令 B      可以将命令A的输出作为命令B的输入 

                命令 A  > 文件B     可以将命令 A 的输出保存到文件B中(无论B存不存在)

                命令 A <  文件 B    可以用文件B内容作为命令A的输入 (B要存在)

                如果一个程序死循环或者睡眠太久想让他停下来。就直接按ctrl + c

                如果想让一个后台运行的进程 停止,那先执行ps 命令  看看进程的id是多少。 然后kill  id就可以杀死(命令后面加 & 可以后台运行)

【推荐完整学习书籍】

                 《鸟哥的私房菜第三版 基础篇》

                 《[Linux命令行和shell脚本编程宝典》

=================================== 常用命令 ============================================

 
 
【 cd 】
- 切换目录
 »语法
 cd[目录]
 
 »功能
 cd 指令cd 指令改变当前目录到指定目录。变量HOME是默认路径
 
 
范例1:切换目录

[root@lX138.COm ~]# echo $HOME //查看HOME录入位置

/root

[root@lX138.COm ~]# pwd //显示当前目录

/root

[root@lX138.COm ~]# cd Desktop/ //切换到Desktop目录

[root@lX138.COm Desktop]#

范例2:返回上级目录

[root@lX138.COm /opt]# cd ..

[root@lX138.COm /]#

范例3:后退到上次目录

[root@lX138.COm /opt]# cd /home

[root@lX138.COm /home]# cd -

/opt

[root@lX138.COm /opt]#

 
【 tar 】-压缩/解压文件
 »语法
 tar[必要参数][选择参数][文件]
 
 »功能
 tar 命令:用来压缩和解压文件。tar本身不具有压缩功能。他是调用压缩功能实现的
【常见解压/压缩命令】

tar

解包:tar xvf FileName.tar

打包:tar cvf FileName.tar DirName

(注:tar是打包,不是压缩!)

----------------------------

.gz

解压1:gunzip FileName.gz

解压2:gzip -d FileName.gz

压缩:gzip FileName

.tar.gz 和 .tgz

解压:tar zxvf FileName.tar.gz

压缩:tar zcvf FileName.tar.gz DirName

----------------------------

.bz2

解压1:bzip2 -d FileName.bz2

解压2:bunzip2 FileName.bz2

压缩: bzip2 -z FileName

.tar.bz2

解压:tar jxvf FileName.tar.bz2

压缩:tar jcvf FileName.tar.bz2 DirName

----------------------------

.bz

解压1:bzip2 -d FileName.bz

解压2:bunzip2 FileName.bz

压缩:未知

.tar.bz

解压:tar jxvf FileName.tar.bz

压缩:未知

----------------------------

.Z

解压:uncompress FileName.Z

压缩:compress FileName

.tar.Z

解压:tar Zxvf FileName.tar.Z

压缩:tar Zcvf FileName.tar.Z DirName

----------------------------

.zip

解压:unzip FileName.zip

压缩:zip FileName.zip DirName

----------------------------

.rar

解压:rar x FileName.rar

压缩:rar a FileName.rar DirName 

 
【 ls 】
- 显示目录内容
 »语法
 ls[选择参数]
 
 »功能
 ls 命令:用来显示目录的内容。是Linux最常用的命令之一,其中很多功能都很有用
范例1:显示文件

[root@hnlinux lx138.cOM]# ls

b.txt test.txt

[root@hnlinux lx138.cOM]# ls -l

总用量 128

-rw-r--r-- 1 root root 114688 1995-05-05 b.txt

-rw-r--r-- 1 root root   13 5月 29 20:54 test.txt

[root@hnlinux lx138.cOM]#

范例2:方便查看显示

[root@hnlinux lx138.cOM]# ls -lh

总用量 14M

-rw-r--r-- 1 root root 14M 5月 29 21:51 b.txt

-rw-r--r-- 1 root root  0 5月 29 21:49 test.txt

[root@hnlinux lx138.cOM]#

【 mv 】
- 移动或更名/重命名文件
 »语法
 mv[必要参数][选择参数]
 
 »功能
 mv 命令:移动或重命名指定文件
范例1:重命名文件

[root@hnlinux l x1 38 .co m]# ls //显示当前目录内容

new_1 new_2

[root@hnlinux l x1 38 .co m]# mv new_2 new_3 //文件重命名

[root@hnlinux l x1 38 .co m]# ls //显示当前目录内容

new_1 new_3

[root@hnlinux l x1 38 .co m]#

范例2:移动文件

[root@hnlinux l x1 38 .co m]# ls //显示当前目录内容

a.c new_1 new_3

[root@hnlinux l x1 38 .co m]# ls /home/test //显示/home/test目录内容

[root@hnlinux l x1 38 .co m]# mv a.c /home/test //移动文件

[root@hnlinux l x1 38 .co m]# ls /home/test //显示/home/test目录内容 

a.c

[root@hnlinux l x1 38 .co m]#

范例3:快速重命名

[root@lx138 ~]# mv main.c{,.cpp}

//将main.c重名为main.cpp

[root@hnlinux ~]#

 
【 mkdir 】-建立目录/文件夹
 »语法
 mkdir[必要参数][选择参数]
 
 »功能
 mkdir 命令:用于建立目录
范例1:创建一个目录

[root@hnlinux lX138.cOM]# ll

总用量 8

drwxr-xr-x 2 root root 4096 5月 29 12:23 new_1

[root@hnlinux lX138.cOM]#

范例2:创建指定属性的目录

[root@hnlinux lX138.cOM]# mkdir -m a=r new_2

[root@hnlinux lX138.cOM]# ll

总用量 16

drwxr-xr-x 2 root root 4096 5月 29 12:23 new_1

dr--r--r-- 2 root root 4096 5月 29 12:23 new_2

[root@hnlinux lX138.cOM]#

 
【 rmdir 】-删除目录/文件夹
 »语法
 rmdir[必要参数][选择参数][目录]
 
 »功能
 rmdir 命令:删除空目录,非空目录出现错误
范例1:删除目录

[root@hnlinux LX138.COm]# ll //显示当前目录内容

总用量 40

drwxr-xr-x 2 root root 4096 5月 29 17:42 Dir_1_feik

drwxr-xr-x 2 root root 4096 5月 29 17:41 Dir_2

drwxr-xr-x 2 root root 4096 5月 29 17:41 Dir_3

drwxr-xr-x 2 root root 4096 5月 29 17:41 Dir_4

drwxr-xr-x 2 root root 4096 5月 29 17:41 Dir_5

[root@hnlinux LX138.COm]# rmdir -v * //删除目当前录下的空目录

rmdir: 正在删除目录 Dir_1_feik

rmdir: ‘Dir_1_feik’: 目录非空

rmdir: 正在删除目录 Dir_2

rmdir: 正在删除目录 Dir_3

rmdir: 正在删除目录 Dir_4

rmdir: 正在删除目录 Dir_5

[root@hnlinux LX138.COm]# ll //显示当前目录内容

总用量 8

drwxr-xr-x 2 root root 4096 5月 29 17:42 Dir_1_feik

[root@hnlinux LX138.COm]#

【 rm 】
- 删除文件或目录
 »语法
 rm[必要参数][选择参数][目标文件或目录]
 
 »功能
 rm 命令:删除不需要的文件。该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除。对于链接文件,只是断开了链接,原文件保持不变
范例1:删除文件

[root@hnlinux lx138.com]# ll //显示当前目录内容

总用量 24

-rw-r--r-- 1 root root 0 5月 29 17:32 a.c

-rw-r--r-- 1 root root 0 5月 29 17:32 b.c

-rw-r--r-- 1 root root 0 5月 29 17:32 c.c

-rw-r--r-- 1 root root 0 5月 29 17:32 d.c

-rw-r--r-- 1 root root 0 5月 29 17:11 file2

-rw-r--r-- 1 root root 0 5月 29 17:11 file3

[root@hnlinux lx138.com]# rm a.c //删除a.c文件

rm:是否删除一般空文件‘a.c’? y

[root@hnlinux lx138.com]# ll //显示当前目录内容

总用量 20

-rw-r--r-- 1 root root 0 5月 29 17:32 b.c

-rw-r--r-- 1 root root 0 5月 29 17:32 c.c

-rw-r--r-- 1 root root 0 5月 29 17:32 d.c

-rw-r--r-- 1 root root 0 5月 29 17:11 file2

-rw-r--r-- 1 root root 0 5月 29 17:11 file3

[root@hnlinux lx138.com]#

范例2:删除目录

[root@hnlinux lx138.com]# ll //显示当前目录内容

总用量 28

-rw-r--r-- 1 root root  0 5月 29 17:32 b.c

-rw-r--r-- 1 root root  0 5月 29 17:32 c.c

-rw-r--r-- 1 root root  0 5月 29 17:32 d.c

drwxr-xr-x 2 root root 4096 5月 29 17:34 Dir_1

-rw-r--r-- 1 root root  0 5月 29 17:11 file2

-rw-r--r-- 1 root root  0 5月 29 17:11 file3

[root@hnlinux lx138.com]# rm -rf Dir_1/  //删除目录

[root@hnlinux lx138.com]# ll //显示当前目录内容

总用量 20

-rw-r--r-- 1 root root 0 5月 29 17:32 b.c

-rw-r--r-- 1 root root 0 5月 29 17:32 c.c

-rw-r--r-- 1 root root 0 5月 29 17:32 d.c

-rw-r--r-- 1 root root 0 5月 29 17:11 file2

-rw-r--r-- 1 root root 0 5月 29 17:11 file3

[root@hnlinux lx138.com]#

范例3:自动应答

[root@hnlinux lx138.com]# yes | rm -i /tmp/* //交互模式删除文件,通过yes自动应答
 

范例4:除某文件外,删除其余文件

 

[root@hnlinux lx138 .com]$ ls -l  //显示当前目录信息

总用量 203

drwxrwxrwx 1 root root  4096 2012-02-20 12:53 ./

drwxrwxrwx 1 root root  4096 2012-02-20 12:07 ../

drwxrwxrwx 1 root root  4096 2012-02-05 12:18 Debug/

drwxrwxrwx 1 root root   456 2012-02-20 12:57 test/

-rwxrwxrwx 1 root root   954 2012-02-05 12:53 Text1.c*

-rwxrwxrwx 1 root root   151 2012-02-05 11:46 Text1.cpp*

-rwxrwxrwx 1 root root  3387 2012-02-05 11:47 Text1.dsp*

-rwxrwxrwx 1 root root   518 2012-02-05 12:55 Text1.dsw*

-rwxrwxrwx 1 root root 33792 2012-02-05 12:55 Text1.ncb*

-rwxrwxrwx 1 root root 48640 2012-02-05 12:55 Text1.opt*

-rwxrwxrwx 1 root root   743 2012-02-05 12:53 Text1.plg*

-rwxrwxrwx 1 root root  3451 2012-02-05 11:47 复件 Text1.dsp*

-rwxrwxrwx 1 root root   528 2012-02-05 11:47 复件 Text1.dsw*

-rwxrwxrwx 1 root root 33792 2012-02-05 11:47 复件 Text1.ncb*

-rwxrwxrwx 1 root root 48640 2012-02-05 11:47 复件 Text1.opt*

-rwxrwxrwx 1 root root   766 2012-02-05 11:47 复件 Text1.plg*

[root@hnlinux lx138 .com]$ ls|grep -v ".cpp"| xargs -i rm -rf {}
 //配合 grep、xargs命令 删除 cpp文件外的所有文件与目录

[root@hnlinux lx138 .com]$ ls -l  //显示当前目录信息

总用量 9
drwxrwxrwx 1 root root 4096 2012-02-20 13:04 ./
drwxrwxrwx 1 root root 4096 2012-02-20 12:07 ../
-rwxrwxrwx 1 root root  151 2012-02-05 11:46 Text1.cpp*

 
【 touch 】-更新文件或目录
 »语法
 touch[必要参数][选择参数]
 
 »功能
 touch 命令:用来更新文件或目录的时间,文件不存在则创建该文件
范例1:更新文件修改时间

[root@hnlinux Lx138.com]# ll //显示当前目录时间

总用量 128

-rw-r--r-- 1 root root 114688 2000-05-05 b.txt

-rw-r--r-- 1 root root   13 5月 29 20:54 test.txt

[root@hnlinux Lx138.com]# touch b.txt  //更新文件为当前时间

[root@hnlinux Lx138.com]# ll //显示当前目录内容

总用量 128

-rw-r--r-- 1 root root 114688 5月 29 21:30 b.txt

-rw-r--r-- 1 root root   13 5月 29 20:54 test.txt

[root@hnlinux Lx138.com]#

范例2:更新文件的指定修改时间

[root@hnlinux Lx138.com]# ll //显示当前目录时间

总用量 128

-rw-r--r-- 1 root root 114688 5月 29 21:30 b.txt

-rw-r--r-- 1 root root   13 5月 29 20:54 test.txt

[root@hnlinux Lx138.com]# touch -d "05:05pm 05/05/1995" b.txt //更新为指定时间

[root@hnlinux Lx138.com]# ll //显示当前目录时间

总用量 128

-rw-r--r-- 1 root root 114688 1995-05-05 b.txt

-rw-r--r-- 1 root root   13 5月 29 20:54 test.txt

[root@hnlinux Lx138.com]#

【 cp 】
- 复制/备份
 »语法
 cp[必要参数][选择参数][源目录或者文件][目标文件或目录]
 
 »功能
 cp 命令:复制/链接文件或目录
范例1:复制文件

[root@lx138 ~]# cp a.c /home/test

范例2:复制时,进行备份

[root@lx138 ~]# cp -b a.c /home/test

范例3:复制文件夹

[root@lx138 ~]# cp -fr Dir/ /home/test

//将当前目录的Dir整个目录强制复制到 /home/test目录中

范例4:复制文件夹文件

[root@lx138 ~]# cp -fr Dir/* /home/test

//将当前目录的Dir整个目录的内容强制复制到 /home/test目录中

范例5:快速备份文件

[root@lx138 ~]# cp file.txt{,.bak}

 
【 ln 】
- 链接文件或目录
 »语法
 ln[必要参数][选择参数][源文件或目录][目标文件或目录]
 
 »功能
 ln 命令:用来链接文件或目录。当同时指定多个文件或目录时,目的目录必须存在,若不存在则出错,若存在,指定多个文件和目录将被复制的目录下。当不指定参数默认创建硬链接。创建的链接分为两种:硬链接和软链接;硬链接相当于创建副本;软链接只是单纯的链接
范例1:创建硬链接

[root@hnlinux ~]# ln file file_2  

//为file 创建硬链接file2,file2与file的各项属性相同

范例2:创建软连接

[root@hnlinux ~]# ln -s abc abc_2

//为abc文件创建软连接abc_2,如果abc丢失,abc_将失效

【 grep 】-文本搜索
 »语法
  grep[关键词][选择参数][文件]
范例1:查找指定进程

root@Lx138.COm:~# ps -ef | grep gedit //查找grep进程

snail   1706 1534 4 19:15 pts/0  00:00:01 gedit //这条是查找出的进程

root   1711 1623 0 19:15 pts/1   00:00:00 grep --color=auto gedit //这条结果是grep进程本身,并非真正要找的进程

范例2:查找指定进程个数

root@Lx138.COm:~# ps -ef | grep -c gedit

2

范例3:从文件中读取关键词进行搜索

root@Lx138.COm:~# cat text.txt //查看文件内容

hnlinux

www.Lx138.COm

ubuntu

ubuntu linux

redhat

Redhat

root@Lx138.COm:~# cat text2.txt //查看文件内容

linux

Redhat

root@Lx138.COm:~#

root@Lx138.COm:~# cat text.txt | grep -f text2.txt

hnlinux

ubuntu linux

Redhat

root@Lx138.COm:~#

范例4: 从文件中读取关键词进行搜索且显示行号

root@Lx138.COm:~# cat text.txt //查看文件内容

hnlinux

www.Lx138.COm

ubuntu

ubuntu linux

redhat

Redhat

root@Lx138.COm:~# cat text2.txt //查看文件内容

linux

Redhat

root@Lx138.COm:~#

root@Lx138.COm:~# cat text.txt | grep -nf text2.txt

1:hnlinux

4:ubuntu linux

6:Redhat

root@Lx138.COm:~#

范例5:从文件中查找关键词

root@Lx138.COm:~# grep 'linux' text.txt //查找包含 linux的关键词

hnlinux

ubuntu linux

root@Lx138.COm:~#

范例6:从多个文件中查找关键词

root@Lx138.COm:~# grep 'linux' text.txt text2.txt

text.txt:hnlinux

text.txt:ubuntu linux

text2.txt:linux

root@Lx138.COm:~#

【 find 】-查找目录或者文件
 »语法
 find[必要参数][选择参数]
 
 »功能
 find 命令:用于在文件树种查找文件,并作出相应的处理
范例1

查找指定时间内修改过的文件

[root@lx138 ~]# find -atime -2 //超找48小时内修改过的文件

.

./.mcoprc

./.bashrc

./xx00

./.bash_history

./c

./b.c

./path

./bud.diff

./xx01

./.DCOPserver_lx138_:0

./c.c

……省略部分结果

./.mcop/trader-cache/example_atan_saturate.arts.mcopclass

./.mcop/trader-cache/instrument_slide.mcopclass

./.mcop/trader-cache/instrument_organ2.arts.mcopclass

./.mcop/trader-cache/instrument_organ2.mcopclass

./.mcop/trader-cache/instrument_simple_tri.mcopclass

./e.c

./.bash_profile

./.ICEauthority

./.kde/socket-hnlinux

./.kde/socket-lx138

./.kde/tmp-lx138

./.kde/tmp-hnlinux

./a.c

./.viminfo

./arm-c

./.DCOPserver_lx138__0

[root@lx138 ~]#

范例2:根据关键字查找

[root@lx138 ~]# find . -name "*.c" //在当前目录查找 以.c结尾的文件。 . 代表当前目录

./b.c

./c.c

./e.c

./a.c

[root@lx138 ~]#

范例3

按照目录或文件的权限来查找文件

[root@lx138 ~]# find /root/ -perm 777 //查找/root目录下 权限为 777的文件

/root/

/root/.DCOPserver_lx138_:0

/root/.kde/tmp-vm-dev

/root/.kde/cache-vm-dev

/root/.kde/socket-vm-dev

/root/.kde/socket-hnlinux

/root/.kde/socket-lx138

/root/.kde/tmp-lx138

/root/.kde/tmp-hnlinux

[root@lx138 ~]#

范例4:按类型查找

[root@lx138 ~]# find . -type f -name "*.c" -print

./b.c

./c.c

./e.c

./a.c

[root@lx138 ~]# 

//查找当目录,以.c结尾的普通文件

范例5

查找的结果,在执行相应的命令操作

[root@lx138 ~]# find . -name "*.zip" -exec unzip "{}" ; //找到文件执行指定命令

//找到的文件执行unzip命令进行解压"{}”表示找到的文件,

[root@lx138 ~]# find . -name "*.c" -exec rm -rf "{}" ; //找到文件执行指定命令

//找到的以.c结尾的文件,删除

范例6:忽略某个目录

[root@lx138 ~]# find / -path "/home" -prune -o -name "*.c" -print

//查找.c结尾的文件忽略/home目录不进行查找

范例7:不进入其他文件系统查找

[root@lx138 ~]# find . -name "*.c" -mount -print

./home/a.c

[root@lx138 ~]#

范例7:查找当前所有目录并排序

[root@hnlinux ~]# find . -type d | sort

范例8:按大小查找文件

[root@hnlinux ~]# find . -size +1000000c -print

./.mozilla/firefox/hdtipisy.default/XUL.mfasl

./.mozilla/plugins/libflashplayer.so

[root@hnlinux ~]#

//查找当前目录大于1M的文件

范例9:查找 10天以前的文件并删除

[root@hnlinux ~]# find /logs -type f -mtime +10 -exec -ok rm {} \;

//指定/log目录10天以前的文件进行删除

【 who 】-显示系统用户信息/当前登录用户
 »语法
 who[必要参数][选择参数][记录文件]
 
 »功能
 who 命令:命令用来显示当前登录系统的用户的信息
范例1:显示当前登录系统的用户

root@snail-hnlinux:~# who  //显示当前登录系统的用户

root   tty7     2010-05-13 12:12 (:0)

root   pts/0    2010-05-14 17:09 (:0.0)

root   pts/1    2010-05-14 18:51 (192.168.1.17)

root   pts/2    2010-05-14 19:48 (192.168.1.17)

root@snail-hnlinux:~#

范例2:显示标题栏

root@snail-hnlinux:~# who -H

NAME   LINE     TIME       COMMENT

root   tty7     2010-05-13 12:12 (:0)

root   pts/0    2010-05-14 17:09 (:0.0)

root   pts/1    2010-05-14 18:51 (192.168.1.17)

root   pts/2    2010-05-14 19:48 (192.168.1.17)

root@snail-hnlinux:~#

范例3:显示用户登录来源

root@snail-hnlinux:~# who -l -H

NAME   LINE     TIME       IDLE     PID COMMENT

LOGIN  tty4     2010-05-13 12:11        852 id=4

LOGIN  tty5     2010-05-13 12:11        855 id=5

LOGIN  tty2     2010-05-13 12:11        862 id=2

LOGIN  tty3     2010-05-13 12:11        864 id=3

LOGIN  tty6     2010-05-13 12:11        867 id=6

LOGIN  tty1     2010-05-13 12:11       1021 id=1

root@snail-hnlinux:~#

范例4:显示终端属性

root@snail-hnlinux:~# who -T -H

NAME    LINE     TIME       COMMENT

root   + tty7     2010-05-13 12:12 (:0)

root   + pts/0    2010-05-14 17:09 (:0.0)

root   - pts/1    2010-05-14 18:51 (192.168.1.17)

root   - pts/2    2010-05-14 19:48 (192.168.1.17)

root@snail-hnlinux:~#

范例5:只显示当前用户

root@snail-hnlinux:~# who -m -H

NAME   LINE     TIME       COMMENT

root   pts/1    2010-05-14 18:51 (192.168.1.17)

root@snail-hnlinux:~#

范例6:精简模式显示

root@snail-hnlinux:~# who -q

root root root root

# users=4

root@snail-hnlinux:~#

【 uname 】-显示系统信息/查看内核版本
 »语法
 uname[必要参数][选择参数]
 
 »功能
 uname 命令:用来显示系统的相关信息
范例1:显示系统信息 root@snail-hnlinux:~# uname -a

Linux snail-hnlinux 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010 i686 GNU/Linux

root@snail-hnlinux:~#

范例2:显示计算机类型

root@snail-hnlinux:~# uname -m

i686

范例3:显示计算机名

root@snail-hnlinux:~#

root@snail-hnlinux:~# uname -n

snail-hnlinux

root@snail-hnlinux:~#

范例4:显示操作系统发行编号

root@snail-hnlinux:~# uname -r

2.6.32-21-generic

范例5:显示操作系统名称

root@snail-hnlinux:~# uname -s

Linux

范例6:显示系统时间

root@snail-hnlinux:~# uname -v

#32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010

root@snail-hnlinux:~#

 
【 ifconfig 】-显示和配置网络设备
 »语法
 ifconfig[网络设备][必要参数][选择参数]
 
 »功能
 ifconfig 命令:用来查看和配置网络设备。当网络环境发生改变时可通过此命令对网络进行相应的配置
范例1:显示网络设备信息

[root@Lx138.com ~]# ifconfig        

eth0   Link encap:Ethernet HWaddr 00:50:56:0A:0B:0C 

     inet addr:192.168.0.3 Bcast:192.168.0.255 Mask:255.255.255.0

     inet6 addr: fe80::250:56ff:fe0a:b0c/64 Scope:Link

     UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

     RX packets:172220 errors:0 dropped:0 overruns:0 frame:0

     TX packets:132379 errors:0 dropped:0 overruns:0 carrier:0

     collisions:0 txqueuelen:1000

     RX bytes:87101880 (83.0 MiB) TX bytes:41576123 (39.6 MiB)

     Interrupt:185 Base address:0x2024

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:2022 errors:0 dropped:0 overruns:0 frame:0

     TX packets:2022 errors:0 dropped:0 overruns:0 carrier:0

     collisions:0 txqueuelen:0

     RX bytes:2459063 (2.3 MiB) TX bytes:2459063 (2.3 MiB)

[root@Lx138.com ~]#

范例2:启动关闭指定网卡

[root@Lx138.com ~]# ifconfig eth0 down

[root@Lx138.com ~]# ifconfig eth0 up

范例3:为网卡配置和删除IPv6地址

[root@Lx138.com ~]# ifconfig eth0 add 33ffe:3240:800:1005::2/ 64 //为网卡诶之IPv6地址

[root@Lx138.com ~]# ifconfig eth0 del 33ffe:3240:800:1005::2/ 64 //为网卡删除IPv6地址

范例4用ifconfig修改MAC地址

[root@Lx138.com ~]# ifconfig eth0 down //关闭网卡

[root@Lx138.com ~]# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址

[root@Lx138.com ~]# ifconfig eth0 up //启动网卡
[root@Lx138.com ~]# ifconfig eth1 hw ether 00:1D:1C:1D:1E //关闭网卡并修改MAC地址 

[root@Lx138.com ~]# ifconfig eth1 up //启动网卡

 

范例5: 配置IP地址

[root@Lx138.com ~]# ifconfig eth0 192.168.1.56

//给eth0网卡配置IP地址

[root@Lx138.com ~]# ifconfig eth0 192.168.1.56 netmask 255.255.255.0
// 给eth0网卡配置IP地址,并加上子掩码

 [root@Lx138.com ~]# ifconfig eth0 192.168.1.56 netmask 255.255.255.0 broadcast 192.168.1.255

// 给eth0网卡配置IP地址,加上子掩码,加上个广播地址

 

范例6: 启用和关闭ARP协议

[root@Lx138.com ~]# ifconfig eth0 arp  //开启

[root@Lx138.com ~]# ifconfig eth0 -arp  //关闭

 

 

范例7: 设置最大传输单元

 [root@Lx138.com ~]# ifconfig eth0 mtu 1500 

//设置能通过的最大数据包大小为 1500 bytes

【 pwd 】-显示工作目录
 »语法
 pwd[选择参数]
 
 »功能
 pwd 命令:可以使用户获取当前路径的信息
 范例1:获取当前目录路径

root@snail-hnlinux:~# pwd

/root

root@snail-hnlinux:~#

[root@hnlinux ~]#

【 shutdown 】-系统关机
 »语法
 shutdown[必要参数][选择参数][时间][警告信息]
 
 »功能
 shutdown 命令:可以进行关机或者重新启动
范例1:立即关机

root@snail-hnlinux:~# shutdown -h now

范例2:指定5分钟后关机

root@snail-hnlinux:~# shutdown +5 “System will shutdown after 5 minutes” //5分钟够关机并显示 警告信息
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux