Re:What's the one Linux command you wish you knew years ago?
by mrb on Sunday November 20, 2011 @04:28AM
(#3257714)
Nobody knows this: the bash extension <(cmd) to pass the output of a command, as if it was a file, to another command. Example to diff the list of files in 2 directories (a and b) without using temporary files:
Internally, bash creates a pipe and passes /dev/fd/XXX to the main command.
[ Parent
| on HN ]
Re:What's the one Linux command you wish you knew years ago?
by sixtofour on Sunday November 20, 2011 @04:52AM
(#3257745)
Just diff the two directories.
$ ls a b
a:
1 2 3 4
b:
1 2 3
# Yours:
$ diff -u <(cd a && find . | sort) <(cd b && find . | sort)
--- /dev/fd/63 2011-11-20 02:50:21.919072726 -0700
+++ /dev/fd/62 2011-11-20 02:50:21.919072726 -0700
@@ -2,4 +2,3 @@
./1
./2
./3
-./4
# Mine:
$ diff -u a b
diff -u a/1 b/1
--- a/1 2011-11-20 02:43:57.073130007 -0700
+++ b/1 2011-11-20 02:45:14.535912768 -0700
@@ -1 +1 @@
-1
+11
Only in a: 4
Maybe I'm missing something?
Re:What's the one Linux command you wish you knew years ago?
by jav on Sunday November 20, 2011 @05:41AM
(#3257825)
The OP's example is diffing listings of the two directories whereas your command is asking diff to directly work on the directories themselves.
Re:What's the one Linux command you wish you knew years ago?
by robertskmiles on Sunday November 20, 2011 @08:51AM
(#3258090)
Which means for example you could get that listing in any format, so you could for example spot changes in permissions or ownership if you included it in the listing.
Re:What's the one Linux command you wish you knew years ago?
by sixtofour on Sunday November 20, 2011 @11:16AM
(#3258362)
I stand enlightened.
Re:What's the one Linux command you wish you knew years ago?
by super_mario on Monday November 21, 2011 @08:37AM
(#3261025)
Yes, you are because the example was contrived. The point is that process substitution (as it is called) is available on systems that support named pipes. You could think of better uses for it.