When doing a search like find -type d
, adding the -print0 argument right after the find command such as find -print0 -type d
causes the search to return more results than without it.
Find Command Returns Different Results with -print0
find
Related Solutions
I've had this in my ~/.screenrc
for a while:
bind -c pasteline 1 eval copy 'stuff "-Y"' 'paste .'
bind -c pasteline 2 eval copy 'stuff "2-Y"' 'paste .'
bind -c pasteline 3 eval copy 'stuff "3-Y"' 'paste .'
bind -c pasteline 4 eval copy 'stuff "4-Y"' 'paste .'
bind -c pasteline 5 eval copy 'stuff "5-Y"' 'paste .'
bind -c pasteline 6 eval copy 'stuff "6-Y"' 'paste .'
bind -c pasteline 7 eval copy 'stuff "7-Y"' 'paste .'
bind -c pasteline 8 eval copy 'stuff "8-Y"' 'paste .'
bind -c pasteline 9 eval copy 'stuff "9-Y"' 'paste .'
bindkey ¬ command -c pasteline
Basically, typing ¬1 from within screen, inserts the first line above the cursor, ¬2 the second line and so on.
In my ~/.Xdefaults
, I also have:
XTerm.VT100.translations: #override\
Meta <KeyPress> /: dabbrev-expand()
Which lets xterm
complete (upon Alt+/) on what's on the screen (looking backward from the cursor position).
With zsh
, when used within screen
, you could do:
copy-screen() {
screen -X eval copy 'stuff "-$ H\r"' 'writebuf .lastoutput'
killring=(${(Oaf)"$(<~/.lastoutput)"})
CUTBUFFER=$killring[1]
killring[1]=()
}
zle -N copy-screen
bindkey '\ec' copy-screen
to bind Alt+C to that widget that stores the lines above the cursor into the cut buffer and the kill ring (what you paste with Ctrl+Y and cycle through with Alt+Y in emacs
mode). (the above assumes screen
was started from your home directory).
If the inserted text needs to be quoted (because it contains spaces or other special shell characters for instance), you can type Alt+" for zsh
to quote it.
As an example, you've just run:
$ find /usr/local -size +1M
/usr/local/lib/liblzma.a
/usr/local/share/doc/sudo/ChangeLog
/usr/local/share/perl/5.18.2/Unicode/Unihan/Definition.db
/usr/local/share/perl/5.18.2/Unicode/Unihan/RSKangXi.db
/usr/local/share/perl/5.18.2/Unicode/Unihan/IRG_TSource.db
/usr/local/share/perl/5.18.2/Unicode/Unihan/HanYu.db
/usr/local/share/perl/5.18.2/Unicode/Unihan/RSUnicode.db
/usr/local/share/perl/5.18.2/Unicode/Unihan/IRG_GSource.db
/usr/local/share/perl/5.18.2/Unicode/Unihan/IRGKangXi.db
/usr/local/share/perl/5.18.2/Unicode/Unihan/IRGHanyuDaZidian.db
And you want to open vim
on that sudo ChangeLog above. With the first approach you'd type:
vim ¬9
With the second approach:
vim /usAlt+/
And repeat that Alt+/ until you get to the changelog.
With the third approach:
vim Alt+CCtrl+YAlt+Y
And repeat that Alt+Y until you get to the changelog.
The last approach can be used for your $s1
query.
Instead of storing in the killring
array, store in an array (like $s
) and use $s[1]
for the first line, $s[2]
for the second...
copy-screen() {
screen -X eval copy 'stuff "-$ H\r"' 'writebuf .lastoutput'
s=(${(Oaf)"$(<~/.lastoutput)"})
}
zle -N copy-screen
bindkey '\ec' copy-screen
That Alt+C stores the lines above the cursor in the s
array.
In any case, what we're retrieving is what is displayed on the screen, which is not necessarily the same as what the last command output. For instance printf 'a\bc \n'
outputs 5 bytes a
, BS, c
, SPC and LF, but displays just a c
.
To get each filename printed to the output and THEN have the grep results corresponding to that file printed after, you could wrap the -exec foo {} | grep
pipe in a shell:
find . -name '*.o' -type f -print -exec sh -c 'foo "$1" | grep "bar"' sh {} \;
To to make the -H
argument of grep work with standard input, if your version of grep
supports the --label=
option you could do
find . -name '*.o' -type f -exec sh -c '
foo "$1" | grep -H --label="$1" "bar"
' sh {} \;
or (if your find supports the +
multi-argument alternative to \;
):
find . -name '*.o' -type f -exec sh -c '
for f; do foo "$f" | grep -H --label="$f" "bar"; done
' sh {} +
Best Answer
If you understand the
&&
and||
operators in the shell (and also in C, C++, and derivative languages), then you understand-a
and-o
infind
.To refresh your memory:
In the shell,
runs
command1
, and, if it (command1
) succeeds, it (the shell) runscommand2
.runs
command1
, and, if it (command1
) fails, it (the shell) runscommand2
.In the compilable languages,
evaluates
expr1
. If it (expr1
) evaluates to false (zero), it returns that as the value of the overall expression. Otherwise (ifexpr1
evaluates to a true (non-zero) value), it evaluatesexpr2
and returns that as the value of the overall expression.evaluates
expr1
. If it (expr1
) evaluates to a true (non-zero) value, it returns that as the value of the overall expression. Otherwise (ifexpr1
evaluates to false (zero)) it evaluatesexpr2
and returns that as the value of the overall expression.Quoting from find(1),
The Open Group Specification for
find
has similar things to say:Both documents say, “If no expression is present, -print shall be used as the expression.”
---------------- TL;DR ----------------
So,
is equivalent to
which is equivalent to
which means,
-type d
test.-print
action.Whereas,
is equivalent to
which means,
-print
action (i.e., this happens for all files).-print
always is), evaluate the-type d
test.-type d
test is ignored.So there you have it.