5 Things You Can Do Faster from the CLI on Linux

570 VIEWS

·

Linux command-line tools are intimidating at first. When I started using Linux about ten years ago, I was terrified every time I had to work from the command-line interface (CLI) instead of pointing and clicking my way through a graphical user interface.

Over time, however, I came to appreciate just how powerful the CLI can be. Sometimes, it’s much faster to accomplish a task through the command line than it is to do it using a mouse and a graphical interface.

Here are five examples of tasks that are much easier to do on the command line.

1. Find a file

If you need to search for a file quickly and you know part of its name, you can open up a terminal and run:

The system will instantly tell you where all files containing the string “somewords” exist.

(The results are pulled from a database that is updated periodically, so it may not be totally up-to-date, but the results are instant. If you want real-time results, you can use the find command instead to search through directories for files with given attributes in their names.)

Finding a file from the CLI is generally much faster than having to fire up your file system browser and search for a file that way. Some Linux desktop environments, like Unity, may provide quick ways to search for files, too, although their results can be weighted in various ways, and it’s hard to customize a search with regular expressions, which you can use with locate or find.

2. Find your IP address

If you want to know the IP address of your computer, you could look it up in whichever graphical system settings or network connection app your distribution supports. But a faster way is to run a quick ifconfig command in the terminal.

  1. Install software

I’m all for graphical apps that help you manage the software that is installed on your system, or add new software to it. Those programs are useful if you want to look up details on a package, or see a screenshot of an app before you install it.

But ninety percent of the time, I just want to install an app quickly, without waiting for a graphical management program to load, then update its repository information. So for me, nothing beats a quick:

or:

command. The package installation syntax for apt-get and yum is quite simple, and the results are much faster than waiting on a graphical app.

4. Resolve a hostname

Sometimes, you want to know which IP address a particular hostname resolves to. There are websites that would give you that information, and you could pull it out of a Web browser, too. But both of those approaches would be kind of tedious.

A faster solution is to open a terminal and run:

You’ll get nearly instant results.

Relatedly, a cool CLI trick I like is using dig (another program for resolving hostnames) to request a hostname resolution from a specific DNS server. This is handy in cases where you want to see how a hostname would be resolved by a DNS server other than the one you’re currently using. For example:

would resolve google.com using the DNS server with IP address 8.8.8.8 (which happens to be a public DNS server run by Google).

 

5. Find the last modified file in a directory

Want to know which files you most recently added to a particular directory? Yes, you could open up a graphical file browser, navigate to the directory in question and tell the browser to sort files according to access or modification time. But that’s a lot of thinking and clicks.

A faster answer is to do a quick:

This will list directory contents with the newest files at the bottom of the results. I find the command helpful when, for example, I just saved a file to a certain directory, but can’t remember the file’s name.

Do you think you can beat this Sweet post?

If so, you may have what it takes to become a Sweetcode contributor... Learn More.
http://www.fixate.io

Chris Tozzi has worked as a journalist and Linux systems administrator. He has particular interests in open source, agile infrastructure and networking. He is Senior Editor of content and a DevOps Analyst at Fixate IO.


Discussion

Click on a tab to select how you'd like to leave your comment

Leave a Comment

Your email address will not be published. Required fields are marked *