Watch and cat the last file to enter a directory

watch "cat `ls -rcA1 | tail -n1`"
Great for watching things like Maildir's or any other queue directory.

1
By: donnoman
2011-03-25 01:22:05

These Might Interest You

  • After typing cd directory [enter] ls [enter] so many times, I figured I'd try to make it into a function. I was surprised how smoothly I was able to integrate it into my work on the command line. Just use cdls as you would cd. It will automatically list the directory contents after you cd into the directory. To make the command always available, add it to your .bashrc file. Not quite monumental, but still pretty convenient. Show Sample Output


    7
    function cdls { cd $1; ls; }
    joem86 · 2009-03-10 19:13:47 6
  • ^V means CTRL-V [ENTER] means ENTER key


    -3
    cat [ENTER]^V^O[ENTER]^D
    minliu2k · 2009-04-17 13:16:56 8
  • Locally watch MySQL process list update every 5s on a remote host. While you watch pipe to a file. The file out put is messy though but hey at least you have a history of what you see.


    -1
    watch -n 0.5 ssh [user]@[host] mysqladmin -u [mysql_user] -p[password] processlist | tee -a /to/a/file
    lunarblu · 2009-08-19 14:21:27 2
  • Most distributions alias cp to 'cp -i', which means when you attempt to copy into a directory that already contains the file, cp will prompt to overwrite. A great default to have, but when you mean to overwrite thousands of files, you don't want to sit there hitting [y] then [enter] thousands of times. Enter the backslash. It runs the command unaliased, so as in the example, cp will happily overwrite existing files much in the way mv works. Show Sample Output


    1
    \[command]
    tyzbit · 2015-01-15 18:31:50 0

What Others Think

You don't need the 'cat' in the middle, you can add -1 (one) to ls: watch "cat `ls -rcA1 | tail -n1`"
flatcap · 374 weeks and 1 day ago
Great, thanks for the tip, updated the command.
donnoman · 374 weeks and 1 day ago
zsh: watch cat *(om[1])
zolden · 374 weeks 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: