What's the one Linux command you wish you knew years ago?
11–20 of 216 posts
Re: What's the one Linux command you wish you knew years ago?
#12For me it was definitely find. I went through a ton of contortions to replicate its behavior several times before somebody knowledgeable clued me in. Also, `` and $(). Find combined with one of these is great. One of my favorite one-liners (I even figured it out myself :)) is: cat `find . --name *.java` | wc -l
Never thought to use ``. I always used xargs: find . -name *.java | xargs cat | wc -l
find . -iname '*.java' -exec cat {} + |wc -l
But if you do that, why not just: find . -iname '*.java' -exec wc -l {} +
Which will also print out output of wc -l for each files along with total lines.Re: What's the one Linux command you wish you knew years ago?
#13For me it was definitely find. I went through a ton of contortions to replicate its behavior several times before somebody knowledgeable clued me in. Also, `` and $(). Find combined with one of these is great. One of my favorite one-liners (I even figured it out myself :)) is: cat `find . --name *.java` | wc -l
wc -l $(find . -name '*.java')Re: What's the one Linux command you wish you knew years ago?
#14For me it was definitely find. I went through a ton of contortions to replicate its behavior several times before somebody knowledgeable clued me in. Also, `` and $(). Find combined with one of these is great. One of my favorite one-liners (I even figured it out myself :)) is: cat `find . --name *.java` | wc -l
For find, you need to use single quotes so your shell doesn't automatically expand the .java glob into the names of all the files. Also, find uses one dash for parameters, and can take an exec parameter: find . -name .java -exec wc -l {} \; The {} means "replace with filename" and the semicolon (escaped so your shell doesn't eat it). This will run wc -l for every file that matches. The -regex flag lets you do the sam…
-exec utility [argument ...] {} +
Same as -exec, except that ``{}'' is replaced with as many path-
names as possible for each invocation of utility. This behaviour
is similar to that of xargs(1).
The problem with just wc -l *.java is that it don't recursive directory.Re: What's the one Linux command you wish you knew years ago?
#15For me it was definitely find. I went through a ton of contortions to replicate its behavior several times before somebody knowledgeable clued me in. Also, `` and $(). Find combined with one of these is great. One of my favorite one-liners (I even figured it out myself :)) is: cat `find . --name *.java` | wc -l
You'll want to quote .java so the shell doesn't interpret it as a glob, and find doesn't use GNU style flags. You can also pass wc the filenames directly like this: wc -l $(find . -name '*.java')
find . -name \*.java -exec cat {} + | wc -lRe: What's the one Linux command you wish you knew years ago?
#16Re: What's the one Linux command you wish you knew years ago?
#17For me it was definitely find. I went through a ton of contortions to replicate its behavior several times before somebody knowledgeable clued me in. Also, `` and $(). Find combined with one of these is great. One of my favorite one-liners (I even figured it out myself :)) is: cat `find . --name *.java` | wc -l
You'll want to quote .java so the shell doesn't interpret it as a glob, and find doesn't use GNU style flags. You can also pass wc the filenames directly like this: wc -l $(find . -name '*.java')
I just use M-x find-dired and friends these days for most things, admittedly.
Re: What's the one Linux command you wish you knew years ago?
#18Earlier quoted context omitted.
For find, you need to use single quotes so your shell doesn't automatically expand the .java glob into the names of all the files. Also, find uses one dash for parameters, and can take an exec parameter: find . -name .java -exec wc -l {} \; The {} means "replace with filename" and the semicolon (escaped so your shell doesn't eat it). This will run wc -l for every file that matches. The -regex flag lets you do the sam…
You can skip xargs altogether with the plus sign instead of semicolon. -exec utility [argument ...] {} + Same as -exec, except that ``{}'' is replaced with as many path- names as possible for each invocation of utility. This behaviour is similar to that of xargs(1). The problem with just wc -l *.java is that it don't recursive directory.
wc -l **/*.javaRe: What's the one Linux command you wish you knew years ago?
#19For me it was definitely find. I went through a ton of contortions to replicate its behavior several times before somebody knowledgeable clued me in. Also, `` and $(). Find combined with one of these is great. One of my favorite one-liners (I even figured it out myself :)) is: cat `find . --name *.java` | wc -l
find . -mmin -5 -print