转载自 http://www.oschina.net/translate/20-advanced-commands-for-middle-level-linux-users

21. 命令: Find

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

root@tecmint:~# find -name *.sh

./Desktop/load.sh

./Desktop/test.sh

./Desktop/shutdown.sh

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

./Desktop/load.sh

./Desktop/test.sh

./Desktop/shutdown.sh

root@tecmint:~# find -name *.tar.gz

/var/www/modules/update/tests/aaa_update_test.tar.gz

./var/cache/flashplugin-nonfree/install_flash_player_11_linux.i386.tar.gz

22. 命令: grep

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

root@tecmint:~# grep tecmint /etc/passwd

tecmint:x:1000:1000:Tecmint,,,:/home/tecmint:/bin/bash

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

root@tecmint:~# grep -i TECMINT /etc/passwd

tecmint:x:1000:1000:Tecmint,,,:/home/tecmint:/bin/bash

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

root@tecmint:~# grep -r "127.0.0.1" /etc/

/etc/vlc/lua/http/.hosts:127.0.0.1

/etc/speech-dispatcher/modules/ivona.conf:#IvonaServerHost "127.0.0.1"

/etc/mysql/my.cnf:bind-address      = 127.0.0.1

注意:您还可以使用以下选项:
  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).

23. 命令: man

man‘是系统帮助页。Man提供命令所有选项及用法的在线文档。几乎所有的命令都有它们的帮助页,例如:

root@tecmint:~# man man

注意:系统帮助页是为了命令的使用和学习而设计的。

24. 命令: ps

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

root@tecmint:~# ps

PID TTY          TIME CMD

4170 pts/1    00:00:00bash

9628 pts/1    00:00:00ps

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

root@tecmint:~# ps -A

  PID TTY          TIME CMD

   1  ?        00:00:01 init

   2  ?        00:00:00 kthreadd

   3  ?        00:00:01 ksoftirqd/0

   5  ?        00:00:00 kworker/0:0H

   7  ?        00:00:00 kworker/u:0H

   8  ?        00:00:00 migration/0

   9  ?        00:00:00 rcu_bh

....

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

root@tecmint:~# ps -A | grep -i ssh

1500 ?        00:09:58 sshd

4317 ?        00:00:00 sshd

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

25. 命令: kill

kill是用来杀死已经无关紧要或者没有响应的进程.

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

root@tecmint:~# ps -A | grep -i apache2

1285 ?        00:00:00 apache2

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

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

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

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

root@tecmint:~# pkill apache2

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

26. 命令: whereis

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

root@tecmint:~# whereis ls

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

kill: /bin/kill/usr/share/man/man2/kill.2.gz /usr/share/man/man1/kill.1.gz

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

27. 命令: service

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

在Ubuntu上启动apache2 server:

root@tecmint:~# service apache2 start

 * Starting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 forServerName httpd (pid 1285) already running [ OK ]

重启apache2 server:

root@tecmint:~# service apache2 restart

* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName ... waiting .
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1forServerName [ OK ]

停止apache2 server:

root@tecmint:~# service apache2 stop

 * Stopping web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 forServerName ... waiting [ OK ]

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

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

28. 命令: alias

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

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

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

试试它是否能用:

root@tecmint:~# l

total 36

drwxr-xr-x 3 tecmint tecmint 4096 May 10 11:14 Binary

drwxr-xr-x 3 tecmint tecmint 4096 May 21 11:21 Desktop

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

root@tecmint:~# unalias l

再试试:

root@tecmint:~# l

bash: l: command not found

29.命令: df

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

root@tecmint:~# df

df’命令的更多例子请参阅 12 df Command Examples in Linux.

30. 命令: du

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

root@tecmint:~# du

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

Linux 环境下的一些常用命令(三)的更多相关文章

  1. git在windows及linux环境下安装及常用命令

    git在windows下安装 下载地址:https://git-scm.com/ 默认安装即可 验证 git --version git在linux下安装 下载地址:https://mirrors.e ...

  2. Linux 操作系统下 VI 编辑器常用命令详细介绍

    一.Vi 简介 vi是unix世界中最通用的全屏编辑器,linux中是用的是vi的加强版vim,vim同vi完全兼容,vi就是"visual interface"的缩写.它可以执行 ...

  3. Linux环境上,Oracle常用命令

    1.启动oracle数据库: //切换至Oracle用户: [root@server36 ~]# su - oracle //进入sqlplus环境,nolog参数表示不登录: [oracle@ser ...

  4. Linux环境下安装配置vsftpd服务(三种认证模式)

    一.FTP简介 文件传输协议(英文:File Transfer Protocol,缩写:FTP)是用于在网络上进行文件传输的一套标准协议.它工作于网络传输协议的应用层,使用客户/服务器模式,主要是用来 ...

  5. windows环境下,kafka常用命令

    创建topics kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partition 3 - ...

  6. Linux 环境下 jar 加解密命令?

    1.源码打jar包 jar -cvf demo-source.jar -C src/ . > log.txt 2.编译字节打jar包 jar -cvf demo-class.jar -C bin ...

  7. Linux环境下实现对文件读写操作

    ---- 今天分享一下在linux系统在实现对文件读写一些基本的操作,在这之前我们要掌握一些基本的技能在Linux环境下.比如查看命令和一个函数的具体用法,就是相当于查手册,在Linux下有一个man ...

  8. Linux 环境下一些常用命令(四)

    转自 http://www.oschina.net/translate/20-advanced-commands-for-middle-level-linux-users 31. 命令: rm 'rm ...

  9. PHP 命令行模式实战之cli+mysql 模拟队列批量发送邮件(在Linux环境下PHP 异步执行脚本发送事件通知消息实际案例)

    源码地址:https://github.com/Tinywan/PHP_Experience 测试环境配置: 环境:Windows 7系统 .PHP7.0.Apache服务器 PHP框架:ThinkP ...

随机推荐

  1. servlet之隐藏域

    隐藏域的实现, 商品对象 package app02b;public class Customer {        private int id;    private String name;   ...

  2. HTML5 AJAX跨域请求

    HTML5新的标准中,增加了" Cross-Origin Resource Sharing"特性,这个特性的出现使得跨域通信只需通过配置http协议头来即可解决. Cross-Or ...

  3. Ubuntu系统安装Pyenv

    安装Pyenv curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | ...

  4. 剥掉层层外衣后的RPC是什么样子的?

    RPC,全称为Remote Procedure Call(远程过程调用).通俗一点讲就是在本地调用远程服务器上的功能.实现远程调用至少需要满足以下几个条件: 1.网络通信 2.序列化与反序列化 3.反 ...

  5. [WC 2006]水管局长数据加强版

    Description SC省MY市有着庞大的地下水管网络,嘟嘟是MY市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可能要将一定量的水从x处送往y处,嘟嘟需要为供水公司找到一 ...

  6. [Vijos 1143]三取方格数

    Description 设有N*N的方格图,我们将其中的某些方格填入正整数, 而其他的方格中放入0. 某人从图得左上角出发,可以向下走,也可以向右走,直到到达右下角. 在走过的路上,他取走了方格中的数 ...

  7. no zuo no die

    #include <iostream> #include <cstring> #include <cstdio> using namespace std; name ...

  8. 2-XOR-SAT

    [题目描述]SAT(Satisfiability,可满足性)问题是著名的 NP 完全问题,它的内容是:判断由有限个布尔变量及其“非”用“或”操作连接起来的表达式组是否可以都为 TRUE.2-SAT 问 ...

  9. bzoj4710: [Jsoi2011]分特产 组合+容斥

    4710: [Jsoi2011]分特产 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 289  Solved: 198[Submit][Status] ...

  10. 求n的阶乘

    import java.util.Scanner; public class J {  public static void main(String args[])  {   //注释:int n=6 ...