If you tend to issue commands and accidentally leave them running, you might want to employ the timeout command
Linux admins are notorious for depending on the command line. With good reason. The command line is incredibly powerful. There is no end to what you can do with Linux commands.
However, there are times when you want to run a command but don't want the command to continue running until you forget it's running and realize that the command has been gobbling up CPU cycles, filling up logs, or just generally doing its thing in the background, harming nothing.
SEE: Disaster recovery and business continuity plan (Tech Pro Research)
How it works
Regardless of why you don't want to allow a command to run forever, the how is quite simple—thanks to the timeout command. The timeout command should be installed by default and is very simple to use. Say you want to run a ping command, on google.com, for five seconds (because who hasn't forgotten they'd run a ping command, only to come back hours later to see it still pinging the target address?).
To do this, log into your Ubuntu server or desktop, open a terminal window, and issue the command timeout 5 ping google.com. The ping command will do its thing for five seconds and stop. Or say you want to follow the syslog log file with tail for ten seconds. That command would be timeout 10 tail -f /var/log/syslog. After the configured 10 seconds, the tail command will end.
And that's how you can automatically stop your commands, without having to resort to the old [Ctrl]+[C] keyboard combination. If you tend to issue commands and accidentally leave them running, you might want to start employing the timeout command, before your IT manager puts you in a timeout.
- How to use SSH to proxy through a Linux jump host (TechRepublic)
- How to use the tmux multiplexer for a more efficient Linux terminal (TechRepublic)
- How to scan for IP addresses on your network with Linux (TechRepublic)
- How to make your Linux machines visible to other Linux machines (TechRepublic)
- Dirty Sock vulnerability lets attackers gain root access on Linux systems (ZDNet)
- The 10 most important iPhone apps of all time (Download.com)
- It takes work to keep your data private online. These apps can help (CNET)
- Programming languages and developer career resources coverage (TechRepublic on Flipboard)