转载自 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. [LeetCode] IPO 上市

    Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Cap ...

  2. 做了两年多salesforce平台开发,转Java的经历

    2015年毕业,转眼已经三年多了.三年对于现在的我,真的很快,一开始对软件开发的执着一直没有变.我是一个很普通很普通长沙的一个专科毕业.刚进大学,对于软件开发真的是小白,仅仅只是存在对于游戏,和桌面软 ...

  3. [Luogu 3768]简单的数学题

    Description 输入一个整数n和一个整数p,你需要求出$(\sum_{i=1}^n\sum_{j=1}^n ijgcd(i,j))~mod~p$,其中gcd(a,b)表示a与b的最大公约数. ...

  4. BZOJ3129: [Sdoi2013]方程

    拓展Lucas+容斥原理 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cs ...

  5. C++Primer学习——各种运算符

    前缀递增和后缀递增 class NewInt { public: NewInt():RootInt(0){}; NewInt(int IniInt):RootInt(IniInt){}; NewInt ...

  6. 浅谈MySQL中优化sql语句查询常用的30种方法

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索 ...

  7. Linux(CentOs6.3)网络配置

    新装好的虚拟机往往还无法连接网络,本文描述了如何在CentOs6.3系统上配置网络信息 1.windows系统下快捷键windows+r,输入cmd并确定,打开黑窗口 2.黑窗口中输入ipconfig ...

  8. PySC2是DeepMind的“星际争霸II学习环境”(SC2LE)的Python组件

    PySC2是DeepMind的"星际争霸II学习环境"(SC2LE)的Python组件. 它暴露了暴雪娱乐公司的星际争霸II机器学习API作为Python RL环境. 这是Deep ...

  9. SQL Server 2008 维护计划实现数据库备份(最佳实践)

    一.背景 之前写过一篇关于备份的文章:SQL Server 维护计划实现数据库备份,上面文章使用完整备份和差异备份基本上能解决数据库备份的问题,但是为了保障数据更加安全,我们需要再次完善我们的备份计划 ...

  10. three.js 3D 动画场景

    Three.js 是一款运行在浏览器中的 3D 引擎,你可以用它创建各种三维场景,包括了摄影机.光影.材质等各种对象.使用它它能让 WebGL 变得更加简单. 下面用Three.js渲染一个物体360 ...