Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1058454
  • 博文数量: 139
  • 博客积分: 1823
  • 博客等级: 上尉
  • 技术积分: 3403
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-05 09:54
文章存档

2014年(7)

2013年(16)

2012年(48)

2011年(68)

分类: LINUX

2013-08-17 11:25:11

本文选自:

1. lsblk命令

"lsblk"就是列出块设备。除了RAM外,以标准的树状输出格式,整齐地显示块设备。

01 root@tecmint:~# lsblk
02   
03 NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
04 sda      8:0    0 232.9G  0 disk 
05 ├─sda1   8:1    0  46.6G  0 part /
06 ├─sda2   8:2    0     1K  0 part 
07 ├─sda5   8:5    0   190M  0 part /boot
08 ├─sda6   8:6    0   3.7G  0 part [SWAP]
09 ├─sda7   8:7    0  93.1G  0 part /data
10 └─sda8   8:8    0  89.2G  0 part /personal
11 sr0     11:0    1  1024M  0 rom

lsblk -l”命令以列表格式显示块设备(而不是树状格式)。

01 root@tecmint:~# lsblk -l
02   
03 NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
04 sda    8:0    0 232.9G  0 disk 
05 sda1   8:1    0  46.6G  0 part /
06 sda2   8:2    0     1K  0 part 
07 sda5   8:5    0   190M  0 part /boot
08 sda6   8:6    0   3.7G  0 part [SWAP]
09 sda7   8:7    0  93.1G  0 part /data
10 sda8   8:8    0  89.2G  0 part /personal
11 sr0   11:0    1  1024M  0 rom

注意:lsblk是最有用和最简单的方式来了解插入的USB设备的名字,特别是当你在终端上处理磁盘/块设备时。

2. md5sum命令

md5sum”就是计算和检验MD5信息签名。md5 checksum(通常叫做哈希)使用匹配或者验证文件的文件的完整性,因为文件可能因为传输错误,磁盘错误或者无恶意的干扰等原因而发生改变。

1 root@tecmint:~# md5sum teamviewer_linux.deb 
2   
3 47790ed345a7b7970fc1f2ac50c97002  teamviewer_linux.deb

注意:用户可以使用官方提供的和md5sum生成签名信息匹对以此检测文件是否改变。Md5sum没有sha1sum安全,这点我们稍后讨论。

3. dd命令

dd”命令代表了转换和复制文件。可以用来转换和复制文件,大多数时间是用来复制iso文件(或任何其它文件)到一个usb设备(或任何其它地方)中去,所以可以用来制作USB启动器。

1 root@tecmint:~# dd if=/home/user/Downloads/debian.iso of=/dev/sdb1 bs=512M; sync

注意:在上面的例子中,usb设备就是sdb1(你应该使用lsblk命令验证它,否则你会重写你的磁盘或者系统),请慎重使用磁盘的名,切忌。

dd 命令在执行中会根据文件的大小和类型 以及 usb设备的读写速度,消耗几秒到几分钟不等。

4. uname命令

"uname"命令就是Unix Name的简写。显示机器名,操作系统和内核的详细信息。

1 root@tecmint:~# uname -a
2   
3 Linux tecmint 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686 GNU/Linux

注意: uname显示内核类别, uname -a显示详细信息。上面的输出详细说明了uname -a

  1. Linux“: 机器的内核名
  2. tecmint“: 机器的节点名
  3. 3.8.0-19-generic“: 内核发布版本
  4. #30-Ubuntu SMP“: 内核版本
  5. i686“: 处理器架构
  6. GNU/Linux“: 操作系统名

5. history命令

history”命令就是历史记录。它显示了在终端中所执行过的所有命令的历史。

01 root@tecmint:~# history
02   
03  1  sudoadd-apt-repository ppa:tualatrix/ppa
04  2  sudoapt-get update
05  3  sudoapt-get installubuntu-tweak
06  4  sudoadd-apt-repository ppa:diesch/testing
07  5  sudoapt-get update
08  6  sudoapt-get installindicator-privacy
09  7  sudoadd-apt-repository ppa:atareao/atareao
10  8  sudoapt-get update
11  9  sudoapt-get installmy-weather-indicator
12  10 pwd
13  11 cd&& sudocp-r unity/6 /usr/share/unity/
14  12 cd/usr/share/unity/icons/
15  13 cd/usr/share/unity

注意:按住“CTRL + R”就可以搜索已经执行过的命令,它可以在你写命令时自动补全。

1 (reverse-i-search)`if': ifconfig


6. touch 命令

touch”命令代表了将文件的访问和修改时间更新为当前时间。touch命令只会在文件不存在的时候才会创建它。如果文件已经存在了,它会更新时间戳,但是并不会改变文件的内容。

1 root@tecmint:~# touch tecmintfile

注意:touch 可以用来在用户拥有写权限的目录下创建不存在的文件。


7. chown命令

chown”命令就是改变文件拥有者和所在用户组。每个文件都属于一个用户组和一个用户。在你的目录下,使用"ls -l",你就会看到像这样的东西。

1 root@tecmint:~# ls -l 
2   
3 drwxr-xr-x 3 server root 4096 May 10 11:14 Binary 
4 drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

在这里,目录Binary属于用户"server",和用户组"root",而目录"Desktop"属于用户“server”和用户组"server"

chown”命令用来改变文件的所有权,所以仅仅用来管理和提供文件的用户和用户组授权。

1 root@tecmint:~# chown server:server Binary
2   
3 drwxr-xr-x 3 server server 4096 May 10 11:14 Binary 
4 drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

注意:“chown”所给的文件改变用户和组的所有权到新的拥有者或者已经存在的用户或者用户组。

 

8. tar命令

tar”命令是磁带归档(Tape Archive),对创建一些文件的的归档和它们的解压很有用。

1 root@tecmint:~# tar -zxvf abc.tar.gz (记住'z'代表了.tar.gz)
1 root@tecmint:~# tar -jxvf abc.tar.bz2 (记住'j'代表了.tar.bz2)
1 root@tecmint:~# tar -cvf archieve.tar.gz(.bz2) /path/to/folder/abc

注意: "tar.gz"代表了使用gzip归档,“bar.bz2”使用bzip压缩的,它压缩的更好但是也更慢。

了解更多"tar 命令"的例子,请查看

 

9. date命令

date”命令使用标准的输出打印当前的日期和时间,也可以深入设置。

1 root@tecmint:~# date
2   
3 Fri May 17 14:13:29 IST 2013
1 root@tecmint:~# date --set='14 may 2013 13:57' 
2   
3 Mon May 13 13:57:00 IST 2013

注意:这个命令在脚本中十分有用,以及基于时间和日期的脚本更完美。而且在终端中改变日期和时间,让你更专业!!!(当然你需要root权限才能操作这个,因为它是系统整体改变)

10. cat命令

cat”代表了连结(Concatenation),连接两个或者更多文本文件或者以标准输出形式打印文件的内容。

1 root@tecmint:~# cat a.txt b.txt c.txt d.txt abcd.txt
1 root@tecmint:~# cat abcd.txt
2 ....
3 contents of fileabcd
4 ...

注意:“<<”和“<”调用了追加符号。它们用来追加到文件里,而不是显示在标准输出上。“<”符号会删除已存在的文件,然后创建一个新的文件。所以因为安全的原因,建议使用“<<”,它会写入到文件中,而不是覆盖或者删除。

 
 

在深入探究之前,我必须让你知道通配符(你应该知道通配符,它出现在大多数电视选秀中)。通配符是shell的特色,和任何GUI文件管理器相比,它使命令行更强大有力!如你所看到那样,在一个图形文件管理器中,你想选择一大组文件,你通常不得不使用你的鼠标来选择它们。这可能觉得很简单,但是事实上,这种情形很让人沮丧!

例如,假如你有一个有很多很多各种类型的文件和子目录的目录,然后你决定移动所有文件名中包含“Linux”字样的HTML文件到另外一个目录。如何简单的完成这个?如果目录中包含了大量的不同名的HTML文件,你的任务很巨大,而不是简单了。

在LInux CLI中,这个任务就很简单,就好像只移动一个HTML文件,因为有shell的通配符,才会如此简单。这些是特殊的字符,允许你选择匹配某种字符模式的文件名。它帮助你来选择,即使是大量文件名中只有几个字符,而且在大多数情形中,它比使用鼠标选择文件更简单。

这里就是常用通配符列表:

1 Wildcard Matches
2    *            零个或者更多字符
3    ?            恰好一个字符
4 [abcde]             恰好列举中的一个字符
5  [a-e]          恰好在所给范围中的一个字符
6 [!abcde]        任何字符都不在列举中 
7 [!a-e]          任何字符都不在所给的范围中
8 {debian,linux}      恰好在所给选项中的一整个单词

! 叫做非,带'!'的反向字符串为真

更多请阅读Linux cat 命令的实例

11. 命令: Find

搜索指定目录下的文件,从开始于父目录,然后搜索子目录。

01 root@tecmint:~# find -name *.sh 
02   
03 ./Desktop/load.sh 
04 ./Desktop/test.sh 
05 ./Desktop/shutdown.sh 
06 ./Binary/firefox/run-mozilla.sh 
07 ./Downloads/kdewebdev-3.5.8/quanta/scripts/externalpreview.sh 
08 ./Downloads/kdewebdev-3.5.8/admin/doxygen.sh 
09 ./Downloads/kdewebdev-3.5.8/admin/cvs.sh 
10 ./Downloads/kdewebdev-3.5.8/admin/ltmain.sh 
11 ./Downloads/wheezy-nv-install.sh

注意: `-name‘选项是搜索大小写敏感。可以使用`-iname‘选项,这样在搜索中可以忽略大小写。(*是通配符,可以搜索所有的文件;‘.sh‘你可以使用文件名或者文件名的一部分来制定输出结果)


01 root@tecmint:~# find -iname *.SH ( find -iname *.Sh /  find -iname *.sH)
02   
03 ./Desktop/load.sh 
04 ./Desktop/test.sh 
05 ./Desktop/shutdown.sh 
06 ./Binary/firefox/run-mozilla.sh 
07 ./Downloads/kdewebdev-3.5.8/quanta/scripts/externalpreview.sh 
08 ./Downloads/kdewebdev-3.5.8/admin/doxygen.sh 
09 ./Downloads/kdewebdev-3.5.8/admin/cvs.sh 
10 ./Downloads/kdewebdev-3.5.8/admin/ltmain.sh 
11 ./Downloads/wheezy-nv-install.sh
01 root@tecmint:~# find -name *.tar.gz 
02   
03 /var/www/modules/update/tests/aaa_update_test.tar.gz 
04 ./var/cache/flashplugin-nonfree/install_flash_player_11_linux.i386.tar.gz 
05 ./home/server/Downloads/drupal-7.22.tar.gz 
06 ./home/server/Downloads/smtp-7.x-1.0.tar.gz 
07 ./home/server/Downloads/noreqnewpass-7.x-1.2.tar.gz 
08 ./usr/share/gettext/archive.git.tar.gz 
09 ./usr/share/doc/apg/php.tar.gz 
10 ./usr/share/doc/festival/examples/speech_pm_1.0.tar.gz 
11 ./usr/share/doc/argyll/examples/spyder2.tar.gz 
12 ./usr/share/usb_modeswitch/configPack.tar.gz

注意:以上命令查找根目录下和所有文件夹以及加载的设备的子目录下的所有包含‘tar.gz'的文件。

’find'命令的更详细信息请参考

 
 

12. 命令: grep

grep‘命令搜索指定文件中包含给定字符串或者单词的行。举例搜索‘/etc/passwd‘文件中的‘tecmint'

1 root@tecmint:~# grep tecmint /etc/passwd 
2   
3 tecmint:x:1000:1000:Tecmint,,,:/home/tecmint:/bin/bash

使用’-i'选项将忽略大小写。

1 root@tecmint:~# grep -i TECMINT /etc/passwd 
2   
3 tecmint:x:1000:1000:Tecmint,,,:/home/tecmint:/bin/bash

使用’-r'选项递归搜索所有自目录下包含字符串 “127.0.0.1“.的行。

01 root@tecmint:~# grep -r "127.0.0.1" /etc/ 
02   
03 /etc/vlc/lua/http/.hosts:127.0.0.1
04 /etc/speech-dispatcher/modules/ivona.conf:#IvonaServerHost "127.0.0.1"
05 /etc/mysql/my.cnf:bind-address      = 127.0.0.1
06 /etc/apache2/mods-available/status.conf:    Allow from 127.0.0.1 ::1
07 /etc/apache2/mods-available/ldap.conf:    Allow from 127.0.0.1 ::1
08 /etc/apache2/mods-available/info.conf:    Allow from 127.0.0.1 ::1
09 /etc/apache2/mods-available/proxy_balancer.conf:#    Allow from 127.0.0.1 ::1
10 /etc/security/access.conf:#+ : root : 127.0.0.1
11 /etc/dhcp/dhclient.conf:#prepend domain-name-servers 127.0.0.1;
12 /etc/dhcp/dhclient.conf:#  option domain-name-servers 127.0.0.1;
13 /etc/init/network-interface.conf:   ifconfiglo 127.0.0.1 up || true
14 /etc/java-6-openjdk/net.properties:# localhost & 127.0.0.1).
15 /etc/java-6-openjdk/net.properties:# http.nonProxyHosts=localhost|127.0.0.1
16 /etc/java-6-openjdk/net.properties:# localhost & 127.0.0.1).
17 /etc/java-6-openjdk/net.properties:# ftp.nonProxyHosts=localhost|127.0.0.1
18 /etc/hosts:127.0.0.1    localhost

注意:您还可以使用以下选项:

  1. -w 搜索单词 (egrep -w ‘word1|word2‘ /path/to/file).
  2. -c 用于统计满足要求的行 (i.e., total number of times the pattern matched) (grep -c ‘word‘ /path/to/file).
  3. –color 彩色输出 (grep –color server /etc/passwd).

13. 命令: ps

ps命令给出正在运行的某个进程的状态,每个进程有特定的id成为PID。

1 root@tecmint:~# ps
2   
3  PID TTY          TIME CMD
4  4170 pts/1    00:00:00 bash
5  9628 pts/1    00:00:00 ps

使用‘-A‘选项可以列出所有的进程及其PID。

01 root@tecmint:~# ps -A
02   
03  PID TTY          TIME CMD
04     1 ?        00:00:01 init
05     2 ?        00:00:00 kthreadd
06     3 ?        00:00:01 ksoftirqd/0
07     5 ?        00:00:00 kworker/0:0H
08     7 ?        00:00:00 kworker/u:0H
09     8 ?        00:00:00 migration/0
10     9 ?        00:00:00 rcu_bh
11 ....

注意:当你要知道有哪些进程在运行或者需要知道想杀死的进程PID时ps命令很管用。你可以把它与‘grep‘合用来查询指定的输出结果,例如:

1 root@tecmint:~# ps -A | grep -i ssh
2   
3  1500 ?        00:09:58 sshd
4  4317 ?        00:00:00 sshd

ps命令与grep命令用管道线分割可以得到我们想要的结果。

 

14. 命令: kill

也许你从命令的名字已经猜出是做什么的了,kill是用来杀死已经无关紧要或者没有响应的进程.它是一个非常有用的命令,而不是非常非常有用.你可能很熟悉Windows下要杀死进程可能需要频繁重启机器因为一个在运行的进程大部分情况下不能够杀死,即使杀死了进程也需要重新启动操作系统才能生效.但在linux环境下,事情不是这样的.你可以杀死一个进程并且重启它而不是重启整个操作系统.

杀死一个进程需要知道进程的PID.

假设你想杀死已经没有响应的‘apache2'进程,运行如下命令:

1 root@tecmint:~# ps -A | grep -i apache2
2   
3 1285 ?        00:00:00 apache2

搜索‘apache2'进程,找到PID并杀掉它.例如:在本例中‘apache2'进程的PID是1285..

1 root@tecmint:~# kill 1285 (to kill the process apache2)

注意:每次你重新运行一个进程或者启动系统,每个进程都会生成一个新的PID.你可以使用ps命令获得当前运行进程的PID.

另一个杀死进程的方法是:

1 root@tecmint:~# pkill apache2

注意:kill需要PID作为参数,pkill可以选择应用的方式,比如指定进程的所有者等.

13765502.93406

15. 命令: whereis

whereis的作用是用来定位命令的二进制文件\资源\或者帮助页.举例来说,获得ls和kill命令的二进制文件/资源以及帮助页:

1 root@tecmint:~# whereis ls 
2   
3 ls: /bin/ls/usr/share/man/man1/ls.1.gz
1 root@tecmint:~# whereis kill
2   
3 kill: /bin/kill/usr/share/man/man2/kill.2.gz /usr/share/man/man1/kill.1.gz

注意:当需要知道二进制文件保存位置时有用.

16. 命令: service

service‘命令控制服务的启动、停止和重启,它让你能够不重启整个系统就可以让配置生效以开启、停止或者重启某个服务。

在Ubuntu上启动apache2 server:

1 root@tecmint:~# service apache2 start
2   
3  * Starting web server apache2                                                                                                                                 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 forServerName
4 httpd (pid 1285) already running                        [ OK ]

重启apache2 server:

1 root@tecmint:~# service apache2 restart
2   
3 * Restarting web server apache2                                                                                                                               apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 forServerName
4  ... waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 forServerName  [ OK ]

停止apache2 server:

1 root@tecmint:~# service apache2 stop
2   
3  * Stopping web server apache2                                                                                                                                 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 forServerName
4  ... waiting                                                                [ OK ]

注意:要想使用service命令,进程的脚本必须放在‘/etc/init.d‘,并且路径必须在指定的位置。

如果要运行“service apache2 start”实际上实在执行“service /etc/init.d/apache2 start”.

 

17. 命令: alias

alias是一个系统自建的shell命令,允许你为名字比较长的或者经常使用的命令指定别名。

我经常用ls -l‘命令,它有五个字符(包括空格)。于是我为它创建了一个别名‘l'。

1 root@tecmint:~# alias l='ls -l'

试试它是否能用:

01 root@tecmint:~# l
02   
03 total 36 
04 drwxr-xr-x 3 tecmint tecmint 4096 May 10 11:14 Binary 
05 drwxr-xr-x 3 tecmint tecmint 4096 May 21 11:21 Desktop 
06 drwxr-xr-x 2 tecmint tecmint 4096 May 21 15:23 Documents 
07 drwxr-xr-x 8 tecmint tecmint 4096 May 20 14:56 Downloads 
08 drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Music 
09 drwxr-xr-x 2 tecmint tecmint 4096 May 20 16:17 Pictures 
10 drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Public 
11 drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Templates 
12 drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Videos

去掉’l'别名,要使用unalias命令:

1 root@tecmint:~# unalias l

再试试:

1 root@tecmint:~# l
2   
3 bash: l: commandnot found

开个玩笑,把一个重要命令的别名指定为另一个重要命令:

1 aliascd='ls -l'(setaliasof ls-l to cd)
2 aliassu='pwd'(setaliasof pwdto su)
3 ....
4 (You can create your own)
5 ....

想想多么有趣,现在如果你的朋友敲入‘cd'命令,当他看到的是目录文件列表而不是改变目录;当他试图用’su‘命令时,他会进入当前目录。你可以随后去掉别名,向他解释以上情况。

18.命令: df

报告系统的磁盘使用情况。在跟踪磁盘使用情况方面对于普通用户和系统管理员都很有用。 ‘df‘ 通过检查目录大小工作,但这一数值仅当文件关闭时才得到更新。

01 root@tecmint:~# df
02   
03 Filesystem     1K-blocks    Used Available Use% Mounted on
04 /dev/sda1       47929224 7811908  37675948  18% /
05 none                   4       0         4   0% /sys/fs/cgroup
06 udev             1005916       4   1005912   1% /dev
07 tmpfs             202824     816    202008   1% /run
08 none                5120       0      5120   0% /run/lock
09 none             1014120     628   1013492   1% /run/shm
10 none              102400      44    102356   1% /run/user
11 /dev/sda5         184307   79852     94727  46% /boot
12 /dev/sda7       95989516   61104  91045676   1% /data
13 /dev/sda8       91953192   57032  87218528   1% /personal

df’命令的更多例子请参阅 .

19. 命令: du

估计文件的空间占用。 逐层统计文件(例如以递归方式)并输出摘要。

01 root@tecmint:~# du
02   
03 8       ./Daily Pics/wp-polls/images/default_gradient
04 8       ./Daily Pics/wp-polls/images/default
05 32      ./Daily Pics/wp-polls/images
06 8       ./Daily Pics/wp-polls/tinymce/plugins/polls/langs
07 8       ./Daily Pics/wp-polls/tinymce/plugins/polls/img
08 28      ./Daily Pics/wp-polls/tinymce/plugins/polls
09 32      ./Daily Pics/wp-polls/tinymce/plugins
10 36      ./Daily Pics/wp-polls/tinymce
11 580     ./Daily Pics/wp-polls
12 1456    ./Daily Pics
13 36      ./Plugins/wordpress-author-box
14 16180   ./Plugins
15 12      ./May Articles 2013/Xtreme Download Manager
16 4632    ./May Articles 2013/XCache

注意: ‘df‘ 只显示文件系统的使用统计,但‘du‘统计目录内容。‘du‘命令的更详细信息请参阅.

20. 命令: cmp

比较两个任意类型的文件并将结果输出至标准输出。如果两个文件相同, ‘cmp‘默认返回0;如果不同,将显示不同的字节数和第一处不同的位置。

以下面两个文件为例:

file1.txt
1 root@tecmint:~# cat file1.txt
2   
3 Hi My name is Tecmint
file2.txt
1 root@tecmint:~# cat file2.txt
2   
3 Hi My name is tecmint [dot] com

比较一下这两个文件,看看命令的输出。

1 root@tecmint:~# cmp file1.txt file2.txt 
2   
3 file1.txt file2.txt differ: byte 15, line 1

21. 命令: wget

Wget是用于非交互式(例如后台)下载文件的免费工具.支持HTTP, HTTPS, FTP协议和 HTTP 代理。

使用wget下载ffmpeg

01 root@tecmint:~# wget
02   
03 --2013-05-22 18:54:52-- 
04 Resolving downloads.sourceforge.net (downloads.sourceforge.net)... 216.34.181.59
05 Connecting to downloads.sourceforge.net (downloads.sourceforge.net)|216.34.181.59|:80... connected.
06 HTTP request sent, awaiting response... 302 Found
07 Location: [following]
08 --2013-05-22 18:54:54-- 
09 Resolving kaz.dl.sourceforge.net (kaz.dl.sourceforge.net)... 92.46.53.163
10 Connecting to kaz.dl.sourceforge.net (kaz.dl.sourceforge.net)|92.46.53.163|:80... connected.
11 HTTP request sent, awaiting response... 200 OK
12 Length: 275557 (269K) [application/octet-stream]
13 Saving to: ‘ffmpeg-php-0.6.0.tbz2’
14   
15 100%[===========================================================================<] 2,75,557    67.8KB/s   in4.0s   
16   
17 2013-05-22 18:55:00 (67.8 KB/s) - ‘ffmpeg-php-0.6.0.tbz2’ saved [275557/275557]

 

22. 命令: nslookup

网络实用程序,用于获得互联网服务器的信息。顾名思义,该实用程序将发现通过查询 DNS 域的名称服务器信息。

1 [avishek@tecmint ~]$ nslookuptecmint.com 
2   
3 Server:     192.168.1.1 
4 Address:    192.168.1.1#53 
5   
6 Non-authoritative answer: 
7 Name:   tecmint.com 
8 Address: 50.16.67.239
查询邮件交换器记录
01 [avishek@tecmint ~]$ nslookup-query=mx tecmint.com 
02   
03 Server:     192.168.1.1 
04 Address:    192.168.1.1#53 
05   
06 Non-authoritative answer: 
07 tecmint.com mail exchanger = 0 smtp.secureserver.net. 
08 tecmint.com mail exchanger = 10 mailstore1.secureserver.net. 
09   
10 Authoritative answers can be found from:
查询域名服务器
01 [avishek@tecmint ~]$ nslookup-type=ns tecmint.com 
02   
03 Server:     192.168.1.1 
04 Address:    192.168.1.1#53 
05   
06 Non-authoritative answer: 
07 tecmint.com nameserver = ns3404.com. 
08 tecmint.com nameserver = ns3403.com. 
09   
10 Authoritative answers can be found from:
查询DNS记录
01 [avishek@tecmint ~]$ nslookup-type=any tecmint.com 
02   
03 Server:     192.168.1.1 
04 Address:    192.168.1.1#53 
05   
06 Non-authoritative answer: 
07 tecmint.com mail exchanger = 10 mailstore1.secureserver.net. 
08 tecmint.com mail exchanger = 0 smtp.secureserver.net. 
09 tecmint.com nameserver = ns06.domaincontrol.com. 
10 tecmint.com nameserver = ns3404.com. 
11 tecmint.com nameserver = ns3403.com. 
12 tecmint.com nameserver = ns05.domaincontrol.com. 
13   
14 Authoritative answers can be found from:
查询起始授权机构
01 [avishek@tecmint ~]$ nslookup-type=soa tecmint.com 
02   
03 Server:     192.168.1.1 
04 Address:    192.168.1.1#53 
05   
06 Non-authoritative answer: 
07 tecmint.com 
08     origin = ns3403.hostgator.com 
09     mail addr = dnsadmin.gator1702.hostgator.com 
10     serial = 2012081102 
11     refresh = 86400 
12     retry = 7200 
13     expire = 3600000 
14     minimum = 86400 
15   
16 Authoritative answers can be found from:
查询端口号

更改使用你想要连接的端口号

1 [avishek@tecmint ~]$ nslookup-port 56 tecmint.com
2   
3 Server:     tecmint.com
4 Address:    50.16.76.239#53
5   
6 Name:   56
7 Address: 14.13.253.12

更多阅读

 

23. 命令: dig

dig是查询DNS 域名服务器的工具,可以查询的主机地址、 邮件交流、 域名服务器相关的信息。在任何 Linux (Unix) 或 Macintosh OS X 操作系统上,都可以使用该工具。dig的最典型的用法是单个主机的查询。

1 [avishek@tecmint ~]$ digtecmint.com
2   
3 ; < >< DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6 < >< tecmint.com 
4 ;; global options: +cmd 
5 ;; Got answer: 
6 ;; -<
关闭注释行
01 [avishek@tecmint ~]$ digtecmint.com +nocomments 
02   
03 ; < >< DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6 < >< tecmint.com +nocomments 
04 ;; global options: +cmd 
05 ;tecmint.com.           IN  A 
06 tecmint.com.        14400   IN  A   40.216.66.239 
07 ;; Query time: 418 msec 
08 ;; SERVER: 192.168.1.1#53(192.168.1.1) 
09 ;; WHEN: Sat Jun 29 13:53:22 2013 
10 ;; MSG SIZE  rcvd: 45
关闭认证块
1 [avishek@tecmint ~]$ digtecmint.com +noauthority 
2   
3 ; < >< DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6 < >< tecmint.com +noauthority 
4 ;; global options: +cmd 
5 ;; Got answer: 
6 ;; -<
关闭其他
1 [avishek@tecmint ~]$ dig  tecmint.com +noadditional 
2   
3 ; < >< DiG 9.9.2-P1 < >< tecmint.com +noadditional
4 ;; global options: +cmd
5 ;; Got answer:
6 ;; -<
关闭 统计块
1 [avishek@tecmint ~]$ digtecmint.com +nostats 
2   
3 ; < >< DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6 < >< tecmint.com +nostats 
4 ;; global options: +cmd 
5 ;; Got answer: 
6 ;; -<
关闭回复块
1 [avishek@tecmint ~]$ digtecmint.com +noanswer 
2   
3 ; < >< DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6 < >< tecmint.com +noanswer 
4 ;; global options: +cmd 
5 ;; Got answer: 
6 ;; -<
关闭所有块
1 [avishek@tecmint ~]$ digtecmint.com +noall 
2   
3 ; < >< DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6 < >< tecmint.com +noall 
4 ;; global options: +cmd

阅读更多

 

24.命令: uptime

你连接到你的 Linux 服务器时发现一些不寻常或恶意的东西,你会做什么?猜测......不,绝不!你可以运行uptime来验证当服务器无人值守式到底发生了什么事情。

1 [avishek@tecmint ~]$ uptime
2   
3 14:37:10 up  4:21,  2 users,  load average: 0.00, 0.00, 0.04

25. 命令: wall

对系统管理员来说一个最重要的命令.wall发送一条消息到大家登录端将其 mesg 权限设置为"yes"。这条信息可以被wall作为参数,或者可以将它作为wall的标准输入。

1 [avishek@tecmint ~]$ wall "we will be going down for maintenance for one hour sharply at 03:30 pm"
2   
3 Broadcast message from root@localhost.localdomain (pts/0) (Sat Jun 29 14:44:02 2013): 
4   
5 we will be going down formaintenance forone hour sharply at 03:30 pm
 

26. 命令: mesg

其他人们可以使用"wtrite"命令,将在在向您发送文本到屏幕上。你可以控制是否显示。

1 mesg [n|y] n - prevents the message from others popping up on the screen. y – Allows messages to appear on your screen.

27. 命令: write

如果 'mesg' 是 'y',让你的文本直接发送到另一台 Linux 机器的屏幕。.

1 [avishek@tecmint ~]$ write ravisaive

28. 命令: talk

增强的write命令,talk命令可让你与其他登录的用户交谈。

1 [avishek@tecmint ~]$ talk ravisaive

注释: 如果 talk 命令没安装的话,可以通过apt 或yum 安装所需的包.

1 [avishek@tecmint ~]$ yum installtalk
2 OR
3 [avishek@tecmint ~]$ apt-get installtalk
 

29. 命令:w

是否觉得命令'w'很滑稽?但是事实上不是的。它是一个命令,尽管只有一个字符长!命令"w"是uptimewho命令,以前后的顺序组合在一起。

1 [avishek@tecmint ~]$ w
2   
3 15:05:42 up  4:49,  3 users,  load average: 0.02, 0.01, 0.00 
4 USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT 
5 server   tty7     :0               14:06    4:43m  1:42   0.08s pam: gdm-passwo 
6 server   pts/0    :0.0             14:18    0.00s  0.23s  1.65s gnome-terminal 
7 server   pts/1    :0.0             14:47    4:43   0.01s  0.01s bash

30. 命令: rename

见名知意,这个命令重命名文件。rename将会通过从文件名的首字符开始替换,重命名为指定的文件名。

1 Give the filenames a1, a2, a3, a4.....1213

仅仅写这些命令:[@Lesus 注: 在Ubuntu上不支持这种格式, rename与mv不同的是,rename可以批量修改,如同带了while的mv操作。]

1 rename a1 a0 a?
2 rename a1 a0 a??
 

31. 命令: top

显示CPU进程信息。这个命令自动刷新,默认是持续显示CPU进程信息,除非使用了中断指令。

01 [avishek@tecmint ~]$ top
02   
03 top- 14:06:45 up 10 days, 20:57,  2 users,  load average: 0.10, 0.16, 0.21
04 Tasks: 240 total,   1 running, 235 sleeping,   0 stopped,   4 zombie
05 %Cpu(s):  2.0 us,  0.5 sy,  0.0 ni, 97.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
06 KiB Mem:   2028240 total,  1777848 used,   250392 free,    81804 buffers
07 KiB Swap:  3905532 total,   156748 used,  3748784 free,   381456 cached
08   
09   PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+ COMMAND                                                                                                            
10 23768 ravisaiv  20   0 1428m 571m  41m S   2.3 28.9  14:27.52 firefox                                                                                                            
11 24182 ravisaiv  20   0  511m 132m  25m S   1.7  6.7   2:45.94 plugin-containe                                                                                                    
12 26929 ravisaiv  20   0  5344 1432  972 R   0.7  0.1   0:00.07 top                                                                                                                
13 24875 ravisaiv  20   0  263m  14m  10m S   0.3  0.7   0:02.76 lxterminal                                                                                                         
14     1 root      20   0  3896 1928 1228 S   0.0  0.1   0:01.62 init                                                                                                               
15     2 root      20   0     0    0    0 S   0.0  0.0   0:00.06 kthreadd                                                                                                           
16     3 root      20   0     0    0    0 S   0.0  0.0   0:17.28 ksoftirqd/0                                                                                                        
17     5 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kworker/0:0H                                                                                                       
18     7 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kworker/u:0H                                                                                                       
19     8 root      rt   0     0    0    0 S   0.0  0.0   0:00.12 migration/0                                                                                                        
20     9 root      20   0     0    0    0 S   0.0  0.0   0:00.00 rcu_bh                                                                                                             
21    10 root      20   0     0    0    0 S   0.0  0.0   0:26.94 rcu_sched                                                                                                          
22    11 root      rt   0     0    0    0 S   0.0  0.0   0:01.95 watchdog/0                                                                                                         
23    12 root      rt   0     0    0    0 S   0.0  0.0   0:02.00 watchdog/1                                                                                                         
24    13 root      20   0     0    0    0 S   0.0  0.0   0:17.80 ksoftirqd/1                                                                                                        
25    14 root      rt   0     0    0    0 S   0.0  0.0   0:00.12 migration/1                                                                                                        
26    16 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kworker/1:0H                                                                                                       
27    17 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 cpuset                                                                                                             
28    18 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 khelper                                                                                                            
29    19 root      20   0     0    0    0 S   0.0  0.0   0:00.00 kdevtmpfs                                                                                                          
30    20 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 netns                                                                                                              
31    21 root      20   0     0    0    0 S   0.0  0.0   0:00.04 bdi-default                                                                                                        
32    22 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kintegrityd                                                                                                        
33    23 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kblockd                                                                                                            
34    24 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 ata_sff

另查看  ·[@Lesus 注:htop比top命令更好用,不过需要自己安装
]

32. 命令: mkfs.ext4

这个命令在指定的设备上创建一个新的ext4文件系统,如果这个命令后面跟的是个错误的设备,那么整个设备就会被擦除和格式化,所以建议不要运行这个命令,除非你清楚自己正在干什么。

1 Mkfs.ext4 /dev/sda1 (sda1 block will be formatted)
2 mkfs.ext4 /dev/sdb1 (sdb1 block will be formatted)

更多查看:

33. 命令: rsync

Rsync复制文件,参数-P开启进度条。如果你已经安装了rsync,你可以使用一个简单的别名。

1 aliascp='rsync -aP'

现在尝试在终端复制一个大文件,这样将会看到显示剩余部分的输出,与进度条类似。

而且,保持和维护备份是系统管理员不得不做的最重要、最无聊的工作之一。Rsync是一个用于新建和维护备份的非常好用的终端工具(也存在许多其它工具)。

1 [avishek@tecmint ~]$ rsync-zvr IMG_5267\ copy\=33\ copy\=ok.jpg ~/Desktop/ 
2   
3 sending incremental filelist 
4 IMG_5267 copy=33 copy=ok.jpg 
5   
6 sent 2883830 bytes  received 31 bytes  5767722.00 bytes/sec 
7 total size is 2882771  speedup is 1.00

注意: -z表示压缩, -v表示详细信息,-r表示递归。

 

34. 命令: free

跟踪内存的使用和资源一样重要,就像管理员执行的任何其它任务,可以使用 'free' 命令来在这里救援.

当前内存使用状态Current Usage Status of Memory
1 [avishek@tecmint ~]$ free
2   
3              total       used       free     shared    buffers     cached
4 Mem:       2028240    1788272     239968          0      69468     363716
5 -/+ buffers/cache:    1355088     673152
6 Swap:      3905532     157076    3748456
设置输出单位为KB,MB或GB
1 [avishek@tecmint ~]$ free-b
2   
3              total       used       free     shared    buffers     cached
4 Mem:    2076917760 1838272512  238645248          0   71348224  372670464
5 -/+ buffers/cache: 1394253824  682663936
6 Swap:   3999264768  160845824 3838418944
1 [avishek@tecmint ~]$ free-k
2   
3              total       used       free     shared    buffers     cached
4 Mem:       2028240    1801484     226756          0      69948     363704
5 -/+ buffers/cache:    1367832     660408
6 Swap:      3905532     157076    3748456
1 [avishek@tecmint ~]$ free-m
2   
3              total       used       free     shared    buffers     cached
4 Mem:          1980       1762        218          0         68        355
5 -/+ buffers/cache:       1338        641
6 Swap:         3813        153       3660
1 [avishek@tecmint ~]$ free-g
2   
3              total       used       free     shared    buffers     cached
4 Mem:             1          1          0          0          0          0
5 -/+ buffers/cache:          1          0
6 Swap:            3          0          3
以可读的格式显示,检查当前内存使用
1 [avishek@tecmint ~]$ free-h
2   
3              total       used       free     shared    buffers     cached
4 Mem:          1.9G       1.7G       208M         0B        68M       355M
5 -/+ buffers/cache:       1.3G       632M
6 Swap:         3.7G       153M       3.6G
设定时间间隔,持续检查使用状态
01 [avishek@tecmint ~]$ free-s 3
02   
03              total       used       free     shared    buffers     cached
04 Mem:       2028240    1824096     204144          0      70708     364180
05 -/+ buffers/cache:    1389208     639032
06 Swap:      3905532     157076    3748456
07   
08              total       used       free     shared    buffers     cached
09 Mem:       2028240    1824192     204048          0      70716     364212
10 -/+ buffers/cache:    1389264     638976
11 Swap:      3905532     157076    3748456

阅读更多

 

35. mysqldump 命令

好了,现在你从名字上就能明白这个命令所代表的作用。mysqldump 命令会转储(备份)数据库的全部或特定一部分数据到一个给定的文件中。例如:

1 [avishek@tecmint ~]$ mysqldump -u root -p --all-databases < /home/server/Desktop/backupfile.sql

注意:mysqldump 需要 mysql 在运行中并且有正确的授权密码。我们在 中讨论了一些有用的 “mysqldump” 命令用法。

 

36. mkpasswd 命令

根据指定的长度,产生一个难猜的随机密码。

1 [avishek@tecmint ~]$ mkpasswd -l 10
2   
3 zI4+Ybqfx9
1 [avishek@tecmint ~]$ mkpasswd -l 20 
2   
3 w0Pr7aqKk&hmbmqdrlmk

注意:-l 10 产生一个10个字符的随机密码,而-l 20 产生 20个字符的密码,它可以设置为任意长度来取得所希望的结果。这个命令很有用,经常在脚本语言里使用来产生随机的密码。你可能需要 yumapt ‘expect’ 包来使用这个命令。

1 [avishek@tecmint ~]$ yum installexpect 
2
3 [avishek@tecmint ~]$ apt-get installexpect
 

37. Command: paste

合并两个或多个文本文件,按行来进行合并。示例。如果 file1 的内容是:

01
02
03
04   
05 file2 是这样的: 
06   
07
08
09
10 d
11
[avishek@tecmint ~]$ pastefile1 file2 < file3
12
13 结果file3将是: 
14 1    a 
15 2    b 
16 3    c 
17      d

38.Command: lsof

lsof 是"list open files("列表中打开的文件") 的缩写,显示您的系统当前已打开的所有文件。这是非常有用的对于想找出哪些进程使用某一特定文件,或显示为单个进程打开所有文件。一些有用的 ,你可能会感兴趣阅读。

01 [avishek@tecmint ~]$ lsof 
02   
03 COMMAND     PID   TID            USER   FD      TYPE     DEVICE SIZE/OFF       NODE NAME
04 init          1                  root  cwd       DIR        8,1     4096          2 /
05 init          1                  root  rtd       DIR        8,1     4096          2 /
06 init          1                  root  txt       REG        8,1   227432     395571 /sbin/init
07 init          1                  root  mem       REG        8,1    47080     263023 /lib/i386-linux-gnu/libnss_files-2.17.so
08 init          1                  root  mem       REG        8,1    42672     270178 /lib/i386-linux-gnu/libnss_nis-2.17.so
09 init          1                  root  mem       REG        8,1    87940     270187 /lib/i386-linux-gnu/libnsl-2.17.so
10 init          1                  root  mem       REG        8,1    30560     263021 /lib/i386-linux-gnu/libnss_compat-2.17.so
11 init          1                  root  mem       REG        8,1   124637     270176 /lib/i386-linux-gnu/libpthread-2.17.so
12 init          1                  root  mem       REG        8,1  1770984     266166 /lib/i386-linux-gnu/libc-2.17.so
13 init          1                  root  mem       REG        8,1    30696     262824 /lib/i386-linux-gnu/librt-2.17.so
14 init          1                  root  mem       REG        8,1    34392     262867 /lib/i386-linux-gnu/libjson.so.0.1.0
15 init          1                  root  mem       REG        8,1   296792     262889 /lib/i386-linux-gnu/libdbus-1.so.3.7.2
16 init          1                  root  mem       REG        8,1    34168     262840 /lib/i386-linux-gnu/libnih-dbus.so.1.0.0
17 init          1                  root  mem       REG        8,1    95616     262848 /lib/i386-linux-gnu/libnih.so.1.0.0
18 init          1                  root  mem       REG        8,1   134376     270186 /lib/i386-linux-gnu/ld-2.17.so
19 init          1                  root    0u      CHR        1,3      0t0       1035 /dev/null
20 init          1                  root    1u      CHR        1,3      0t0       1035 /dev/null
21 init          1                  root    2u      CHR        1,3      0t0       1035 /dev/null
22 init          1                  root    3r     FIFO        0,8      0t0       1714 pipe
23 init          1                  root    4w     FIFO        0,8      0t0       1714 pipe
24 init          1                  root    5r     0000        0,9        0       6245 anon_inode
25 init          1                  root    6r     0000        0,9        0       6245 anon_inode
26 init          1                  root    7u     unix 0xf5e91f80      0t0       8192 @/com/ubuntu/upstart
27 init          1                  root    8w      REG        8,1     3916        394 /var/log/upstart/teamviewerd.log.1 (deleted)
阅读(3104) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~