How to Use watch Command
If you need to execute a certain command repeatedly, you may use the watch command to do the repeating for you.
In this example, the command ps will be run every 2 seconds to monitor how fast the new processes spawn:
$ watch -n2 "ps aux|grep http"
The watch command will run ps every two seconds and it will display the output in stdout. You may increase or decrease the interval as necessary. This is useful if you want to monitor a process at certain time intervals. Personally, I use this to check for processes that spawns children way too fast.
Send Email in One Line
I use this nifty one liner to test if a Linux machine can send emails.
$ echo "This is the body of the email" | mail -s "This is the subject" rai@email.com
You need to install the package mailx (Red Hat or Fedora) to have the mail command.
How to Use the alias Command
Let us say you execute the command ‘ls –alh’ every time you need a long listing of files and directories. Now you want a shortcut to do this. Fortunately, you can do so by using the command alias.
The alias command is useful for creating shortcuts for long commands or for correcting typing mistakes.
To create a shortcut for ls, you can do this:
$ alias ls=”ls -alh”
Now, everytime you execute ls command, it will be run as if you are executing the whole ls –alh command. Be reminded that this will replace the existing ls command. You may use a different name for the new shortcut like so:
$ alias ll=”ls -alh”
However, once you exit the current terminal, the alias will not be saved. To make the alias permanent, you may edit the .bashrc file in user’s home directory:
$ vi ~rai/.bashrc
Then insert the alias command after the line that says #system wide functions and aliases. Save and exit.
That should do it!
How to Fix the Terminal After Viewing Binary File
Every now and then, I open up a file only to realize that it is a binary file (yes, I keep ignoring the warning that I am about to view a binary file, not text). Then the terminal ends up messy, or in other words, wonky. The characters have turned out in various colors, the lines are indented, and you can’t see what you are typing.
To fix it, run this command:
$ reset
As the name implies, this will reset the terminal back to its normal state.
Using Perl to Replace Text in Multiple Files
You can search and replace text inside multiple files using Perl. This is how you do it:
$ perl -i -pe 's/Windows/Linux/;' test*
This command will search for the word ‘Windows’ inside all files that begin with ‘test’. When it finds one, it will substitute it with the word ‘Linux’. This is useful if you have multiple files that contain the same text. Remember that you can use regular expressions to make searching flexible.
Search PinoyTux
Subscribe to Email Feeds
Blog Lounge
Popular Posts
Recent Posts
Drop your Card Here
Recent Comments
- Belarus Hava Yolları, Belarus airlines, Uçak Bileti, Air tickets, Belarus uçak on Cebu Pacific Sucks
- Cezayir Hava Yolları, Cezayir airlines, Uçak Bileti, Air tickets, Cezayir uçak on Cebu Pacific Airlines is Evil!
- Lambchop on Cebu Pacific Airlines is Evil!
- rabat on Linux Comics of the Day
- Kost on Item for Sale: 1GB DDR400 Kingston Memory








