Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using script from sorted by
Terminal - Commands using script - 14 results
script -qf | tee >(nc -l -p 5000)
script -t 2> timing.txt -a session.txt ; Run some commands here; exit; scriptreplay timing.txt session.txt
RX1=`cat /sys/class/net/${INTERFACE}/statistics/rx_bytes` (see script below)
2012-01-23 18:22:44
User: jp
Functions: script
0

Need output in mbps (bits)

# ./bytes-second.sh eth0

eth0 interface maximum Speed: 1000Mb/s

RX:12883212 TX:17402002 B/s | RX:98 TX:132 Mb/s

RX:12371647 TX:17830111 B/s | RX:94 TX:136 Mb/s

RX:12502750 TX:17860915 B/s | RX:95 TX:136 Mb/s

script -f /tmp/foo; tail -f /tmp/foo
2011-11-22 15:16:08
Functions: script tail
Tags: script tail -f
2

script -f /tmp/foo will place all output of the terminal, including carriage returns, to a file. This file can be tail dash-eff'ed by one or more other terminals to display the information of the main terminal. Good way to share one's screen on short notice.

Note: This produces a very accurate output, but that includes depending on the size of your terminal to be the same. You can clear screens or even resize the terminal for others using this function; I use it in conjunction with the "mid" command in my list.

mkfifo foo; script -f foo
2011-09-08 02:51:44
User: realist
Functions: mkfifo script
17

One person does `mkfifo foo; script -f foo' and another can supervise real-time what is being done using `cat foo'.

# su - <user> ; script /dev/null ; screen -r
2011-07-04 16:26:10
User: dmmst19
Functions: screen script su
Tags: screen su pty
2

Normally, if you su to another user from root and try to resume that other user's screen session, you will get an error like "Cannot open your terminal '/dev/pts/0' - please check." This is because the other user doesn't have permission for root's pty. You can get around this by running a "script" session as the new user, before trying to resume the screen session. Note you will have to execute each of the three commands separately, not all on the same line as shown here.

Credit: I found this at http://www.hjackson.org/blog/archives/2008/11/29/cannot-open-your-terminal-dev-pts-please-check.

script -qf >(nc -ub 192.168.1.255 5000)
screencast() { arecord -R 1000 -f cd -t wav $1.wav & RECPID=$!; echo "Starting screencast in new shell. Exit subshell to quit."; script -t 2> $1.timing -a $1.session; kill $RECPID; }
2011-01-20 14:35:47
User: bartonski
Functions: arecord cd echo kill script
2

This shell function takes a single argument, which is used as the base name of the .wav, .timing and .session files created. To create a screencast:

screencast test

type and talk ...

then type 'exit' or to exit the screencast.

test.wav will contain the audio from your screencast.

test.session will contain text and control characters needed to paint the screen

test.timing will contain timing information needed to synch individual keystrokes in test.session with the audio.

to play back:

aplay test.wav & scriptreplay test.{timing,session}

NOTE: because the shell function uses the variable "$!", and bash likes to expand '!' during history expansion, you will need to turn off bash's history before you enter the shell function.

This can be achieved using the command

set +H
script -t /tmp/mylog.out 2>/tmp/mylog.time; <do your work>; <CTRL-D>; scriptreplay /tmp/mylog.time /tmp/mylog.out
2011-01-19 07:16:30
User: olorin
Functions: script
23

If you provide the option -t to the script command and redirect stderr into a file, the timing information on what is going on on the terminal, is also stored.

You can replay the session via the scriptreplay command, where you can also provide a speedup factor (see the man page for details).

Great for demonstration purposes ...

script /tmp/log.txt
script -qf | tee >(nc -kl 5000) >(nc -kl 5001) >(nc -kl 5002)
2010-10-11 07:55:30
User: clvv
Functions: script tee
Tags: tee pipe script nc
36

run 'nc yourip 5000', 'nc yourip 5001' or 'nc yourip 5002' elsewhere will produce an exact same mirror of your shell. This is handy when you want to show someone else some amazing stuff in your shell without giving them control over it.

script -f /dev/pts/3
2009-08-19 07:04:17
User: realist
Functions: script
6

Will redirect output of current session to another terminal, e.g. /dev/pts/3

Courtesy of bassu, http://www.commandlinefu.com/commands/by/bassu

script /dev/null | tee /dev/pts/3
2009-04-19 00:29:45
Functions: script tee
10

can display the commands and their output to another user who is connected to another terminal, by example pts/3

script
2009-02-09 22:38:56
User: chrisdrew
Functions: script
8

Creates a log of a session in a file called typescript. Or specify the file with:

script filename

Exit the session with control-d.