Show progress during dd copy

Ok, this is actually a copy and paste post thus credit is due where credit is deserved: Linux Commando.

The quick-and-dirty trick: open a new terminal and enter:

$ kill -INFO <PID of dd process>

NOTE: do not use USR1 on Mac OS X!

The “output” will be printed on the console where dd is actually running:

$ dd if=/path/to/file of=/dev/sdb1 bs=1M
0+14 records in
0+14 records out
204 bytes (204 B) copied, 24.92 seconds, 0.0 kB/s

[131028 update]: in fact $ sudo pkill -INFO -n -x dd seems to be a much quicker, and easy to remember, one-liner.

Source: RPi Easy SD Card Setup

Instant Python HTTP server

The quick and dirty way of starting an instant web server is by means of Python‘s simple HTTP request handler.

The following command will start listening to HTTP requests on port <port> (if <port> is blank a default value of 8000 is assumed) and will be serving files from the current directory:

$ python -m SimpleHTTPServer <port>

On the host’s console the access log will be displayed (example):

Serving HTTP on 0.0.0.0 port 4444 ...
<source address> - - [16/May/2013 12:12:17] "GET / HTTP/1.1" 200 -
<source address> - - [16/May/2013 12:12:17] "GET /favicon.ico HTTP/1.1" 404 -
<source address> - - [16/May/2013 12:12:19] "GET /example_file.txt HTTP/1.1" 200 -
...

To stop the server, according to the above-mentioned quick and dirty approach, issuing CTRL+C is fine (a traceback will be printed by the Python interpreter, that’s not something to worry about).

Source: http://osxdaily.com/2010/05/07/create-an-instant-web-server-via-terminal-command-line/

tree-like ls

tree” is a very nice command that’s not always available on any systems. As the name implies it lists the contents of directories in a tree-like format.

An example is:

$ tree
.
|-- Boards
|-- Members
|-- Messages
|-- Settings.pl
|-- Sources
|-- Variables
|-- YaBB.cgi
|-- english.lng
|-- template.html
`-- template2.html

Well, a similar result can be achieved in Bash with a nifty little one-liner:

ls -R | grep ":$" | sed -e 's/:$//' \
   -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

NOTE: long line, I had to break/fold it, sorry about that. Copy&paste is fine as long as the backslash (“\”) at the end of the first line is preserved.

A short explanation of the cryptic syntax above is as follows:

  • initially a recursive listing of the current directory is done: ls -R
  • pipe
  • any output other that the directory names, identified by “:” at the very end of each line (hence “:$“), is filtered out: grep ":$"
  • pipe
  • finally there’s a little of “sedmagic finding and replacing any hierarchy level (“/“) with one or more dashes (“-“):
    sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

*NIX chat

Well, no, not chat in the common/modern sense but did you know you can display which users are connected to the same system you’re logged on and send them messages?

First off, displaying users connected to the same system is, for sysadmins, a basic and quite an important monitoring command.

The syntax is extremely simple: “w“!

Example:

$ w
10:02:12 up 2 min,  2 users,  load average: 0.33, 0.18, 0.07
USER      TTY      FROM             LOGIN@   IDLE   JCPU   PCPU  WHAT
<userid1> pts/0    <src IP addr>    10:02    0.00s  4.83s  0.08s bash
<userid2> pts/1    <src IP addr>    10:02    0.00s  4.83s  0.08s w

Now, sending a message to <userid1> from <userid2> is as easy as:

echo "I'm about to disconnect you ;)" | write <userid1> pts/0

On <userid1>‘s console the following will be printed:

Message from <userid2>@<server> on pts/1 at 10:04 ...
I'm about to disconnect you ;)
EOF

Please notice that the TTY being used, pts/0 in the example, may differ from one OS to another.
For instance, on Mac OS X, it should be ttys00x.

The same is possible on Cisco routers by means of “send” command.