(> errors.log) && tail -f !^

Flush and then immediately start watching a file

This is useful for keeping an eye on an error log while developing. The !^ pulls the first arg from the previous command (which needs to be run in a sub-shell for this shortcut to work).

2
By: root
2009-02-03 16:08:19

These Might Interest You

  • Ever need to erase the contents of a file and start over from scratch? This easy command allows you to do so. Be warned! This will immediately erase all the contents of your file and start you over from scratch (i.e. your file will be at 0 bytes, like if you touch a file). Show Sample Output


    -3
    > [filename]
    bbbco · 2011-05-18 14:59:02 3
  • Flush the DNS cache under Ubuntu (Debian?)


    0
    sudo /etc/init.d/dns-clean
    varghjarta · 2012-08-06 18:40:49 0
  • Use the following key binding to search ---------------------------------------------------------------- ng : Jump to line number n. Default is the start of the file. nG : Jump to line number n. Default is the end of the file. /pattern : Search for pattern. Regular expressions can be used. [/ = slash] Press / and then Enter to repeat the previous search pattern. Press ESC and then u to undo search highlighting. n : Go to next match (after a successful search). N : Go to previous match. mletter : Mark the current position with letter. 'letter : Return to position letter. [' = single quote] '^ or g : Go to start of file. '$ or G : Go to end of file. s : Save current content (got from another program like grep) in a file. = or Ctrl+g : File information. F : continually read information from file and follow its end. Useful for logs watching. Use Ctrl+c to exit this mode. -option : Toggle command-line option -option. h : Help.


    -4
    less file.ext
    totti · 2011-09-13 10:29:27 3
  • Occasionally, to force zone updating, cache flush is necessary. The use of this command is better than restart the Bind9 process.


    2
    rndc flush
    ironmarc · 2011-10-21 14:27:05 0
  • GNU Sed can 'address' between two regex, but it continues parsing through to the end of the file. This slight alteration causes it to terminate reading the input file once the STOP match is made. In my example I have included an extra '/START/d' as my 'start' marker line contains the 'stop' string (I'm extracting data between 'resets' and using the time stamp as the 'start'). My previous coding using grep is slightly faster near the end of the file, but overall (extracting all the reset cycles in turn) the new SED method is quicker and a lot neater. Show Sample Output


    3
    sed -n '/START/,${/STOP/q;p}'
    mungewell · 2009-06-19 15:27:36 1
  • Prints the unique IP Addresses as they arrive from an Apache `access.log` file. The '-W interactive' tells awk to start writing to stdout immediately and not buffer the output. This command builds on the uniq lines without sorting command (http://www.commandlinefu.com/commands/view/4389/remove-duplicate-entries-in-a-file-without-sorting.)


    1
    tail -f /var/log/apache2/access.log | awk -W interactive '!x[$1]++ {print $1}'
    pykler · 2010-01-12 15:23:03 0

What Others Think

Nice tip, but be careful. !^ does not work in shell scripts.
pixelbeat · 484 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: