Cool Linux command tricks
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.Advertisement