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.
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:
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.
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.