A Means To An End

Posted on 15th October 2008

Recently I was pointed at a blog post, entitled "8 Unix Tricks You Didn't Know". Although 7 I did know, there were 2 entries that I felt I could extend. I sent the author of the blog a mail, so hopefully he may add them (I don't have a Moveable Type, Live Journal or Vox account ... I know, I'm so unhip! ... so cannot add a comment). In the meantime, I thought I'd add them here, and include a couple of extra tips that I use regularly.

Firstly, for entry 6, an addition to the '+' syntax, you can also write something like 'vi +' (without any number after the '+'). vi then will open the file and immediately start on the last line of the file. This is extremely handy when editing a large file that you wish to edit from the end.

Secondly, for entry 8, while the method described works when you only editing one file, and in fact will work with any control character (change Ctrl-M to Ctrl-I and it will remove tabs), but if you have several it can be a bit labourious. An alternative is to install the 'sysutils' package and use 'dos2unix' command line program. I use this all the time to ensure that any file that could potentially have been edited in a Windows environment is sanitised for Linux.

So those were the ones that were already listed, but there another couple of tips that I use, that I am occasionally surprised to discover that others don't. So I thought I share them here. These two are specifically aimed at monitoring:

'tail -f filename'

'tail' lists the last few lines of a file (you can specify how many or use the default of 10). By adding the '-f' option the tail will continue to display lines from the file, that are freshly written by other applications. This is especially useful when watching output files, such as log files.

'watch "command"'

I only came across 'watch' in the last year or so, and now use it all the time. It takes a command line argument and repeats the command every 2 seconds. Instead of repeatedly typing the command you want (or Up-Arrow/Return if you use your command line history), 'watch' will do that for you. A common one I use is 'watch "ls -altr | tail"', particularly in my apache web logs folder, so I can see which websites are being looked at most recently, and more importantly, quickly spot when something has been written to an error.log file.

Speaking of the history file, you might not be aware of the Ctrl-R history search feature in bash. On the command line enter Ctrl-R and then type a sequence of characters. bash will then attempt to auto-complete the command you have previously used. I particularly use this when trying to remember what the IP address is of the server I waht to SSH to.

So these are just a few of mine. I'm sure there are plenty of others that other people use too. It's reminded me that I really ought to add Linux Server Hacks and Linux Server Hacks, Volume Two to my Christmas wishlist :)

Comments

Too many Linux / Unix hacks

There are too many of these little tweaks, and utilities. Bad vi/vim habits are in my muscle memory, so I'll never be a vim power user. I feel happy just to have got "mmv" into my repetoire of commands in the last year, the brain is ossifying, I need a new challenge. "paste" I've known about since I first learn Unix, and never used it in anger that I recall. "split" I have used. "incron" is not nearly as useful as I expected, but unlike "paste" I do have it doing useful stuff, even if it is just resetting permissions where getting them right each time FTP/Apache/or SVN updated a directory just got too complex.

Posted by Simon on Friday, 17th October 2008


gnu tail

tail -F will even keep going if the file handle is closed (think logrotate kicking in)

Posted by pfig on Tuesday, 9th December 2008


Add A Comment

Ignore this:
Subject *
Your Name *
Comment *
Link

Some Rights Reserved Unless otherwise expressly stated, all original material of whatever nature created by Barbie and included in the Memories Of A Roadie website and any related pages, including the website's archives, is licensed under a Creative Commons by Attribution Non-Commercial License. If you wish to use material for commercial puposes, please contact me for further assistance regarding commercial licensing.