非常不错的 linux 技巧(推荐)

原贴:http://ubuntu.guoshuang.com/2008/02/04/%E9%9D%9E%E5%B8%B8%E4%B8%8D%E9%94%99%E7%9A%84-linux-%E6%8A%80%E5%B7%A7%EF%BC%88%E6%8E%A8%E8%8D%90%EF%BC%89/

非常不错的 linux 技巧(推荐)

Posted 8 months, 1 week ago at 11:32 am. 0 comments

ad 468x60

原文来自 Hot tips to get the best of Linux in 2008,很有趣也比较复杂(对我来说),所以看了几天才转过来:

1. Avoid out of the session or close the terminal with the command Ctrl+D

Ctr+D 退出终端

* set -o ignoreeof Enable Ctrl+D
* set +o ignoreeof Disable Ctrl+D

2. The Alias — We introduce a command with an alias, and the shell will recode it with its value. For example, whether we define an alias this way: alias buscar=”find. -name”, when we input commands in the line buscar name_file the shell will execute find. -name name_file and will seek the file we ask starting in the current path.
Alias name_of_the_alias=”command_which_will_execute_the_alias”.

使用 alias 别名。比如终端输入

alias ls

显示

alias ls=’ls –color=auto’

这就是说我们默认的 ls 就被加入了颜色参数。

再比如终端输入

alias buscar=”find. -name”

然后

buscar XXX

这个命令就等于

find . -name XXX

To disable an alias use the command unalias:unalias name_of_de_alias. If you want to see the alias defined in the system just write: alias.

去掉别名用

unalias buscar

3. Most recently used commands — Execute the following instruction in the console:

history|awk ‘{print $2}’|awk ‘BEGIN {FS=”|”} {print $1}’|sort|uniq -c|sort -rn|head -10

方向键控制命令的历史记录貌似默认就有啊?不理解。

The history command shows a list of all recently executed commands. You can use the arrow keys to navigate the next and previous commands.

Tux4. Kill all the process in a determined application — This command will be very useful when you are running programs which tend to drag on the system resources. Open terminal and type: ps aux c. It will show you a complete list of running processes.?The first column contain the user owner of the process, the second one is the PID of the process and if we jump to the last column we will see the name of the application which belong to each processes. If the application you want to kill is, for example, Firefox, then it would be: ps aux c | grep firefox and then write kill -9. The next time you do a ps aux c | grep firefox, this program shouldn’t appear anymore.

显示和杀死进程

ps aux c

寻找 firefox 相关进程

ps aux c|grep firefox

杀死 pid XXX 的进程

kill -9 XXX

5. Get the basic system information — There are some commands you can use to determine basic information of your machine such as kernel version, hardware information and others. The following command lines shows what they’ll return when executed;

查看系统基本信息

$ cat /proc/version = “It returns a full string of information”
$ uname -m = “The result of the machine’s number”
$ uname -r = “Show the version of the kernel”
$ uname -n = “Returns the local domain name”
$ uname -s = “Will show the system name”
$ uname -p = “It tells you the type and name of the processor”
$ uname -a = “Will show all the information above and also the date and time of the system”

cat /proc/version 返回系统信息
uname -m 返回 “i686″等信息
uname -r 内核版本
uname -n 主机名
uname -s 系统名称,比如”linux”
uname -p 处理器类型和名称(我这里显示 “unknown”)
uname -a 所有 uname 信息

你还可以参考这篇日志:如何查看 ubuntu 版本信息

6. Use the Calendar — With the following commands you can have different views and displays of the Calendar in the different versions of Linux.

日历

cal -3 = “Simply display the calendar”
cal 1 2008 = “This command display a calendar of a particular month of the year”
date -d fri = “Display the date of the next on the current or next week”
date –date=’25 Dec’ +%A = “Tell you which day will be Christmas this year”

7. Disk Space — Having sufficient and optimized disc space is something vital for good performance of your system. In the case of Linux, here are the different ways to optimize your storage space and display information of your hard disc.

显示磁盘空间

df -h = “This command display the free disc space”
fdisk -l = “Very similar to Windows environment show you the partitions of the disc”
ls -lSr = “Display the all the files and the biggest last”
du -s * | sort -k1,1rn | head = “Show top disc users in the current directory”

df -h 显示剩余空间
sudo fdisk -l 显示磁盘分区、空间等
ls -lSr 显示文件列表,从打到小
du -s * | sort -k1,1rn | head 这句 Show top disc users in the current directory,我不敢翻译。

8. Set Operations — In Linux you can make operations with files quickly. Test the following commands which help you a lot to manipulate files.

文件操作

学习中…

LANG=C sort file1 file2 | uniq” = “Make the union of unsorted files”
LANG=C sort file1 file2 | uniq -d = “Intercept unsorted files”
LANG=C comm file1 file2 | sed ’s/^/t*//’ = “Union of sorted files”
LANG=C comm -3 file1 file2 | sed ’s/^/t*// = “Symmetric difference of sorted files”

9. Text Manipulation — Manipulation of text is another very important aspect of the work. Let’s see some of this in Linux.

sed 文本操作

学习中…

sed -n ’s/.*<//title>.*//1/ip;T;q’ = “Extract title from an HTML page”
sed -n ‘10,20p;20q’ = “Print lines from 10 to 20″
sed ‘:a; ///$/N; sn//; ta’ = “Concatenate lines between /”
sed ’s/[ /t]*$//’ = “Remove trailing spaces from lines”
sed ’s/string1/string2/g’ = “Replace string1 with string2″

10. Searching of Files — Faster method to search for almost anything under a Linux platform.

查找文件的一些命令

alias l=’ls -l –color=auto’page” = “Make a quick listing of directories”
ls -lrt = “List files by date”
find -name ‘*.[ch]‘ | xargs grep -E ‘expr’ “Search ‘expr’ in the current directory and below”
find -type f ! -perm -444 = “Find files not readable by all”
locate -r ‘file[^/]*/.txt’ = “Search cached index for names”

11. Frozen Windows — Sometimes you can have a frozen window, and there are two fast ways to solve this problem without turning off your computer or restarting it. First, you can try the traditional key combination of Ctrl + Alt + Backspace.

The other way is a little more complicated than the previous one but is more efficient. Hit Ctrl + Alt + F2 to jump to the virtual console. Then log in with your user name, password and type the following:
ps -ax | grep startx

This executed command will provide you the PID of your Xserver. Then kill it with the next command
kill -9 PID_Number

If you want return to your first console, just press Alt + F1.

如果 X windows 锁死(无响应),处理办法有二

1.ctrl+alt+backspace 杀死当前 x win
2.ctrl+alt+f1 进入虚拟终端,ps -ax|grep startx,然后杀死这个进程。

注意:ubuntu 中可能是 gdm。我的办法是

sudo /etc/init.d/gdm stop
sudo /etc/init.d/gdm start

12. Remote Execution — With the service “rexec” you can have remote execution, very useful when you are working on a network environment. The user using this service must authenticate with a user name and password.

这个没听说过,学习中…

Popularity: 23% [?]

Tags: , , , , , , ,
ad 468x60

No Replies

Feel free to leave a reply using the form below!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值