[Shell advanced] most bull b Linux shell Command (iii)

Source: Internet
Author: User
Tags echo b disk usage

1. More friendly display of the currently mounted file system
Mount | column-t
This command applies to any file system, and column is used to format the output as a list, and the main purpose here is to familiarize you with the usage of columnt. The following is the result of using the Mount command alone:
$ mount/dev/root on/type ext3 (rw)
/proc on/proc type proc (rw)
/dev/mapper/lvmraid-home on/home type ext3 (rw,noatime)
And after adding the COLUMN-T command, it became like this:
$ mount | column-t/dev/root on/type ext3 (rw)
/proc on/proc type proc (rw)
/dev/mapper/lvmraid-home on/home type ext3 (rw,noatime)
Plus you can add column names to improve the output.
$ (echo "Device-path-type flags" && mount) | Column-t device-path-type Flags
/dev/root on/type ext3 (rw)
/proc on/proc type proc (rw)
/dev/mapper/lvmraid-home on/home type ext3 (rw,noatime)
Column 2 and column 4 are not very friendly, we can use awk to deal with it.
$ (echo "Device path type Flags" && Mount | awk ' $2=$4= ""; 1 ') | column-t device Path Type flags
/DEV/ROOT/EXT3 (rw)
/PROC/PROC proc (rw)
/dev/mapper/lvmraid-home/home ext3 (rw,noatime)
Finally, we can set an alias for Nicemount
$ nicemount () {(echo "DEVICE PATH TYPE FLAGS" && mount | awk ' $2=$4= "; 1 ') | column-t;}
Try it.
$ nicemountdevice PATH TYPE FLAGS
/DEV/ROOT/EXT3 (rw)
/PROC/PROC proc (rw)
/dev/mapper/lvmraid-home/home ext3 (rw,noatime)
2. Run the previous Shell command and replace each "foo" in the command line with "bar"
!!:gs/foo/bar
!! Indicates that the previous command was executed repeatedly and replaced with: Gs/foo/bar. About!! This usage isin a previous posthas been described in detail. 3. View the latest changed files in a real-time directory
watch-d-N 1 ' df; Ls-flat/path '
When using this command you need to replace the/path part, watch is the real-time monitoring tool, the-d parameter highlights the changed area, and the-N 1 parameter indicates a refresh interval of 1 seconds. df Ls-flat/path runs two commands, DF is the output disk usage, and Ls-flat lists all the files under/path. Ls-flat's parameters are detailed:
-
f Add a file symbol after the file type, a total of */=>@| these types, * represents the executable file,/represents the directory, = Represents the interface (sockets),> represents the door, @ represents the symbolic link, | represents the pipeline.
-L is displayed in list mode
-A display. And..
-T sort files based on time
4. Mount the folder on the remote host via SSH
SSHFS [email protected]:/path/to/folder /path/to/mount/point
This command allows you to load the file system on the remote host via SSH as a local disk, provided you need to install both the FUSE and SSHFS software. Translator Note: About SSHFS Actually I've written an article about it before, see "use SSHFS to map the remote SSH file system to a local disk on Ubuntu"。 Uninstall the words using the Fusermount command:
fusermount-u/path/to/mount/point
5. Read Wikipedia's entry via DNS
dig +short txt <keyword>.wp.dg.cx
This is perhaps the most interesting trick, David Leadbeater has created aDNS Server, which, when you query a TXT record type, returns a short entry text from Wikipedia, which ishis introduction。 Here is a sample to query the meaning of "hacker":
$ dig +short txt hacker.wp.dg.cx "hacker may refer To:hacker (computer security), someone involved
In Computer security/insecurity, Hacker (programmer subculture), a
Programmer subculture originating in the US academia in the 1960s,
Which is nowadays mainly notable for the free software/"" Open
Source movement, Hacker (hobbyist), an enthusiastic home computer
Hobbyist http://a.vu/w:Hacker"
The dig command is used here, which is the standard system Management tool used to query DNS, the +short parameter is to simply return the text response, and TXT is the specified query TXT record type. A simpler approach is to create an alias for this technique:
wiki () {dig +short txt $1.wp.dg.cx;}
Then try it:
$ wiki Hacker "hacker may refer To:hacker (computer security), ..."
If you do not want to use dig, you can also use the host command:
host-t txt hacker.wp.dg.cx
6. Download the entire site using Wget's Recursive method
wget--random-wait-r-p-e robots=off-u Mozilla www.example.com
Parameter explanation:
--random-wait waits 0.5 to 1.5 seconds for the next request
-R Turn on recursive retrieval
-E Robots=off Ignore robots.txt
-u Mozilla set user-agent head for Mozilla
Some other useful parameters are:
--limit-rate=20k limit download speed to 20K
-O logfile.txt Record download log
-L 0 Delete Depth (default = 5)
--wait=1h wait 1 hours after each file download
7. Copy the parameters from the last used command
ALT +. (or ESC +.)
This shortcut can only work with the Shell's Emacs edit mode, which copies the parameters from the last command line to the current command line, as follows:
$ echo a b C
A b C $ echo <press ALT + .>
$ echo C
You can repeat the shortcut to get the parameters you want, and here's a sample:
$ echo 1 2 3
1 2 3
$ echo a b C
A b C $ echo <press ALT + .>
$ echo C $ echo <press ALT + .> again
$ echo 3
Alternatively, if you want to specify a 1th or 2nd, or the nth argument, you can press ALT + 1 (or ESC + 1) or ALT + 2 (or ESC +2) for shortcuts. The following is a sample example:
$ echo a b C
A b C $ echo <press ALT + 1> <press ALT + .>
$ echo A
a$ echo <press ALT + 2> <press ALT + .>
$ echo B
b
ViewEmacs Editing Mode Keyboard ShortcutsArticle to get more similar shortcuts. 8. Execute a command but not save to history
<space> Command
This command can be run in the latest Bash shell, which has not been tested in other shells. By adding a space at the front of the command line, you can prevent this command from being saved in the Bash history file, which can be ~/.bash_history by $HISTIGNORE shell variables. My settings are histignore= "&:[]*", which means that no duplicate commands are saved to the history, and the command line beginning with a space is not saved. The values in the $HISTIGNORE are separated by colons. If you are interested and want to know more, you can read more about this article "The definitive guide for Bash Command Line"9. Displays the size of all subdirectories in the current directory
du-h--max-depth=1
-The-max-depth=1 parameter allows the du command to display statistics for Level 1 subdirectories in the current directory, but you can also change 1 to 2 to further display the statistics of the 2-level subdirectory, which can be used flexibly. The-h parameter displays the size in units such as Mb and G. Translator Note: A small tool NCDU is recommended here, which can be more convenient to achieve this effect. 10. Show the 10 running processes that consume the most memory, sort by memory usage
PS aux | sort-nk +4 | tail
Obviously this is not the best approach, but it does work well. This is a typical piping application that is output to the sort command via the PS aux, sorted by sort in the 4 column, and then further to the tail command, and the final output of 10 lines shows the process using the most memory. If you want to find out which process uses a lot of memory, I usually use htop or top rather than PS. Extra: Use Python to quickly open an SMTP service
python-m smtpd-n-C debuggingserver localhost:1025
This is a Python standard library SMTPD (specified with-M smtpd) implemented in the simple SMTP service, running on port 1025. An explanation of the other three parameters:
The-
n parameter allows Python not to setuid (change the user) to "nobody", which means to run directly with your account
The-c debuggingserver parameter is for the Python runtime to output debug and run information on the screen
The localhost:1025 parameter is to have Python open the SMTP service on the local port 1025
Also, if you want the program to run on a standard 25 port, you must use the sudo command, because only root can open the service on port 1-1024. As follows:
sudo python-m smtpd-n-c debuggingserver localhost:25

[Shell advanced] (GO) The most bull B Linux shell Command (iii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.