设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 技术文摘 查看内容

对中级 Linux 用户非常有用的 20 个命令

2013-8-12 10:11| 发布者: 红黑魂| 查看: 4852| 评论: 0|来自: 开源中国编译

摘要:   也许你已经发现第一篇文章非常的有用,这篇文章是继对初级Linux用户非常有用的20个命令的一个延伸。第一篇文章的目的是为新手准备的而这篇文章则是为了Linux的中高级用户。在这里你将学会如何进行自定义搜索,知 ...

26. 命令: whereis

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

的二进制文件/资源以及帮助页:

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

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


27. 命令: service

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

开启、停止或者重启某个服务。

在Ubuntu上启动apache2 server:

1root@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
4httpd (pid 1285) already running                        [ OK ]

重启apache2 server:

1root@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:

1root@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”.


28. 命令: alias

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

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

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

试试它是否能用:

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

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

1root@tecmint:~# unalias l

再试试:

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

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

1alias cd='ls -l' (set alias of ls -l to cd)
2alias su='pwd' (set alias of pwd to su)
3....
4(You can create your own)
5....

想想多么有趣,现在如果你的朋友敲入‘cd'命令,当他看到的是目录文件列表而不是改变目录;

当他试图用’su‘命令时,他会进入当前目录。你可以随后去掉别名,向他解释以上情况。


29.命令: df

报告系统的磁盘使用情况。在跟踪磁盘使用情况方面对于普通用户和系统管理员都很有用。 ‘df‘ 通过检查目

录大小工作,但这一数值仅当文件关闭时才得到更新。

01root@tecmint:~# df
02 
03Filesystem     1K-blocks    Used Available Use% Mounted on
04/dev/sda1       47929224 7811908  37675948  18% /
05none                   4       0         4   0% /sys/fs/cgroup
06udev             1005916       4   1005912   1% /dev
07tmpfs             202824     816    202008   1% /run
08none                5120       0      5120   0% /run/lock
09none             1014120     628   1013492   1% /run/shm
10none              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’命令的更多例子请参阅 12 df Command Examples in Linux.

30. 命令: du

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

01root@tecmint:~# du
02 
038       ./Daily Pics/wp-polls/images/default_gradient
048       ./Daily Pics/wp-polls/images/default
0532      ./Daily Pics/wp-polls/images
068       ./Daily Pics/wp-polls/tinymce/plugins/polls/langs
078       ./Daily Pics/wp-polls/tinymce/plugins/polls/img
0828      ./Daily Pics/wp-polls/tinymce/plugins/polls
0932      ./Daily Pics/wp-polls/tinymce/plugins
1036      ./Daily Pics/wp-polls/tinymce
11580     ./Daily Pics/wp-polls
121456    ./Daily Pics
1336      ./Plugins/wordpress-author-box
1416180   ./Plugins
1512      ./May Articles 2013/Xtreme Download Manager
164632    ./May Articles 2013/XCache

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

10 du (Disk Usage) Commands.



酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部