how to remove image files that are smaller than certain dimensions

Multi tool use
I have already found an answer that lists pretty much everything. Except I cannot get it to work.
I use:
find . -iname "*.jpg" -type f | xargs -I{} identify -format '%w %h %i' {} | awk '$1<300 || $2<300{print $3}'
What is needed to remove the output files?
I tried adding | rm at the end but an error shows that im missing an opperand. I want all the files that the code above prints to be deleted.
Can someone please help
rm pipe
add a comment |
I have already found an answer that lists pretty much everything. Except I cannot get it to work.
I use:
find . -iname "*.jpg" -type f | xargs -I{} identify -format '%w %h %i' {} | awk '$1<300 || $2<300{print $3}'
What is needed to remove the output files?
I tried adding | rm at the end but an error shows that im missing an opperand. I want all the files that the code above prints to be deleted.
Can someone please help
rm pipe
I think you can use rm $(find...$3}'). In other words, wrap the above command inside the parens in $() to use the results as an argument to rm.
– chaskes
Feb 4 '15 at 23:52
It worked thanks. (Late) Positive feedback.
– Julio Sitges
Feb 18 '15 at 19:47
Cool. Thanks for letting me know. I'll move it to an answer.
– chaskes
Feb 18 '15 at 20:05
add a comment |
I have already found an answer that lists pretty much everything. Except I cannot get it to work.
I use:
find . -iname "*.jpg" -type f | xargs -I{} identify -format '%w %h %i' {} | awk '$1<300 || $2<300{print $3}'
What is needed to remove the output files?
I tried adding | rm at the end but an error shows that im missing an opperand. I want all the files that the code above prints to be deleted.
Can someone please help
rm pipe
I have already found an answer that lists pretty much everything. Except I cannot get it to work.
I use:
find . -iname "*.jpg" -type f | xargs -I{} identify -format '%w %h %i' {} | awk '$1<300 || $2<300{print $3}'
What is needed to remove the output files?
I tried adding | rm at the end but an error shows that im missing an opperand. I want all the files that the code above prints to be deleted.
Can someone please help
rm pipe
rm pipe
edited 2 days ago


PerlDuck
6,08211334
6,08211334
asked Feb 4 '15 at 23:11
Julio SitgesJulio Sitges
135
135
I think you can use rm $(find...$3}'). In other words, wrap the above command inside the parens in $() to use the results as an argument to rm.
– chaskes
Feb 4 '15 at 23:52
It worked thanks. (Late) Positive feedback.
– Julio Sitges
Feb 18 '15 at 19:47
Cool. Thanks for letting me know. I'll move it to an answer.
– chaskes
Feb 18 '15 at 20:05
add a comment |
I think you can use rm $(find...$3}'). In other words, wrap the above command inside the parens in $() to use the results as an argument to rm.
– chaskes
Feb 4 '15 at 23:52
It worked thanks. (Late) Positive feedback.
– Julio Sitges
Feb 18 '15 at 19:47
Cool. Thanks for letting me know. I'll move it to an answer.
– chaskes
Feb 18 '15 at 20:05
I think you can use rm $(find...$3}'). In other words, wrap the above command inside the parens in $() to use the results as an argument to rm.
– chaskes
Feb 4 '15 at 23:52
I think you can use rm $(find...$3}'). In other words, wrap the above command inside the parens in $() to use the results as an argument to rm.
– chaskes
Feb 4 '15 at 23:52
It worked thanks. (Late) Positive feedback.
– Julio Sitges
Feb 18 '15 at 19:47
It worked thanks. (Late) Positive feedback.
– Julio Sitges
Feb 18 '15 at 19:47
Cool. Thanks for letting me know. I'll move it to an answer.
– chaskes
Feb 18 '15 at 20:05
Cool. Thanks for letting me know. I'll move it to an answer.
– chaskes
Feb 18 '15 at 20:05
add a comment |
3 Answers
3
active
oldest
votes
You should be able to use rm $(find...$3}')
.
In other words, wrap the above command inside the parentheses in $() to use the results as an argument to rm
.
add a comment |
rm
doesn't read filenames from input. You can probably do:
find . -iname "*.jpg" -type f -exec bash -c 'for i; do size=($(identify -format "%w %h" "$i")); (( size[1] < 300 || size[2] < 300 )) && rm -v "$i"' remove-files {} +
- You can use
-exec
instead ofxargs
.
The bash command:
for i
do
size=($(identify -format "%w %h" "$i"))
(( size[1] < 300 || size[2] < 300 )) && rm -v "$i"
done
- loops over all the input arguments (
for i
) - gets the size and stores it in an array (that's why there are parentheses around
$()
:($(identify -format "%w %h" "$i"))
- uses shell arithmetic
(( ))
to do the comparison
add a comment |
The following works and is very fast.
Save to ~/checksize.sh and make it executable with chmod (chmod +x ~/checksize.sh
)
#! /bin/bash
#find . -type f -exec bash -c ~/checksize.sh ;
echo ${@}
if [ -z "$1" ]
then
echo "$1 empty" >&2
exit
fi
size=($(identify -format "%w %h" "$1" | tr -d "()"))
#echo ${size[@]}
#echo ${size[0]}
#echo ${size[1]}
if [ ${size[0]} -lt 300 -a ${size[1]} -lt 300 ]
then
rm -v "$1"
fi
Then change directory into the directory you want to remove the files that are too small from.
After cd'ing into the directory, run the following: find . -type f | xargs -P 0 -L 1 ~/checksize.sh
It runs fast because it uses xarg's -P 0 which makes xarg
run with the maximum amount of paralellity possible. See its man page for details.
New contributor
Noel Kuntze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f581784%2fhow-to-remove-image-files-that-are-smaller-than-certain-dimensions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should be able to use rm $(find...$3}')
.
In other words, wrap the above command inside the parentheses in $() to use the results as an argument to rm
.
add a comment |
You should be able to use rm $(find...$3}')
.
In other words, wrap the above command inside the parentheses in $() to use the results as an argument to rm
.
add a comment |
You should be able to use rm $(find...$3}')
.
In other words, wrap the above command inside the parentheses in $() to use the results as an argument to rm
.
You should be able to use rm $(find...$3}')
.
In other words, wrap the above command inside the parentheses in $() to use the results as an argument to rm
.
answered Feb 18 '15 at 20:06


chaskeschaskes
13.1k74159
13.1k74159
add a comment |
add a comment |
rm
doesn't read filenames from input. You can probably do:
find . -iname "*.jpg" -type f -exec bash -c 'for i; do size=($(identify -format "%w %h" "$i")); (( size[1] < 300 || size[2] < 300 )) && rm -v "$i"' remove-files {} +
- You can use
-exec
instead ofxargs
.
The bash command:
for i
do
size=($(identify -format "%w %h" "$i"))
(( size[1] < 300 || size[2] < 300 )) && rm -v "$i"
done
- loops over all the input arguments (
for i
) - gets the size and stores it in an array (that's why there are parentheses around
$()
:($(identify -format "%w %h" "$i"))
- uses shell arithmetic
(( ))
to do the comparison
add a comment |
rm
doesn't read filenames from input. You can probably do:
find . -iname "*.jpg" -type f -exec bash -c 'for i; do size=($(identify -format "%w %h" "$i")); (( size[1] < 300 || size[2] < 300 )) && rm -v "$i"' remove-files {} +
- You can use
-exec
instead ofxargs
.
The bash command:
for i
do
size=($(identify -format "%w %h" "$i"))
(( size[1] < 300 || size[2] < 300 )) && rm -v "$i"
done
- loops over all the input arguments (
for i
) - gets the size and stores it in an array (that's why there are parentheses around
$()
:($(identify -format "%w %h" "$i"))
- uses shell arithmetic
(( ))
to do the comparison
add a comment |
rm
doesn't read filenames from input. You can probably do:
find . -iname "*.jpg" -type f -exec bash -c 'for i; do size=($(identify -format "%w %h" "$i")); (( size[1] < 300 || size[2] < 300 )) && rm -v "$i"' remove-files {} +
- You can use
-exec
instead ofxargs
.
The bash command:
for i
do
size=($(identify -format "%w %h" "$i"))
(( size[1] < 300 || size[2] < 300 )) && rm -v "$i"
done
- loops over all the input arguments (
for i
) - gets the size and stores it in an array (that's why there are parentheses around
$()
:($(identify -format "%w %h" "$i"))
- uses shell arithmetic
(( ))
to do the comparison
rm
doesn't read filenames from input. You can probably do:
find . -iname "*.jpg" -type f -exec bash -c 'for i; do size=($(identify -format "%w %h" "$i")); (( size[1] < 300 || size[2] < 300 )) && rm -v "$i"' remove-files {} +
- You can use
-exec
instead ofxargs
.
The bash command:
for i
do
size=($(identify -format "%w %h" "$i"))
(( size[1] < 300 || size[2] < 300 )) && rm -v "$i"
done
- loops over all the input arguments (
for i
) - gets the size and stores it in an array (that's why there are parentheses around
$()
:($(identify -format "%w %h" "$i"))
- uses shell arithmetic
(( ))
to do the comparison
answered Feb 4 '15 at 23:56


murumuru
1
1
add a comment |
add a comment |
The following works and is very fast.
Save to ~/checksize.sh and make it executable with chmod (chmod +x ~/checksize.sh
)
#! /bin/bash
#find . -type f -exec bash -c ~/checksize.sh ;
echo ${@}
if [ -z "$1" ]
then
echo "$1 empty" >&2
exit
fi
size=($(identify -format "%w %h" "$1" | tr -d "()"))
#echo ${size[@]}
#echo ${size[0]}
#echo ${size[1]}
if [ ${size[0]} -lt 300 -a ${size[1]} -lt 300 ]
then
rm -v "$1"
fi
Then change directory into the directory you want to remove the files that are too small from.
After cd'ing into the directory, run the following: find . -type f | xargs -P 0 -L 1 ~/checksize.sh
It runs fast because it uses xarg's -P 0 which makes xarg
run with the maximum amount of paralellity possible. See its man page for details.
New contributor
Noel Kuntze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
The following works and is very fast.
Save to ~/checksize.sh and make it executable with chmod (chmod +x ~/checksize.sh
)
#! /bin/bash
#find . -type f -exec bash -c ~/checksize.sh ;
echo ${@}
if [ -z "$1" ]
then
echo "$1 empty" >&2
exit
fi
size=($(identify -format "%w %h" "$1" | tr -d "()"))
#echo ${size[@]}
#echo ${size[0]}
#echo ${size[1]}
if [ ${size[0]} -lt 300 -a ${size[1]} -lt 300 ]
then
rm -v "$1"
fi
Then change directory into the directory you want to remove the files that are too small from.
After cd'ing into the directory, run the following: find . -type f | xargs -P 0 -L 1 ~/checksize.sh
It runs fast because it uses xarg's -P 0 which makes xarg
run with the maximum amount of paralellity possible. See its man page for details.
New contributor
Noel Kuntze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
The following works and is very fast.
Save to ~/checksize.sh and make it executable with chmod (chmod +x ~/checksize.sh
)
#! /bin/bash
#find . -type f -exec bash -c ~/checksize.sh ;
echo ${@}
if [ -z "$1" ]
then
echo "$1 empty" >&2
exit
fi
size=($(identify -format "%w %h" "$1" | tr -d "()"))
#echo ${size[@]}
#echo ${size[0]}
#echo ${size[1]}
if [ ${size[0]} -lt 300 -a ${size[1]} -lt 300 ]
then
rm -v "$1"
fi
Then change directory into the directory you want to remove the files that are too small from.
After cd'ing into the directory, run the following: find . -type f | xargs -P 0 -L 1 ~/checksize.sh
It runs fast because it uses xarg's -P 0 which makes xarg
run with the maximum amount of paralellity possible. See its man page for details.
New contributor
Noel Kuntze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The following works and is very fast.
Save to ~/checksize.sh and make it executable with chmod (chmod +x ~/checksize.sh
)
#! /bin/bash
#find . -type f -exec bash -c ~/checksize.sh ;
echo ${@}
if [ -z "$1" ]
then
echo "$1 empty" >&2
exit
fi
size=($(identify -format "%w %h" "$1" | tr -d "()"))
#echo ${size[@]}
#echo ${size[0]}
#echo ${size[1]}
if [ ${size[0]} -lt 300 -a ${size[1]} -lt 300 ]
then
rm -v "$1"
fi
Then change directory into the directory you want to remove the files that are too small from.
After cd'ing into the directory, run the following: find . -type f | xargs -P 0 -L 1 ~/checksize.sh
It runs fast because it uses xarg's -P 0 which makes xarg
run with the maximum amount of paralellity possible. See its man page for details.
New contributor
Noel Kuntze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Noel Kuntze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 2 days ago


Noel KuntzeNoel Kuntze
1
1
New contributor
Noel Kuntze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Noel Kuntze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Noel Kuntze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f581784%2fhow-to-remove-image-files-that-are-smaller-than-certain-dimensions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
08 c H2b zsiM7,3pzhK D 9FiWMQq hiO4j,WEKfSx,T6KrIMhFjSSnPZOwz O
I think you can use rm $(find...$3}'). In other words, wrap the above command inside the parens in $() to use the results as an argument to rm.
– chaskes
Feb 4 '15 at 23:52
It worked thanks. (Late) Positive feedback.
– Julio Sitges
Feb 18 '15 at 19:47
Cool. Thanks for letting me know. I'll move it to an answer.
– chaskes
Feb 18 '15 at 20:05