views:

3522

answers:

33

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.

+1  A: 

I find that wcalc is a nice replacement for bc

Draemon
the problem with wcalc , that it is not installed by default in a linux system
bmwael
Fair point. But then neither is sudo (at least on debian) and I consider that vital.
Draemon
+19  A: 

The most obvious:

less is more.

William
and more is most...
Paco
+8  A: 

One might say that awk has been completely obsoleted by perl.

However, since I was using awk since before perl existed, I still use it; as for more serious scripts, I use python instead of perl.

ΤΖΩΤΖΙΟΥ
A significant advantage of perl over awk is that perl behaves the same way on all platforms. You cannot say the same for awk. Just look at awk/nawk on Solaris, and compare awk there with awk (gawk) on any Linux system, or awk on another Unix box. Fun!
Zathrus
"The AWK programming language"-style awk scripts that I wrote pre-1995 for a client still run unmodified, on HP-UX then, on Debian now. In many systems, awk pointed to nawk, or gawk, true. But so did perl (and I'm talking about versions), so I don't see any difference.
ΤΖΩΤΖΙΟΥ
well gnu awk compiles pretty much everywhere, so as long as you target gnu awk you are fine
Luka Marinko
awk starts faster and is easier to use if you're doing delimited parsing. It's far from obsolete. :)
dannysauer
I read a similar story at http://www.samiam.org/perl.bug.html -- "At this point, I gave up. These days, I write in either awk (for simple stuff) or Python (for complicated stuff)."
system PAUSE
@system PAUSE - to fix the problem, he should have used binmode(STDIN, ":utf8"); to make STDIN read as UTF-8. STDIN is, by default, UTF-8 for characters 0-127, and characters 256+, but not 128-255 for backwards compatibility. "use utf8;" allows UTF-8 in the program's source code, not I/O.
Chris Lutz
+4  A: 

'rename' is a good alternative to the long oneliners one writes to change name to a bunch of files.

Federico Ramponi
Not familiar with that one, but your description sounds like the basic functionality is the same as 'mmv' ("mass mv").
Dave Sherohman
Watch out with rename, there are two different versions. One ships with perl (and is the default on Debian-based distros), and one is a much less functional one that at least RedHat shipped as default for a while.
derobert
+30  A: 

I like to point to my ack, an alternative to grep for programmers.

http://petdance.com/ack/

I'm surprised people (including me) have lived with cobbled-together aliases and shell scripts with find & xargs for so long.

Andy Lester
`ack` is like a gift from the gods, thank you!
ephemient
Thanks for the kind words. Just tell your friends about it.
Andy Lester
We use this at my place, it is freakin' awesome. If only so I don't have to "| grep -v '.svn'" all the time ;)
Danny
Ahhh the bliss ... sudo apt-get ack-grep has made me very happy today :)
Sam Saffron
ack is slow in my experience. Also it's not as "UNIXy" as it replaces find and grep rather than enhancing them. I prefer a simple wrapper around find and grep myself: http://www.pixelbeat.org/scripts/findrepo
pixelbeat
+8  A: 

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.

For 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.

fcw
The $() syntax is indeed much nicer, but it's not just bash - it is in the POSIX standard so should be in any shell these days.
Mark Baker
Actually, $() originated in ksh. And while it may be POSIX, it's not supported by /sbin/sh or /usr/bin/sh on Solaris. You have to use /usr/xpg4/bin/sh if you want a POSIX-compliant "sh" (or use ksh or bash, which are also supplied by default).
Zathrus
The j and z flags are not even required with recent GNU tar, you just run "tar xf foo.tar.gz" and it figures out that it needs to be run through gzip.
Ted Percival
Actually all your points are slightly innaurate Andy :)find | xargs grep, is now standardized as: find ... -exec grep {} +
pixelbeat
+7  A: 

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. :-)

Edit: 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.

Chris Jester-Young
Yes, except then you end up with pax files which no-one will know what to do with, and which you have to compress separately.
Mark Baker
Actually, I've just noticed that the BSD implementation of pax supports tar archives and has a -z option to compress them. But they're not part of the standard and are not mentioned on the page you cite.
Mark Baker
pax supports both tar and cpio archives. If not, it'd be useless for mainstream archiving purposes! -z is not standard pax, but it's not standard tar either (and it's not supported on native Solaris, say). So by habit I've always done "gunzip -c ... | tar xf -" or "gunzip -c ... | pax -r". :-)
Chris Jester-Young
Now, Jörg Schilling's tar, "star", has a complementary program called "spax". Both star and spax support -z and -bz options for doing gzip and bzip2 compression, respectively. (Yes, I know, it's not -j like GNU tar; but I never liked -j very much anyway.)
Chris Jester-Young
+9  A: 

Not exactly replacements for anything, but moreutils is a collection of small Unixy tools, which are basically meant to fill holes in the *nix toolbox.

Since, 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
skoob
+13  A: 

rsh/rexec/rcp/etc. have been supplanted by ssh/scp/etc.

ephemient
I voted you up, but you _should_ split your answer to separate answers, one-command-per-answer as requested by the question.
ΤΖΩΤΖΙΟΥ
I hate releasing a flood of answers to one question, but you're right, the question does ask for one-command-per-answer.
ephemient
+6  A: 

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.

mmacaulay
tmux is even better these days
Wahnfrieden
+3  A: 

bm (link), instead of popd and pushd or creating temporary aliases, is really useful.

To add a directory to be called with tag

bm -a /path/to/a/dir tag

To go to this directory

cdbm tag
HoboBen
That looks quite handy in many cases, but not in the situations where pushd and popd are typically used.
Mark Baker
+6  A: 

netcat should be universally replaced by socat.

ephemient
On linux, using bash, netcat can be replaced by the special /dev/tcp/hostname/portnumber and /etc/udp/hostname/portnumber files
dannysauer
Only if Bash is compiled with TCP support enabled, which I don't believe is the default.
ephemient
+2  A: 

If you're on a GNU system, don't use sed '1!G;h;$!d'; instead, use tac.

ephemient
I didn't know that bit of sed, if I'd ever come across a system without tac and needed it I'd have probably spent ages poring over the manpage to sed, or most likely just given up and downloaded tac.
Mark Baker
I thought it was a well-known sed trick. 1!G: on every line except the first, append the hold buffer to the current line; h: move the current line to the hold buffer; $!d: on every line except the last, don't print the line.
ephemient
+5  A: 

On Linux, ip (from the iproute2 package) behaves more predictably and gives easier-to-parse output than ifconfig/route.

ephemient
Unfortunately the documentation is still very lacking.
niXar
+3  A: 

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.

ephemient
I used to have a dozen line C program for that. Nice tip.
Joshua
+3  A: 

Why bother typing gzip -dc foo.tar.gz | tar xf - when tar xzf foo.tar.gz will spawn the decompressor for you?

Going 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.

ephemient
Yes this is great on GNU/Linux. Unfortunately does not work with AIX.
Davide
I did specify *GNUtar*, did I not?
ephemient
I prefer atool for this: "aunpack foo.tar.gz" results in slightly less typing (aun<Tab>). I don't use it for _creating_ archives though, since it doesn't offer many options.
Ant P.
+11  A: 

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:

$ 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).

Zathrus
We used HP-UX when I was at uni (eng.cam.ac.uk) more than a decade ago, and it was awful then, I've not had the misfortune of using it since.
Mark Baker
And that is why Linux has been killing Unix for the last 15 years. Because this has been true of Linux (and the *BSDs) for that much time.
niXar
Oh, yes, and if we don't have any anaesthetic, you can make do with a tot of rum. Ridiculous.
Brent.Longborough
semiuseless
+1  A: 

ar(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.

Essentially, in the few places where ar is used, its existence is hidden away.

Simon Howard
If you ever want to build a static library you'll need to use ar directly (unless you use libtool, but I wouldn't reccommend it), but then again, who does?
Mark Baker
I believe that gcc -static will do it for you.
Simon Howard
+1  A: 

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.

Zathrus
Speaking of replacements: bzip2 compresses better than gzip, at the cost of being slower and taking more memory; lzma compresses better than bzip2, at the cost of being slower and taking more memory (during compression; decompression is still quite resource-efficient).
ephemient
@ephemient, bzip2 does NOT compress better than gzip! It just performs (a little) better on average. Similarly with lzma, but it's very rare to find lzma compressing worse than gzip or bzip2.
strager
strager: yes it does. for example, if you grab the latest Linux tarball from kernel.org, it's a 50MB .bz2 and a 64MB .gz. That's 4/5 the size, which AFAIK is not atypical. The higher computational requirements mean that gzip is still common in many places though.
Peter
+14  A: 

Context sensitive autocompletion.

Well, 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!

Davide
Nice tip, and I'd like to point out that this seems to be a feature of bash at least. Running msys bash on Windows, I get the same thing. Pretty amazing though.
Ibrahim
It works with git, too.
Baju
For some reason bash completion seems to be usually broken for me(especially for apt-get). zsh seems less finicky.
Roman A. Taycher
+3  A: 

I'm not sure if this should be an answer or merely an edit to the question.

Before 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!

Harvey
A: 

But, 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'.

What about "grep xxxxx < FILE | less" ? This beats tail (you can scroll back, search, pan right, etc). However, it can't do what tail -F does, so you do still need tail in some places.
bstpierre
Actually tail will only poll changes in the file once per second. Well with coreutils 7.4 on linux it will use inotify to get immediate updates. If that is not available you can get updates as fast as humans can parse with ¬tail -s.1 file`. Note also that if piping through grep you'll need it's --line-buffered option
pixelbeat
A: 

I agree with MadCoder that `tail -f' allows you to connect things using a pipe while less cannot. But less is easier for interactive sessions, which is what it is designed for. So strictly speaking this is not a replacement.

But other things may be. For example, vim replaced vi and ed virtually everywhere in the PC world, nano replaces pico (not because it's better but because it's free), mutt and pine basically replaced things like `mail' in many places. Bash is now dominant and replaced sh. The list can go on and on forever :)

PolyThinker
A: 

Not sure if it's a perfect replacement but "xtail" is a really nice improvement on "tail".
It can monitor multiple files at the same time. Hitting the interrupt key (commonly CTRL+C) will give you a summary of which files changed by how much.

Daisuke Shimamoto
[multitail][1] is really impressive too.[1]http://www.vanheusden.com/multitail/
scrible
+2  A: 

cfdisk is an easy-to-use upgrade of the command-line drive partitioning utility fdisk.

Colin
+2  A: 

atool: handling archives without headaches

Some 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/

Kalmi
+1  A: 

I really like locate as a substitute for find - much easier to use "locate filepattern" than "find / -name filepattern -print", and more efficient because it uses an index database.

You have to have the updatedb command run on a schedule to update the locate database; check your distro's man page for details.

gareth_bowles
you don't need '-print', because that is what find will do by default. Of course, if don't search a special directory, and the file isn't too fresh, locate is much faster - but is doesn't provide all the options of find.
user unknown
+9  A: 

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.

Due to its versatility, it has a lot of options. But I really recommend to learn at least the basics of rsync.

matli
+11  A: 

Try htop -- top on steroids.

Try multitail -- tail on steroids.

scrible
+2  A: 

mtr is a traceroute replacement (it is a combination ping and traceroute).

Unlike 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).

UdiM
A: 

innotail

Like tail, but uses the inotify file change notification instead of polling the filesystem. It makes the scrolling look smoother.

jds
coreutils-7.4 has inotify support built in
pixelbeat
A: 

I don't know if this qualifies as "outdated," but in my opinion awk makes sed utterly redundant.

JCCyC
+1  A: 

ifconfig and iwconfig are deprecated in favor of ip which is a extremely powerful tool to show / manipulate routing, devices, policy routing and tunnels.

Federico