Cool Linux command tricks

Jack Wallen
Nov 2, 2010
Updated • Dec 27, 2012
Linux
|
6

The Linux command line is one of the most versatile tools you will ever use. It can do just about anything you can image for a machine. With such a large scope of tasks you can imagine just how much there is to learn. So, it's always good  to have an arsenal of tricks at your fingertips.

So...let's take a look at some nifty trickery with the Linux command line.

seq

This is one of the coolest (and most useful) tips I have ever come across.  The seq command will print out a sequence of numbers. So if you issue the command:

seq 0 50

You will see the numbers 0-50 printed out on the terminal. Very simple. Sure that's great but what good is a sequence of numbers? Let's apply it and find out. Remember you can always declare a value in bash and by making use of the $ symbol you can use variables in your commands. So what happens if you issue the command:

for k in `seq -w 1 50` ; do ssh 192.168.100.$k uptime ; done

What happens is ssh will walk through all the addresses from 192.168.100.1 to 192.168.100.50 until it finds one with an ssh server accepting connections. When it does it will ask you for the users password and then print out the uptime of that machine. Very handy indeed.

How much space left?

Quick, how much space do you have left on your drive(s)?  And where are those drives mounted on? Do you have the answer yet? If you had a terminal window open you could have issued the command df -h and you would have seen, in a user-friendly format, the percentage of your hard disk space that has been used. Very handy command.

Those pesky bash colors

Do you prefer the colors you see in bash? Do you even know about the colors in bash? From the command line issue the command ls you will see that files are black, folders are blue, executables are green (that's a simplistic explanation). What if those colors bother you (or cause your pretty transparent terminal from giving you a good read on your file listing)? You can turn that off easily from the command by issuing:

ls --color=none

Of course that is a one-time deal. In order to make this permanent you have to edit your ~/.bashrc file. In that file you will see the following entry:

alias ls='ls --color=auto'

Comment out that entry and ls will no longer use color.

Find files modified TODAY

If you have saved a file today and you can't remember where you saved it, you can use the find command to print out all files modified today. The command:

find ~ -type f -mtime 0

Will print out a listing of all files that were modified on the day the command was issued (today).

Install from source to package

That might not make any sense. It will in a moment. Say you've downloaded the source for a package that you want to install, but you want to keep with the standard for your distribution by installing it from a package (so your package manager is aware of it). You can do this with the help of the checkinstall application. This isn't installed by default, but you can install it with the command sudo apt-get install checkinstall. Once installed you can install from source with the command (from within the source code directory):

./configure && make && checkinstall

This will ask you some questions regarding your distribution and will install the application.

Advertisement

Previous Post: «
Next Post: «

Comments

  1. Dotan Cohen said on November 3, 2010 at 8:32 pm
    Reply

    Very coo,l, Jack, every single one of these will come in handy. Of course df is not really a trick, and I use it often, but the search for SSH servers is just great! Keep them coming!

  2. z0iid said on November 3, 2010 at 5:14 am
    Reply

    !whatever:p <—- searches the history for the last command run starting with "whatever" and prints it to the screen (and puts it as the last run command in history even though it isn't run, so you can just hit the up arrow)

    ^old^new^ <—– replace the last run command that contains the word "old" with the word "new" (useful when running long commands)

  3. Simon said on November 3, 2010 at 3:41 am
    Reply

    for k in {1..50}

  4. jasray said on November 3, 2010 at 2:46 am
    Reply

    Not much good with the CLI, but I would like to know how to install a .tar file via the command line.

    For ssh, the only one I really need or remember is the following:

    ssh -p443 -ND 8081 username@ipaddress of ssh server

    enter password

    accept RSA once

    What is happening?

    Establishing a connection on a non-standard port with the SSH server; not opening a shell; using 8081 for local port; connecting with my login name and password.

    Then would enter 127.0.0.1:8081 in the Socks 4 or 5 line in Firefox.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.