[Translated] 8 Interesting Linux Tips And Tricks

This commit is contained in:
geekpi 2014-01-21 02:47:58 +00:00
parent 69a9bf662d
commit dbc3164371
2 changed files with 157 additions and 162 deletions

View File

@ -1,162 +0,0 @@
Translating-------------geekpi
8 Interesting Linux Tips And Tricks!
================================================================================
We keep bringing you tips and tricks for Linux from time to time. Keeping in tune with this practice, here are eight most interesting tips and tricks that we received recently from out readers. We hope you like it. Read on...
![](http://www.efytimes.com/admin/useradmin/photo/j4lm23703PM1182014.jpg)
### Listing files in the order of their sizes ###
If you want to have a list of the files sorted on the basis of their size, you can use the following command.
It will list the files in decreasing order.
# ls -l | grep ^- | sort -nr -k 5 | more
If you need to do the same thing recursively, you could use the second command shown below.
# ls -lR | grep ^- | sort -nr -k 5 | more
*—Sumedh Gajbhiye,
sumedh.gajbhiye1985@gmail.com*
### Resetting weird terminals ###
If youve felt that your bash terminal is misbehaving—showing junk characters for the prompt and displaying non-ascii characters for whatever you type—the following commands should put things back on track.
Type the command shown below at the terminal and press Enter:
# reset
If that does not fix the issue, then try the following:
# stty sane
*—Sudheer Divakaran,
cdsudheer@gmail.com*
### Recording and playing back the terminal session ###
Here is a simple tip to record and playback a terminal session. It is done by using the command script and scriptreplay.
This comes very handy while making tutorials using the terminal.
To start recording of your terminal session, use the following command:
$ script -t 2> timing.log -a output.session
Then type in:
$ ls
$touch test
.....
$ exit
Here, the script command takes two files as the -arguments timing.log (which stores information on the time at which each command is run) and output.session (which stores the output of the commands).
Now, to playback the recorded session, use scriptplay as shown below.
$ scriptreplay timing.log output.session
Note: timing.log and output.session can be shared with anyone who wants to replay a terminal session in his terminal.
*—Abhishek Singh,
abhishekkumarsingh.cse@gmail.com*
### Generate random numbers using the shell script ###
Sometimes when you are programming with the shell script, there may be a requirement to generate a random number to be used in the script.
Here is the code to get a 3-digit random number.
var=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d” “ | cut -c 3-5);
This will store the generated random number in the variable named as var.
*—Arpan Chavda,
09bce006@nirmauni.ac.in*
### Make software run on Linux as the root user ###
As a root user, to make software run on Linux, you have to change the string geteuid to getppid in the hex dump of the software.
This technique is extremely helpful in operating systems such as Backtrack, where most of the installation work has to be done as a root user.
For example: to run the Google Chrome browser as the root user, use the following command:
# hexedit /opt/google/chome/chrome
Then press Ctrl+S and search the string geteuid in the hex dump.
Replace that with string getppid. Press Ctrl+X to save and exit the hex editor.
Now run the browser as the root user.
# google-chrome
*—Mayank Bhanderi,
mbhanderi24@gmail.com*
### Optimise your site with GZIP compression ###
Compression is a simple, effective way to save bandwidth and speed up your site.
With the help of compression, any sites home page goes from 100 KB to 10 KB.
To enable this feature in the Apache Web server you need to include the deflate_module in httpd.conf and add the lines shown below in the configuration file of Apache (/etc/httpd/conf/httpd.conf) to compress text, html, javascript, css and xml files:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
*—Munish Kumar,
munishtotech@gmail.com*
### Check server load information while logging in ###
Here is a tip to check the server load average when you log in to the server. Create a text file named sload.sh with content shown below:
#!/bin/bash
gh=$(uptime | awk -F, {print $3})
echo -e “Server$gh\n”
Now, to check the server load at the time of logging in, call the sload.sh script through /root/.bashrc
Do remember to allow permission to the script as shown below:
# chmod 755 /root/sload.sh
To call the sload.sh script, append the following to the end of /root/.bashrc
/root/sload.sh
Or you can even append the content of the sload.sh to .bashrc
$echo “/root/sload.sh” >> /root/.bashrc
After completing the above steps, you can log out and log in again to see the server load when you next log in.
*—Ranjith Kumar T,
ranjith.stc@gmail.com*
### Start your job at a specific time ###
You can schedule your job at a specific time with the use of the following command:
# at 2015
> >vlc /music/rockstar.mp3
This command will start to play rockstar.mp3 using VLC player at 2015 hours.
You can check your pending jobs by using the option -l with the at command, as follows:
# at -l
More info can be found in the man pages of the at command.
*—Manas Pradhan,
acmeofmanas@gmail.com*
--------------------------------------------------------------------------------
via: http://www.efytimes.com/e1/fullnews.asp?edid=127250
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出

View File

@ -0,0 +1,157 @@
8个有趣的Linux提示与技巧
================================================================================
我们时不时给你带来关于Linux的提示与技巧。和这个实践保持一致这里有8个我们从读者收到最有趣的提示和技巧。我们希望你喜欢它。请继续读下去。。。
![](http://www.efytimes.com/admin/useradmin/photo/j4lm23703PM1182014.jpg)
### 以它们的大小列出文件 ###
如果你想要一个基于它们大小排序的文件列表,你可以使用下面的命令。
它会以递减顺序排列文件。
# ls -l | grep ^- | sort -nr -k 5 | more
如果你想要递归地做相同的事,你可以使用下面的第二个命令。
# ls -lR | grep ^- | sort -nr -k 5 | more
*—Sumedh Gajbhiye,
sumedh.gajbhiye1985@gmail.com*
### 重置奇怪的终端 ###
如果感觉你的bash终端错误地显示垃圾的提示字符信息并无论你输入任何命令都显示非ASCII字符-下面的命令可以让事情回到正轨。
在终端输入下面的命令并按回车:
# reset
如果那个不能修复这个问题,试一下下面的:
# stty sane
*—Sudheer Divakaran,
cdsudheer@gmail.com*
### 记录并回放终端会话 ###
下面是一个简单的贴士来记录并回放终端回放。它通过使用命令script和scriptreplay。
这在使用终端制作教程时非常方便。
要开始记录你的终端会话,使用下面的命令:
$ script -t 2> timing.log -a output.session
接着输入:
$ ls
$touch test
.....
$ exit
这里script命令取两个文件作为参数timing.log(它记录了每个命令执行的时间信息)和output.session(存储了命令的输出)。
现在要回访记录的会话使用下面所示的scriptplay。
$ scriptreplay timing.log output.session
timing.log和output.session可以被任何想要在自己的终端上重放会话的人使用。
*—Abhishek Singh,
abhishekkumarsingh.cse@gmail.com*
### 使用shell脚本生成随机数 ###
有时当你想要用shell脚本编程时可能需要生成一个随机数来用于脚本。
这里是获得一个3位随机数的代码。
var=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d” “ | cut -c 3-5);
这回存储随机生成的数字在名为var的变量中。
*—Arpan Chavda,
09bce006@nirmauni.ac.in*
### 以root用户运行Linux上的软件 ###
作为一名root用户为了让软件运行在Linux上你不得不在软件的16进制转储文件中改变字符串geteuid到getppid。
这个技术在操作系统中非常有用比如backtrack这里的大多数安装工作都以root用户完成。
比如:为了以root用户运行Google Chrome使用下面的命令:
# hexedit /opt/google/chome/chrome
接着按下Ctrl+S并在16进制转储文件中搜寻geteuid字符串。用字符串getppid代替。按下Ctrl+X来保存并退出编辑器。
现在浏览器就可以以root用户运行了。
# google-chrome
*—Mayank Bhanderi,
mbhanderi24@gmail.com*
### 用gzip压缩优化你的站点 ###
压缩是一种简单、有效的方法来节约带宽和加速你的站点。
在压缩的帮助下任何站点的主页面会从100KB变成10KB。
为了在Apache Web服务器中启用这个特性你需要在httpd.conf中包含deflate_module并且在Apache配置文件中加入下面的行 (/etc/httpd/conf/httpd.conf)来压缩text、html、 javascript、 css 和 xml 文件:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
*—Munish Kumar,
munishtotech@gmail.com*
### 在登陆时检查服务器负载信息 ###
这里有一个贴士来在你登陆服务器的时候检查服务器平均负载。创建一个sload.sh的文本文件内容如下:
#!/bin/bash
gh=$(uptime | awk -F, {print $3})
echo -e “Server$gh\n”
现在,为了在登陆时检查服务器负载,通过/root/.bashrc调用sload.sh脚本。
记住如下允许脚本权限:
# chmod 755 /root/sload.sh
要调用sload.sh脚本如下在/root/.bashrc后追加
/root/sload.sh
或者你还可以这样追加sload.sh的内容到.bashrc中。
$echo “/root/sload.sh” >> /root/.bashrc
当你完成上面的步骤后,你可以登出并再次登陆来查看服务器负载。
*—Ranjith Kumar T,
ranjith.stc@gmail.com*
### 在特定时间开始你的作业 ###
你可以使用下面的命令来在特定时间调度你的作业:
# at 2015
> >vlc /music/rockstar.mp3
这个命令会在2015小时后使用vlc播放器播放rockstar.mp3。
你可以在at命令后跟上-l选项来检查挂起的作业
# at -l
更多at命令的信息可以在man页找到。
*—Manas Pradhan,
acmeofmanas@gmail.com*
--------------------------------------------------------------------------------
via: http://www.efytimes.com/e1/fullnews.asp?edid=127250
译者:[geekpi](https://github.com/geekpi) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出