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 tagged timeout from sorted by
Terminal - Commands tagged timeout - 7 results
if [ -n "$SSH_CONNECTION" ]; then export TMOUT=300; fi
2012-11-03 18:39:25
User: Testuser_01
Functions: export
0

This will check if a user is logged in using ssh and will log out the user automatically after the specified time in seconds without data retrieval on the server side.

Will work with bash and zsh so put it into your sourced shell file on the server side.

Be aware that users can change this themselves as it's just a envoronment variable.

timeout -k 1m 30s some_command
2012-03-27 18:06:18
User: tlemerond
Tags: fg bg kill timeout
1

A timeout is great, but what if the command is taking longer than expected because it's hung up or ran into some other problem? That's where the -k option comes in. Run "some_command" and timeout after 30s. If the command is still running after 1 minute, it will receive a kill signal.

timeout 5s COMMAND
timelimit -t100 somecommand
2010-09-27 08:44:37
User: CodSpirit
-3

I found this in Ubuntu repos, and consider it better than timeout.

very_long_command& sleep 10; kill $!
2010-04-29 20:43:13
User: dooblem
Functions: kill sleep
5

or "Execute a command with a timeout"

Run a command in background, sleep 10 seconds, kill it.

! is the process id of the most recently executed background command.

You can test it with:

find /& sleep10; kill $!

echo 'ServerAliveInterval 60' >> /etc/ssh/ssh_config
2010-03-31 09:22:54
User: rpavlick
Functions: echo
Tags: ssh timeout
6

ssh_config is the system-wide configuration file for ssh.

For per-user configuration, which allows for different settings for each host:

echo 'ServerAliveInterval 60' >> ~/.ssh/ssh_config

On OSX:

echo 'ServerAliveInterval 60' >> ~/.ssh/config

or

echo 'ServerAliveInterval 60' >> ~/etc/ssh_config
timeout 10 sleep 11