LJ Archive

Shorter Commands

Discover some short replacements for some of your favorite command-line commands.

Although a GUI certainly has its place, it's hard to beat the efficiency of the command line. It's not just the efficiency you get with a purely keyboard-driven interface, but the raw power of piping the output of one command into the input of another. This drive toward efficiency influenced the commands themselves. In the age before tab-completion, having a long command, much less a hyphenated command, was something to avoid. That's why we call it "tar" not "tape-archive" and "cp" instead of "copy." I like to think of old UNIX commands like rough stones worn smooth by a river, all their unnecessary letters worn away by the erosion of years of typing.

Tab completion has made long commands more bearable and more common; however, there's still something to be said for the short two- or three-letter commands that pop from our fingers before we even think about them. Although there are great examples of powerful short commands (my favorite has to be dd), in this article, I highlight some short command-line substitutions for longer commands ordered by how many characters you save by typing them.

Save Four Characters with apt

Example:


sudo apt install vim

I'm a long-time Debian user, but I think I was the last one to get the news that apt-get was being deprecated in favor of the shorter apt command, at least for interactive use. The new apt command isn't just shorter to type, it also provides a new and improved interactive interface to installing Debian packages, including an RPM-like progress bar made from # signs. It even takes the same arguments as apt-get, so it's easy to make the transition to the shorter command. The only downside is that it's not recommended for scripts, so for that, you will need to stick to the trusty apt-get command.

Save Four Characters with dig

Example:


dig linuxjournal.com NS

The nslookup command is a faithful standby for those of us who have performed DNS lookups on the command line for the past few decades (including on DOS), but it's also been deprecated for almost that long. For accurate and supported DNS searches, dig is the command of choice. It's not only shorter, it's also incredibly powerful. But, with that power comes a completely separate set of command-line options from what nslookup has.

Save Four Characters with nc

Example:


nc mail.example.com 25

I've long used telnet as my trusty sidekick whenever I wanted to troubleshoot a broken service. I even wrote about how to use it to send email in a past Linux Journal article. Telnet is great for making simple network connections, but it seems so bloated standing next to the slim nc command (short for netcat). The nc command is not just a simple way to troubleshoot network services, it also is a Swiss-army knife of network features in its own right, and it even can perform basic port-scan style tests in place of nmap via the nc -zv arguments.

Save Five Characters with ss

Example:


ss -lnpt

When you are troubleshooting a network, its incredibly valuable to be able to see what network connections are currently present on a system. Traditionally, I would use the netstat tool for this, but I discovered that ss performs the same functions and even accepts similar arguments. The only downside is that its output isn't formatted quite as nicely, but that's a small price to pay to save an extra five keystrokes.

Save Six Characters with ip

Example:


ip addr

The final command on this list is a bit controversial among old-timers like me who grew up with the ifconfig command. Sadly ifconfig has been deprecated, so if you want to check network link state, or set IP addresses or routing tables, the ip command is what all the kids are using. The syntax and output formats are dramatically different from what you might be used to with the ifconfig command, but on the plus side, you are saving six keystrokes.

—Kyle Rankin

LJ Archive