转载自 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] Minimum Factorization 最小因数分解

    Given a positive integer a, find the smallest positive integer b whose multiplication of each digit ...

  2. css 的一些知识点的整理

    css的一些标签整理   background-attachment: scroll;背景图可滚动 background-attachment: fixed; 固定背景的位置,不随着滚动条移动而移动 ...

  3. [USACO15OPEN]回文的路径Palindromic Paths 2.0版

    题目描述 农夫FJ的农场是一个N*N的正方形矩阵(2\le N\le 5002≤N≤500),每一块用一个字母作标记.比如说: ABCD BXZX CDXB WCBA 某一天,FJ从农场的左上角走到右 ...

  4. bzoj 2212: [Poi2011]Tree Rotations

    Description Byteasar the gardener is growing a rare tree called Rotatus Informatikus. It has some in ...

  5. [Codeforces]906D Power Tower

    虽说是一道裸题,但还是让小C学到了一点姿势的. Description 给定一个长度为n的数组w,模数m和询问次数q,每次询问给定l,r,求: 对m取模的值. Input 第一行两个整数n,m,表示数 ...

  6. Codeforces Round #398 (div.2)简要题解

    这场cf时间特别好,周六下午,于是就打了打(谁叫我永远1800上不去div1) 比以前div2的题目更均衡了,没有太简单和太难的...好像B题难度高了很多,然后卡了很多人. 然后我最后做了四题,E题感 ...

  7. [Codeforces]605E Intergalaxy Trips

    小C比较棘手的概率期望题,感觉以后这样的题还会贴几道出来. Description 给定一个n*n的邻接矩阵,邻接矩阵中元素pi,j表示的是从 i 到 j 这条单向道路在这一秒出现的概率百分比,走一条 ...

  8. Python中tuple的功能介绍

    Tuple的功能介绍 1. 元祖的两种方法 1. 元祖的内置方法 两个元祖的相加 格式:x.__add__(y)等同于x+y 例如:tu1 = (1,2,3,) print(tu1.__add__(( ...

  9. Cisco 关闭命令同步提示信息

    Router(config)#no logging console 如果你通过console连接,使用第一条Router(config)#no logging monitor 如果通过telnet,s ...

  10. VMWare - Ubuntu 64 (16.04)之扩容介绍

    背景 貌似是一个老生常谈的问题哈,由于自己之前也没有弄过,今天正好有时间稍微折腾了一下. 这里就选择最简单的方式来为大家呈现. VMWare 的设置 没有什么可以过多说的,完全是图形操作.这里直接上图 ...