Archive for the ‘Tools’ Category
Each line in a crontab file is a job and follows a particular format as a series of fields, separated by spaces or tabs(see example below). Each field can have a single value or a series of values.
There are multiple ways of specifying several date/time values in a field:
- The comma(,) specifies a list of values, for example: “1,3,4,7,8”
- The dash(-) specifies a range. Example: “1-6”, which is equivalent to “1,2,3,4,5,6”
- The asterisk(*) operator specifies all possible values for a field. For example, an asterisk in the hour time field would be the same as ‘every hour’.
There is also an operator which some extended versions of cron support, the slash(/) operator, which can be used to skip a given number of values. For example, “*/3” in the hour time field is equivalent to “0,3,6,9,12,15,18,21”. So “*” specifies ‘every hour’ but the “*/3” means only those hours divisible by 3.
Example: the following will clear the Apache error log at one minute past midnight each day.
01 00 * * * echo "" > /www/apache/logs/error_log
.---------------- minute (0 - 59) | .------------- hour (0 - 23) | | .---------- day of month (1 - 31) | | | .------- month (1 - 12) OR jan,feb,mar,apr ... | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat | | | | | * * * * * <command to be executed>
For more information about the cron and crontab, run the command
man cron and
You can use this tool to generate the crontab commands easily. Just enter the command and the intervals it should be executed on – this tool will create a line in crontab syntax that will do the work for you. All you have to do is add the generated line to your crontab file. Once the result line is generated, run the command ‘crontab -e’ – this will open your crontab file in an editor. Just copy the generated line into this editor and save the file – you are done.
For example, lets say you want to clear the apache log file every day at midnight. The command to be executed is…
echo "" > /www/apache/logs/error_log
Enter that command into the command input field in the application. Next click on the ‘Choose’ radio button in the minute and set it to 0. Then select the ‘Choose’ option in Hour and set it to 12 Midnight. Live the rest as it it – we want the command to be executed every day. Now just click on the ‘Create Crontab Line’. The final crontab line will show up in the ‘Result crontab Line’ textarea.
Posted in Applications, Tools | 5 Comments »
Terminal GUI Apps? Does sound oxymoronic doesn’t it? Well, there are GUI apps in the terminal – and here is a tribute to ones that I find most useful…
top/htop – Process Viewer
From the man page…
The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. The types of system summary information shown and the types, order and size of information displayed for tasks are all user configurable and that configuration can be made persistent across restarts.
I always have a processor load displaying applet(System Monitor) in my panel. Whenever I see a spike, I fire up a console and type in the top command – its very useful in finding which process is creating the load. Usually, it is some cron job like
makewhatis. But occasionally, I find a zombie processes this way.
htop is, for the lack of a better word, a better top. It provides a more colorful display(
top has a color mode as well – open top and press ‘z’). It also makes it a bit more easier to kill processes.
mc – File Manager
mc(or Midnight Commander) is a file manager. Sure you can cp and mv your files around, but after a while, it gets tiring. mc is a dual pane file manager -it means you can see two folders at the same time. You can copy/move files from one to the other, delete, rename, view file etc – in short, everything a file manager is expected to have, mc has.
mpg123 – Audio Player
aptitude is a ncurces based GUI for the apt package manage – as a result, this is only available in Debian based systems(Ubuntu, Knopix, etc.). I have not yet seen anyone using aptitude – if they have a GUI system, they use synaptic – and if they are comfortable with the command line, they use apt-get command. But still, there is a middle ground – if for some reason you need it.
Thanks to Rajesh for the aptitude screenshot.
Any other Terminal GUI application? I can only think of these at the moment. If you can think of others, comment.
Tags: application, aptitude, gui, htop, mc, mpg123, review, terminal, top
Posted in Applications, Command Line, Reviews, Tools | 12 Comments »
A few tips and tricks on the terminal to make you more efficient when using it. If you know of any other tips, add it in the comments section.
1. ls Without ls
When you are trying to cd into a deep folder, you might not know the correct folder name some levels deep. You might have to do something like…
$ cd ~/Scripts/Perl $ ls bin SedGUI ToSee Cronjobs Maintenance $ cd Maintenance
There is an easier way – go to the wanted folder
$ cd ~/Scripts/Perl
Now, without pressing enter, double tap the TAB key. You will get a list of files. And the command prompt waiting to be filled…
$ cd ~/Scripts/Perl/[TAB TAB] bin SedGUI ToSee Cronjobs Maintenance $ cd ~/Scripts/Perl/_
You can also use double-TAB to auto-complete commands.
2. Searching the history with Ctrl+R
If you have to use a command you have already used before, press CTRL+R and then type a few characters of the command. The latest command with those characters will be shown – if that is the command you want to execute, press enter and it will be executed. If not, just press CTRL+R again and it will show the next command.
You have no idea how useful this tip is if you haven’t been using it. I use this all the time.
For more details, read this article.
3. Open Terminal using a Shortcut
If you are a GUI user, chances are you prefer using a Terminal emulator(like
konsole) instead of going into the Terminal mode by pressing CTRL+ALT+F1. If so, assign a shortcut to those emulator apps. I prefer using the shortcut ‘Ctrl+Alt+A’ to do this.
If you are in gnome, there is a very easy way to do this…
- Go to System > Preferences > Keyboard Shortcuts
- Find ‘Run a Terminal’ – assign the shortcut ‘Ctrl+Alt+A’
- Right Click on the K-Menu > Menu Editor
- Find your terminal application in the list(usually System > Terminal Applications > Terminal)
- Select the ‘Current Shortcut Key’ option and set it to ‘Ctrl+Alt+A’
You can also do this by opening the KHotKeys application.
4. Bash Keyboard Shortcuts
Learn the bash keyboard shortcuts – these are the ones I use the most…
- Search the history. We already talked about this.
- Clears the screen. Use this instead of the
- Use this instead of the
- Kill whatever is running
- Puts whatever is running into a suspended background process. Use
fgto restore it.
5. Find Command using
Find the command you want using the
apropos command. Just type in a description of the command as the first argument. For example, lets say you want to find the command to list the directory contents. Use the command…
$ apropos "directory contents" dir (1) - list directory contents ls (1) - list directory contents ls (1p) - list directory contents ntfsls (8) - list directory contents on an NTFS filesystem vdir (1) - list directory contents
The only problem is that I can never spell ‘apropos’ – so I keep this in my
6. Learn New Commands
There are a few sites that publish cool commands on a daily/semi-daily basics – subscribe to those and learn new commands…
Tags: command, key, shortcut, tab, terminal, tips, tricks
Posted in Command Line, Configuration, Tools | 5 Comments »
So far we looked at the GUI MP3 Players for linux – like Amarok, Exile, XMMS etc. Most linux users need only that – but there are some people who want a simpler system – command line players. The two top players in this area are mpg123 and mpg321.
mpg123 is a fast, free, minimalist, console MPEG audio player software program for UNIX and Linux operating systems. The development on this project ceased for a long time – but now it has a new maintainer.
mpg321 is a clone of mpg123.
Most distros have mpg321 in their repositories(not all have mpg123) – so just log in as root and use these commands to install it…
yum install mpg321 – For RedHat, Fedora, CentOS etc.
apt-get install mpg321 – For Debian, Ubuntu, etc.
Using mpg321 is straight forward. Since it has no GUI, just go to the folder with the song and just execute the command…
If you want to play all the songs in a folder, you have to create a list of files in that folder. Then you have to specify this list as an argument for the mpg321 command. These commands can get the job done…
Create a list of all MP3 Files in the current folder…
find . -name "*.mp3"|sed 's/\.\///;'|sort>List.lst
Use this list as the play list for mpg321
mpg123 --list List.lst
Why Use Command Line Players?
If we have a number of shiny GUI players, why should one use a command line player? Unless you are an anti-GUI command line guru, chances are you don’t need it. But still, it has its uses.
For example, if you have to restart the X Server often for some reason, then mpg321 is the best player for you. All other player will stop playing when X server is down.
This actually happend to me – when I bought my second LCD screen, it took me some time to configure it. And that meant editing the
xorg.conf file and restarting the X Server to see if it worked. At that time, I opened a virtual terminal(Ctrl+Alt+F1) and opened mpg321 with a bunch of MP3s in the list. It kept playing even if the X server is down. This is propably the reason that I was still sane after around six hours of XOrg configuration.
Tags: cli, mp3, mpg123, mpg321, player, review
Posted in Audio, Command Line, Tools | 11 Comments »
The mount command in Linux is a very powerful command. It can be used to mount any thing from a Samba mount to a ISO image file. The ability of the mount command to read ISO files makes it very useful for me.
My brother has a habit of saving DVD films as a image file. I believe he uses Alcohol 120% to do this. If he wants to view the Film, he ‘mount’ this image using Daemon Tools. He uses windows to do this. After he is done, he hands me this image. I can mount this image without any special tools in Linux – I just need the mount command.
mount -t iso9660 -o loop <Image_File> <Mount_Point>
mount -t iso9660 -o loop /home/binnyva/Films/300.iso /mnt/Image
The ‘-t’ option specifies the filetype – this is optional.
This command works with both ISO and MDF images.
Posted in Command Line, Tools | 25 Comments »
fish(Friendly Interactive Shell) is a new shell for Linux. I tried it out and have decided to dump bash for fish. Try it out – you will come to the same conclusion as well.
Features of fish
The shell colorizes the commands as you type them – if it is a valid command it will have a green color. For example, lets say I want to see my network interfaces. Recently, I had a lot of use for that – but that is another post. So, I type ifconfig into the shell. When I am at ‘ifco’, the shell will be like this…
When I have completed the command, ifconfig, the shell will be like this…
Strings, matching etc. are also highlighted as you type.
You would not think that this is a new feature. Bash has tab completion. Even Windows XP’s DOS terminal has tab completion. But fish’s tab completion is no ordinary tab completion – think of it as tab completion on steroids.
fish’s tab completion implements a feature that I really needed – tab completion for subcommands. Subcommand is the command line argument that is given to some programs. For example,
yum update gimp cvs commit file.php
In the first example,
yum is the command an ‘
update‘ is the subcommand. Just type ‘yum upd’ and press Tab to complete the command. Similarly in the second case
cvs is the command and
commit is the subcommand.
Many other completions are also supported…
- Commands, both builtins, functions and regular programs.
- Environment variable names (Eg. $HOME).
- Usernames for tilde(~) expansion.
- Filenames, even on strings with wildcards such as ‘*’, ‘**’ and ‘?’.
- Job id, job name and process names for process expansion. This is very useful when using
Enough talking. You can download the fish shell from their official website. For Red Hat/Fedora Core users, this command will do the trick.
yum install fish
If you are a debian or Ubuntu user, use this command
apt-get install fish
Tags: bash, fish, shell, terminal
Posted in Command Line, Tools | 5 Comments »