20 Advanced Commands for Middle Level Linux Users_工程师WWW的博客-程序员宅基地

技术标签: linux系统  

You might have found the first article very much useful, this article is an extension of the 20 Useful Commands for Linux Newbies. The first article was intended for newbies and this article is for Middle-Level-User and Advanced Users. Here you will find how to customise search, know the processes running guide to kill them, how to make your Linux terminal productive is an important aspect and how to compile cc++java programs in nix.

Linux Advanced & Expert Commands

20 Linux Advanced & Expert Commands

21. Command: Find

Search for files in the given directory, hierarchically starting at the parent directory and moving to sub-directories.

[email protected]:~# find -name *.sh 


Note: The `-name‘ option makes the search case sensitive. You can use the `-iname‘ option to find something regardless of case. (* is a wildcard and searches all the file having extension ‘.sh‘ you can use filename or a part of file name to customise the output).

[email protected]:~# find -iname *.SH ( find -iname *.Sh /  find -iname *.sH)

[email protected]:~# find -name *.tar.gz 


Note: The above command searches for all the file having extension ‘tar.gz‘ in root directory and all the sub-directories including mounted devices.

Read more examples of Linux ‘find‘ command at 35 Find Command Examples in Linux

22. Command: grep

The ‘grep‘ command searches the given file for lines containing a match to the given strings or words. Search ‘/etc/passwd‘ for ‘tecmint‘ user.

[email protected]:~# grep tecmint /etc/passwd 


Ignore word case and all other combination with ‘-i‘ option.

[email protected]:~# grep -i TECMINT /etc/passwd 


Search recursively (-ri.e. read all files under each directory for a string ““.

[email protected]:~# grep -r "" /etc/ 

/etc/speech-dispatcher/modules/ivona.conf:#IvonaServerHost ""
/etc/mysql/my.cnf:bind-address		=
/etc/apache2/mods-available/status.conf:    Allow from ::1
/etc/apache2/mods-available/ldap.conf:    Allow from ::1
/etc/apache2/mods-available/info.conf:    Allow from ::1
/etc/apache2/mods-available/proxy_balancer.conf:#    Allow from ::1
/etc/security/access.conf:#+ : root :
/etc/dhcp/dhclient.conf:#prepend domain-name-servers;
/etc/dhcp/dhclient.conf:#  option domain-name-servers;
/etc/init/network-interface.conf:	ifconfig lo up || true
/etc/java-6-openjdk/net.properties:# localhost &
/etc/java-6-openjdk/net.properties:# http.nonProxyHosts=localhost|
/etc/java-6-openjdk/net.properties:# localhost &
/etc/java-6-openjdk/net.properties:# ftp.nonProxyHosts=localhost|
/etc/hosts:	localhost

Note: You can use these following options along with grep.

  1. -w for word (egrep -w ‘word1|word2‘ /path/to/file).
  2. -c for count (i.e., total number of times the pattern matched) (grep -c ‘word‘ /path/to/file).
  3. –color for coloured output (grep –color server /etc/passwd).

23. Command: man

The ‘man‘ is the system’s manual pager. Man provides online documentation for all the possible options with a command and its usages. Almost all the command comes with their corresponding manual pages. For example,

[email protected]:~# man man

MAN(1)                                                               Manual pager utils                                                              MAN(1)

       man - an interface to the on-line reference manuals

       man  [-C  file]  [-d]  [-D]  [--warnings[=warnings]]  [-R  encoding]  [-L  locale]  [-m  system[,...]]  [-M  path]  [-S list] [-e extension] [-i|-I]
       [--regex|--wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P pager] [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justification]  [-p
       string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ...
       man -k [apropos options] regexp ...
       man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ...
       man -f [whatis options] page ...
       man -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] [-T[device]]
       [-H[browser]] [-X[dpi]] [-Z] file ...
       man -w|-W [-C file] [-d] [-D] page ...
       man -c [-C file] [-d] [-D] page ...
       man [-hV]

Manual page for man page itself, similarly ‘man cat‘ (Manual page for cat command) and ‘man ls‘ (Manual page for command ls).

Note: man page is intended for command reference and learning.

24. Command: ps

ps (Process) gives the status of running processes with a unique Id called PID.

[email protected]:~# ps

 PID TTY          TIME CMD
 4170 pts/1    00:00:00 bash
 9628 pts/1    00:00:00 ps

To list status of all the processes along with process id and PID, use option ‘-A‘.

[email protected]:~# 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

Note: This command is very useful when you want to know which processes are running or may need PID sometimes, for process to be killed. You can use it with ‘grep‘ command to find customised output. For example,

[email protected]:~# ps -A | grep -i ssh

 1500 ?        00:09:58 sshd
 4317 ?        00:00:00 sshd

Here ‘ps‘ is pipelined with ‘grep‘ command to find customised and relevant output of our need.

25. Command: kill

OK, you might have understood what this command is for, from the name of the command. This command is used to kill process which is not relevant now or is not responding. It is very useful command, rather a very very useful command. You might be familiar with frequent windows restarting because of the fact that most of the time a running process can’t be killed, and if killed it needs windows to get restart so that changes could be taken into effect but in the world of Linux, there is no such things. Here you can kill a process and start it without restarting the whole system.

You need a process’s pid (ps) to kill it.

Let suppose you want to kill program ‘apache2‘ that might not be responding. Run ‘ps -A‘ along with grep command.

[email protected]:~# ps -A | grep -i apache2

1285 ?        00:00:00 apache2

Find process ‘apache2‘, note its pid and kill it. For example, in my case ‘apache2‘ pid is ‘1285‘.

[email protected]:~# kill 1285 (to kill the process apache2)

Note: Every time you re-run a process or start a system, a new pid is generated for each process and you can know about the current running processes and its pid using command ‘ps‘.

Another way to kill the same process is.

[email protected]:~# pkill apache2

Note: Kill requires job id / process id for sending signals, where as in pkill, you have an option of using pattern, specifying process owner, etc.

26. Command: whereis

The ‘whereis‘ command is used to locate the BinarySources and Manual Pages of the command. For example, to locate the BinarySources and Manual Pages of the command ‘ls‘ and ‘kill‘.

[email protected]:~# whereis ls 

ls: /bin/ls /usr/share/man/man1/ls.1.gz
[email protected]:~# whereis kill

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

Note: This is useful to know where the binaries are installed for manual editing sometimes.

27. Command: service

The ‘service‘ command controls the StartingStopping or Restarting of a ‘service‘. This command make it possible to startrestart or stop a service without restarting the system, for the changes to be taken into effect.

Startting an apache2 server on Ubuntu

[email protected]:~# service apache2 start

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

Restarting a apache2 server on Ubuntu

[email protected]:~# service apache2 restart

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

Stopping a apache2 server on Ubuntu

[email protected]:~# service apache2 stop

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

Note: All the process script lies in ‘/etc/init.d‘, and the path might needs to be included on certain system, i.e., in spite of running “service apache2 start” you would be asked to run “service /etc/init.d/apache2 start”.

28. Command: alias

alias is a built in shell command that lets you assign name for a long command or frequently used command.

I uses ‘ls -l‘ command frequently, which includes 5 characters including space. Hence I created an alias for this to ‘l‘.

[email protected]:~# alias l='ls -l'

check if it works or not.

[email protected]:~# 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 
drwxr-xr-x 2 tecmint tecmint 4096 May 21 15:23 Documents 
drwxr-xr-x 8 tecmint tecmint 4096 May 20 14:56 Downloads 
drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Music 
drwxr-xr-x 2 tecmint tecmint 4096 May 20 16:17 Pictures 
drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Public 
drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Templates 
drwxr-xr-x 2 tecmint tecmint 4096 May  7 16:58 Videos

To remove alias ‘l‘, use the following ‘unalias‘ command.

[email protected]:~# unalias l

check, if ‘l‘ still is alias or not.

[email protected]:~# l

bash: l: command not found

Making a little fun out of this command. Make alias of certain important command to some other important command.

alias cd='ls -l' (set alias of ls -l to cd)
alias su='pwd' (set alias of pwd to su)
(You can create your own)

Now when your friend types ‘cd‘, just think how funny it would be when he gets directory listing and not directory changing. And when he tries to be ‘su‘ the all he gets is the location of working directory. You can remove the alias later using command ‘unalias‘ as explained above.

29. Command: df

Report disk usages of file system. Useful for user as well as System Administrator to keep track of their disk usages. ‘df‘ works by examining directory entries, which generally are updated only when a file is closed.

[email protected]:~# df

Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       47929224 7811908  37675948  18% /
none                   4       0         4   0% /sys/fs/cgroup
udev             1005916       4   1005912   1% /dev
tmpfs             202824     816    202008   1% /run
none                5120       0      5120   0% /run/lock
none             1014120     628   1013492   1% /run/shm
none              102400      44    102356   1% /run/user
/dev/sda5         184307   79852     94727  46% /boot
/dev/sda7       95989516   61104  91045676   1% /data
/dev/sda8       91953192   57032  87218528   1% /personal

For more examples of ‘df‘ command, read the article 12 df Command Examples in Linux.

30. Command: du

Estimate file space usage. Output the summary of disk usages by ever file hierarchically, i.e., in recursive manner.

[email protected]:~# du

8       ./Daily Pics/wp-polls/images/default_gradient
8       ./Daily Pics/wp-polls/images/default
32      ./Daily Pics/wp-polls/images
8       ./Daily Pics/wp-polls/tinymce/plugins/polls/langs
8       ./Daily Pics/wp-polls/tinymce/plugins/polls/img
28      ./Daily Pics/wp-polls/tinymce/plugins/polls
32      ./Daily Pics/wp-polls/tinymce/plugins
36      ./Daily Pics/wp-polls/tinymce
580     ./Daily Pics/wp-polls
1456    ./Daily Pics
36      ./Plugins/wordpress-author-box
16180   ./Plugins
12      ./May Articles 2013/Xtreme Download Manager
4632    ./May Articles 2013/XCache

Note: ‘df‘ only reports usage statistics on file systems, while ‘du‘, on the other hand, measures directory contents. For more ‘du‘ command examples and usage, read 10 du (Disk Usage) Commands.

31. Command: rm

The command ‘rm‘ stands for remove. rm is used to remove files (s) and directories.

Removing a directory

[email protected]:~# rm PassportApplicationForm_Main_English_V1.0

rm: cannot remove `PassportApplicationForm_Main_English_V1.0': Is a directory

The directory can’t be removed simply by ‘rm‘ command, you have to use ‘-rf‘ switch along with ‘rm‘.

[email protected]:~# rm -rf PassportApplicationForm_Main_English_V1.0

Warning: “rm -rf” command is a destructive command if accidently you make it to the wrong directory. Once you ‘rm -rf‘ a directory all the files and the directory itself is lost forever, all of a sudden. Use it with caution.

32. Command: echo

echo as the name suggest echoes a text on the standard output. It has nothing to do with shell, nor does shell reads the output of echo command. However in an interactive script, echo passes the message to the user through terminal. It is one of the command that is commonly used in scripting, interactive scripting.

[email protected]:~# echo "Tecmint.com is a very good website" 

Tecmint.com is a very good website
creating a small interactive script

1. create a file, named ‘interactive_shell.sh‘ on desktop. (Remember ‘.sh‘ extension is must).
2. copy and paste the below script, exactly same, as below.

echo "Please enter your name:" 
   read name 
   echo "Welcome to Linux $name"

Next, set execute permission and run the script.

[email protected]:~# chmod 777 interactive_shell.sh
[email protected]:~# ./interactive_shell.sh

Please enter your name:
Ravi Saive
Welcome to Linux Ravi Saive

Note: ‘#!/bin/bash‘ tells the shell that it is an script an it is always a good idea to include it at the top of script. ‘read‘ reads the given input.

33. Command: passwd

This is an important command that is useful for changing own password in terminal. Obviously you need to know your current passowrd for Security reason.

[email protected]:~# passwd 

Changing password for tecmint. 
(current) UNIX password: ******** 
Enter new UNIX password: ********
Retype new UNIX password: ********
Password unchanged   [Here was passowrd remians unchanged, i.e., new password=old password]
Enter new UNIX password: #####
Retype new UNIX password:#####

34. Command: lpr

This command print files named on command line, to named printer.

[email protected]:~# lpr -P deskjet-4620-series 1-final.pdf

Note: The ‘lpq‘ command lets you view the status of a printer (whether it’s up or not), and the jobs (files) waiting to be printed.

35. Command: cmp

compare two files of any type and writes the results to the standard output. By default, ‘cmp‘ Returns 0 if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported.

To provide examples for this command, lets consider two files:

[email protected]:~# cat file1.txt

Hi My name is Tecmint
[email protected]:~# cat file2.txt

Hi My name is tecmint [dot] com

Now, let’s compare two files and see output of the command.

[email protected]:~# cmp file1.txt file2.txt 

file1.txt file2.txt differ: byte 15, line 1

36. Command: wget

Wget is a free utility for non-interactive (i.e., can work in background) download of files from the Web. It supports HTTPHTTPSFTP protocols and HTTP proxies.

Download ffmpeg using wget

[email protected]:~# wget http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2

--2013-05-22 18:54:52--  http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2
Resolving downloads.sourceforge.net (downloads.sourceforge.net)...
Connecting to downloads.sourceforge.net (downloads.sourceforge.net)||:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://kaz.dl.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 [following]
--2013-05-22 18:54:54--  http://kaz.dl.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2
Resolving kaz.dl.sourceforge.net (kaz.dl.sourceforge.net)...
Connecting to kaz.dl.sourceforge.net (kaz.dl.sourceforge.net)||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 275557 (269K) [application/octet-stream]
Saving to: ‘ffmpeg-php-0.6.0.tbz2’

100%[===========================================================================>] 2,75,557    67.8KB/s   in 4.0s   

2013-05-22 18:55:00 (67.8 KB/s) - ‘ffmpeg-php-0.6.0.tbz2’ saved [275557/275557]

37. Command: mount

Mount is an important command which is used to mount a filesystem that don’t mount itself. You need root permission to mount a device.

First run ‘lsblk‘ after plugging-in your filesystem and identify your device and note down you device assigned name.

[email protected]:~# lsblk 

sda      8:0    0 931.5G  0 disk 
├─sda1   8:1    0 923.6G  0 part / 
├─sda2   8:2    0     1K  0 part 
└─sda5   8:5    0   7.9G  0 part [SWAP] 
sr0     11:0    1  1024M  0 rom  
sdb      8:16   1   3.7G  0 disk 
└─sdb1   8:17   1   3.7G  0 part

From this screen it was clear that I plugged in a 4 GB pendrive thus ‘sdb1‘ is my filesystem to be mounted. Become a root to perform this operation and change to /dev directory where all the file system is mounted.

[email protected]:~# su
[email protected]:~# cd /dev

Create a directory named anything but should be relevent for reference.

[email protected]:~# mkdir usb

Now mount filesystem ‘sdb1‘ to directory ‘usb‘.

[email protected]:~# mount /dev/sdb1 /dev/usb

Now you can navigate to /dev/usb from terminal or X-windows system and acess file from the mounted directory.

Time for Code Developer to know how rich Linux environment is

38. Command: gcc

gcc is the in-built compiler for ‘c‘ language in Linux Environment. A simple c program, save it on ur desktop as Hello.c (remember ‘.c‘ extension is must).

#include <stdio.h>
int main()
  printf("Hello world\n");
  return 0;
Compile it
[email protected]:~# gcc Hello.c
Run it
[email protected]:~# ./a.out 

Hello world

Note: On compiling a c program the output is automatically generated to a new file “a.out” and everytime you compile a c program same file “a.out” gets modified. Hence it is a good advice to define a output file during compile and thus there is no risk of overwrite to output file.

Compile it this way
[email protected]:~# gcc -o Hello Hello.c

Here ‘-o‘ sends the output to ‘Hello‘ file and not ‘a.out‘. Run it again.

[email protected]:~# ./Hello 

Hello world

39. Command: g++

g++ is the in-built compiler for ‘C++‘ , the first object oriented programming language. A simplec++ program, save it on ur desktop as Add.cpp (remember ‘.cpp‘ extension is must).

#include <iostream>

using namespace std;

int main() 
          int a;
          int b;
          cout<<"Enter first number:\n";
          cin >> a;
          cout <<"Enter the second number:\n";
          cin>> b;
          int result = a + b;
          cout<<"Result is"<<"  "<<result<<endl;
          return 0;
Compile it
[email protected]:~# g++ Add.cpp
Run it
[email protected]:~# ./a.out

Enter first number: 

Note: On compiling a c++ program the output is automatically generated to a new file “a.out” and everytime you compile a c++ program same file “a.out” gets modified. Hence it is a good advice to define a output file during compile and thus there is no risk of overwrite to output file.

Compile it this way
[email protected]:~# g++ -o Add Add.cpp
Run it
[email protected]:~# ./Add 

Enter first number: 

40. Command: java

Java is one of the world’s highly used programming language and is considered fast, secure, and reliable. Most of the the web based service of today runs on java.

Create a simple java program by pasting the below test to a file, named tecmint.java(remember ‘.java‘ extension is must).

class tecmint {
  public static void main(String[] arguments) {
    System.out.println("Tecmint ");
compile it using javac
[email protected]:~# javac tecmint.java
Run it
[email protected]:~# java tecmint

Note: Almost every distribution comes packed with gcc compiler, major number of distros have inbuilt g++ and java compiler, while some may not have. You can apt or yum the required package.

Don’t forget to mention your valueable comment and the type of article you want to see here. I will soon be back with an interesting topic about the lesser known facts about Linux.

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。


Solidity 常用方法总结_wilson_go的博客-程序员宅基地

block中的方法block.blockhash(uint blockNumber) returns (bytes32):给定块的散列 - 仅适用于256个最近的块block.coinbase (address):当前块矿工的地址block.difficulty (uint):当前块难度block.gaslimit (uint):当前块gaslimitblock.number (uint...

NYOJ204Coin Test_weixin_34120274的博客-程序员宅基地

Coin Test时间限制:3000ms | 内存限制:65535KB难度:1描述As is known to all,if you throw a coin up and let it droped on the desk there are usually three results. Yes,just believe what I say ~it can...

身为C的超集—— 我这个当大哥的有话要说 o( ̄ヘ ̄o) 超级超级详细!!!_沉梦昂志__的博客-程序员宅基地



  10天没有写博客了,不知道为什么,心里感觉挺不舒服的,可能这是自己给自己规定要去完成的事情,没有按照计划执行,总会心里不怎么舒服。最近事情挺多的,终于今天抽空来更新一下博客了。  今天写的是一个小插件。平时我们习惯于使用javascript中自带的confirm()函数做出一个弹窗的效果,但是问题在于这样的弹窗非常不美观,大大降低了网页的整体效果。  好吧废话不多说,首先先来了解一下c...


李林 发自 凹非寺量子位 出品 | 公众号 QbitAI等了半年,百度自动驾驶系统Apollo新版本3.5终于要亮相了。下周,拉斯维加斯,百度将在美国最大的消费电子展CE...


https://hub.fastgit.org/PX4/PX4-Autopilotgit describe --tag 查看当前版本号git tag -l 查看所有版本,也就是打个taggit checkout v1.9.1 跳转到指定版本。注意这个地方不要加-b ,-b是创建新的分支。git checkout表示跳转分支。git log 可以查看当前位于哪个分支上git 中 branch 和 tag的使用,参考(git tag的使用)两者在功能上很类似,但是在使用上是不同的。Branch 是



本人小白一个,不能保证博客中内容都准确,如果博客中有错误的地方,望各位多多指教,请指正。上面的内容仅仅能解决本人遇到的错误,不一定适用于所有人,如有不适用,请多多包涵。问题 描述: 使用default-servlet-handler,只能通过url 访问静态资源,而无法在controller层访问静态资源。...

kotlin doc 之 类和继承_69Yuan的博客-程序员宅基地

类和继承类class Invoice{}类的声明包括 class关键字 类名 类头(第一构造函数) 类体。并且类头和类体是可以省略的class Empty构造函数在kotlin中,一个类有一个“第一”构造函数和多个“第二”构造函数。并且第一构造函数是类头的一部分,被放置在类名的后面。class Persion constructor(firstN...

Hadoop 2.7 安装和配置_爱好美食的尘的博客-程序员宅基地_hadoop2.7

内容一、安装规划二、安装准备1、检查节点的网络管理器2、使用下面的命令来验证网络管理器服务的状态:3、检查节点的IP地址4、设置节点的IP地址5、编辑网卡配置文件6、使配置文件生效7、检查网络互连三、关闭防火墙服务1、检查防火墙服务状态2、禁用并停止防火墙服务3、确认防火墙状态四、设置主机名1、修改主机名2、修改hosts文件五、设置免密登录1、配置SSH免密登录2、为root用户生成证书3、在master节点上合并公钥4、检查合并生成的authorized_ keys文件5、复制authorized_ k


python机器学习——决策树1、概念决策树(DEcision Tree)他通过对训练样本的学习,并建立分类规则,对新样本数据进行分类,属于有监督学习决策树也是一种多功能的机器学习算法,它可以实现分类和回归任务,甚至是多输出任务。优点:决策树易于理解和实现决策树可处理数值型和非数值型数据2 决策树生成方法dtModel=DecisionTreeClassifier(max_leaf_nodes=None)max_leaf_nodes 最大的叶子节点数训练模型dtMOdel.fit(

mysql数据库创建数据表语法_若圆之意的博客-程序员宅基地_mysql 创建数据库表语法

create table blog_user( user_Name char(15) not null check(user_Name !=''), user_Password char(15) not null, user_emial varchar(20) not null unique, primary key(user_Name) )engine=


using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;using Excel = Microsoft.Office.Interop.Excel;using System.Diagnos...