mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-13 22:30:37 +08:00
20140120-5 选题
This commit is contained in:
parent
53e0e0c094
commit
7ce51111ca
159
sources/8 Interesting Linux Tips And Tricks!.md
Normal file
159
sources/8 Interesting Linux Tips And Tricks!.md
Normal file
@ -0,0 +1,159 @@
|
||||
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 you’ve 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 site’s 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/) 荣誉推出
|
@ -0,0 +1,71 @@
|
||||
Linux pwd command - Know Your Current Working Directory
|
||||
================================================================================
|
||||
Where you are inside a deep directory, sometimes you may want to know where exactly you are. With this pwd command, you can do it.
|
||||
|
||||
### What is pwd ###
|
||||
|
||||
Pwd is a command to print name of current / working directory. When we are “lost” into a deep directory, we can always reveal where we are.
|
||||
|
||||
### How to use it ###
|
||||
|
||||
Since pwd command is intended to only print name of current / working directory, pwd does not have a lot of parameter to add. To use it, you just can type :
|
||||
|
||||
$ pwd
|
||||
|
||||
And it will print where you are. For a shell like bash, sometimes this information already print after host-name. Take a look at below picture.
|
||||
|
||||
![Pwd in bash](http://linoxide.com/wp-content/uploads/2014/01/pwd_bash.png)
|
||||
|
||||
As you can see above, the **/lib/udev/rules.d** is printed a hostname. When we type pwd, it will print **/lib/udev/rules.d** again. But when you are using another shell such as **csh**, pwd may help you to tell where are you. Here’s a sample of it.
|
||||
|
||||
% pwd
|
||||
|
||||
![Pwd in csh shell](http://linoxide.com/wp-content/uploads/2014/01/pwd_csh.png)
|
||||
|
||||
### Print physical directory avoid all symlinks ###
|
||||
|
||||
When you are in directory which is a symbolic links to another directory, you will find that pwd will print the alias / symbolic links to it. To print the real directory name, we can use **-P** parameter.
|
||||
|
||||
$ pwd -P
|
||||
|
||||
![Physical pwd](http://linoxide.com/wp-content/uploads/2014/01/pwd_P1.png)
|
||||
|
||||
![Physicall pwd](http://linoxide.com/wp-content/uploads/2014/01/pwd_P2.png)
|
||||
|
||||
![Physical pwd](http://linoxide.com/wp-content/uploads/2014/01/pwd_P3.png)
|
||||
|
||||
At the screenshot above, we are change the directory to **PlayOnLinux’s virtual drives**. This directory is located in **/home/pungki** and its a symbolic link to wineprefix directory. When we do pwd command, the shell return **/home/pungki/PlayOnLinux’s virtual drives**. But if we add **-P** parameter, the we will know that the real directory is **/home/pungki/.PlayOnLinux’s/wineprefix**
|
||||
|
||||
### Reveal which pwd ###
|
||||
|
||||
On bash shell, pwd may already built-in inside it. To know it, we can use this command :
|
||||
|
||||
$ type -a pwd
|
||||
|
||||
![pwd type](http://linoxide.com/wp-content/uploads/2014/01/pwd_type.png)
|
||||
|
||||
You see that there are **two** pwd’s. When you use pwd, you may use the built-in pwd command on your shell. This pwd will override the original pwd. Here’s a sample.
|
||||
|
||||
![Symlink pwd](http://linoxide.com/wp-content/uploads/2014/01/pwd_L.png)
|
||||
|
||||
On the screenshot above, we are now inside **/home/pungki./PlayOnLinux/wineprefix**. When we use **/bin/pwd**, it will return the real name of current directory. But when we add **-L** parameter, it will return a symbolic link name of current directory.
|
||||
|
||||
This **-L** parameter output the same result if we just type pwd, which use built-in shell pwd.
|
||||
|
||||
### Print pwd version ###
|
||||
|
||||
To print pwd version, we can use **--version** parameter. But for bash shell, we need to use **/bin/pwd** instead of pwd. Otherwise, it will return an error message.
|
||||
|
||||
![pwd version](http://linoxide.com/wp-content/uploads/2014/01/pwd_version.png)
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
pwd may help you to know where your current directory when your bash don’t print it directly on command prompt. As usual, you can always type **man pwd** to explore pwd usage more detail.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-command/linux-pwd-command/
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user