Today I discovered you can make less act like tail -f .
less filename , then press Shift-F to start follow mode.
Just like tail, but you have all the added features of less - like scrolling, searching, and the highlighting of search hits.
I've been watching log files with tail for years.
This just made me ponder: are there other commands that are outdated and have powerful alternatives?
Please share the bliss - a single command per post.
Source: Tips4all
I like to point to my ack, an alternative to grep for programmers.
ReplyDeletehttp://betterthangrep.com/
I'm surprised people (including me) have lived with cobbled-together aliases and shell scripts with find & xargs for so long.
The most obvious:
ReplyDeleteless is more.
Try htop -- top on steroids.
ReplyDeleteTry multitail -- tail on steroids.
Rsync replaces/complements most file transfer methods (scp, rcp, piped tar commands etc, and even cp in many cases) in an efficient and powerful way.
ReplyDeleteDue to its versatility, it has a lot of options. But I really recommend to learn at least the basics of rsync.
rsh/rexec/rcp/etc. have been supplanted by ssh/scp/etc.
ReplyDeleteNot exactly replacements for anything, but moreutils is a collection of small Unixy tools, which are basically meant to fill holes in the *nix toolbox.
ReplyDeleteSince, you only wanted one command per post, I guess I'll have to choose sponge, which allows you to save the output of a pipe to one of the files used as input. IOW, it allows you to modify files in-place, without having to worry about temporary files.
For example, if you do:
grep 'something' somefile.txt > somefile.txt
somefile.txt will end up empty. So, you could use sponge:
grep 'something' somefile.txt | sponge somefile.txt
Context sensitive autocompletion.
ReplyDeleteWell, I know, it's not a command and it's unlikely to be found on many Unices, but Linux. In my Ubuntu Hardy, bash_completion is already configured very well, and that means not only for files and direcotires! For example if I type
svn pr<TAB><TAB>
I get:
praise propdel propedit propget proplist propset
And even
svn propget svn:k<TAB>
I get automaticaly
svn propget svn:keywords
It works also for ant and make automatically reading the default files or the ones specified on the commandline! That's a real time saver!
The question and tags are contradictory. Linux isn't Unix (stupid Open Group), and most "real" Unix boxes don't have anywhere close to the software that Linux does. As an example, on a fairly plain AIX 5.3pl6 install:
ReplyDelete$ less
ksh: less: not found.
And yes, I admin these systems, but we've agreed to not load non-core components in most cases since we need them to match the deployed systems in the field.
It's great to have the newer tools in your toolbox, but if you don't know the "old school" way then you're going to be in a world of hurt if you're ever on a AIX/Solaris/HP-UX/etc system which doesn't have the newer tools (and may not even have bash).
Note, on our development VM I do have as many modern tools installed as I can find, simply because while I can work in a more plain environment, it doesn't mean that I enjoy it. And I do as much work as possible on our Linux (CentOS 5) system, simply because the tools on it are still newer than anything I can find readily packaged for AIX (Solaris is somewhat better; HP-UX is infinitely worse).
netcat should be universally replaced by socat.
ReplyDeleteOne might say that awk has been completely obsoleted by perl.
ReplyDeleteHowever, since I was using awk since before perl existed, I still use it; as for more serious scripts, I use python instead of perl.
It's worth having a look at the GNU versions of some commonplace commands, since they've quietly acquired useful refinements beyond the standard (XPG4, etc.) versions.
ReplyDeleteFor example, recursive grep is much nicer than find | xargs grep.
Also, find ... -print0 | xargs -0 ... handles the long-standing horrible quoting problem that makes xargs fail to handle funky space-filled filenames properly.
GNU tar takes 'j' and 'z' flags to handle bzipped and gzipped archives directly.
And bash's $() alternative to backticks makes the occasional nested backquoted expression easier to read and write.
pax is a replacement for tar and cpio, with a sane set of command-line options: -r to read from an archive, -w to write to an archive, -rw to do tree-to-tree copies. It also provides a -s option to allow you to perform substitutions on filenames before reading/writing a file from/to an archive. :-)
ReplyDeleteEdit: Mark Baker makes an interesting point (in comments) that I should clarify. pax makes pax archives (which are an extension of ustar, and can be unpacked by most tar programs) by default. But, with the -x option, it can be made to create cpio archives and ustar archives (these two are guaranteed by the standard). Some implementations, such as the BSD one, support creating even more types, such as old-style (pre-ustar) tar archives.
mtr is a traceroute replacement (it is a combination ping and traceroute).
ReplyDeleteUnlike traceroute, it finds the route almost immediately (since it doesn't wait for a response before moving to the next hop).
The command line version is installed by default in Debian (package mtr-tiny).
Not really a replacement for an outdated command per se, but screen is a great alternative to opening multiple terminal windows and/or using bg, etc.
ReplyDeleteOn Linux, ip (from the iproute2 package) behaves more predictably and gives easier-to-parse output than ifconfig/route.
ReplyDelete'rename' is a good alternative to the long oneliners one writes to change name to a bunch of files.
ReplyDeletedig instead of nslookup
ReplyDeletebm (link), instead of popd and pushd or creating temporary aliases, is really useful.
ReplyDeleteTo add a directory to be called with tag
bm -a /path/to/a/dir tag
To go to this directory
cdbm tag
Wherever glibc is installed, you can getent passwd foo instead of grep foo /etc/passwd (similarly for aliases ethers group hosts netgroup networks protocols rpc services shadow) -- it even Does The Right Thing(TM) in an NIS setup.
ReplyDeleteWhy bother typing gzip -dc foo.tar.gz | tar xf - when tar xzf foo.tar.gz will spawn the decompressor for you?
ReplyDeleteGoing even further... why bother typing tar xzf foo.tar.gz or tar xjf foo.tar.bz2 when GNUtar will automatically detect compression? tar xf foo.tar.(gz|bz2) just magically works.
I'm not sure if this should be an answer or merely an edit to the question.
ReplyDeleteBefore using less as a tail replacement, you can search for something "/search_string" and THEN invoke the Follow command (shift-F). Now any "search_strings" that scroll by will be highlighted. This is useful for when you're scanning a bunch of program output or logs and are looking for a particular string or pattern.
Don't forget that you can use regular expressions, too!
atool: handling archives without headaches
ReplyDeleteSome examples:
aunpack archive.tgz Unpacks all the files in the archive.
If the author of the archive was so
inconsiderate as to put multiple files
in the archive’s root, the command
automatically creates a directory and
moves the files inside.
aunpack -e archive1.tgz archive2.zip Unpacks each archive.
apack archive.tar.bz2 *.txt Creates a new compressed archive containing
all text files in the current working
directory.
als archive.rar Shows the names of the files contained in the archive.
Examples are from: http://debaday.debian.net/2008/12/28/atool-handling-archives-without-headaches/
ifconfig and iwconfig are deprecated in favor of ip which is a extremely powerful tool to show / manipulate routing, devices, policy routing and tunnels.
ReplyDeleteThe Perl Pie: perl -pi -e 's/foo/bar/' instead of sed 's/foo/bar/', with the much more powerful perlre syntax. (It's not quite a drop-in replacement, since Perl regexes use, for example, ? instead of \?.)
ReplyDeleteIf you're on a GNU system, don't use sed '1!G;h;$!d'; instead, use tac.
ReplyDeletecfdisk is an easy-to-use upgrade of the command-line drive partitioning utility fdisk.
ReplyDeleteI find that wcalc is a nice replacement for bc
ReplyDeletear(1) archives; tar is almost always used instead. ar does continue to have some limited uses; .deb package files are actually ar archives, for example, and the .a library libraries used for static compilation are actually ar archives containing a bunch of .o object files.
ReplyDeleteEssentially, in the few places where ar is used, its existence is hidden away.
compress -- replaced by gzip (even available on traditional Unix systems by default now). It can handle .Z files. More importantly, gzip is faster and creates smaller output than compress.
ReplyDeleteBut, less is still no replacement for 'tail -f'. If you need to filter a log in realtime for a live test, less won't beat 'tail -f | grep xxxxx'.
ReplyDelete