xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option












2















I'd like to count all the ordinary file on home directory with commands:



$ find ~ -type f | xargs echo | wc -w
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option


It prompts



xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option


What's the problem with usage?










share|improve this question


















  • 1





    Do you really want to count the total number of words in all the filenames, or do you actually want to count the number of files? if the latter, then you can avoid processing the names altogether e.g. find ~ -type f -printf 1 | wc -c (print a single - arbitrary - character for each file, and count those)

    – steeldriver
    Jan 4 at 5:27


















2















I'd like to count all the ordinary file on home directory with commands:



$ find ~ -type f | xargs echo | wc -w
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option


It prompts



xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option


What's the problem with usage?










share|improve this question


















  • 1





    Do you really want to count the total number of words in all the filenames, or do you actually want to count the number of files? if the latter, then you can avoid processing the names altogether e.g. find ~ -type f -printf 1 | wc -c (print a single - arbitrary - character for each file, and count those)

    – steeldriver
    Jan 4 at 5:27
















2












2








2








I'd like to count all the ordinary file on home directory with commands:



$ find ~ -type f | xargs echo | wc -w
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option


It prompts



xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option


What's the problem with usage?










share|improve this question














I'd like to count all the ordinary file on home directory with commands:



$ find ~ -type f | xargs echo | wc -w
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option


It prompts



xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option


What's the problem with usage?







xargs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 4 at 5:07









user10726006user10726006

903




903








  • 1





    Do you really want to count the total number of words in all the filenames, or do you actually want to count the number of files? if the latter, then you can avoid processing the names altogether e.g. find ~ -type f -printf 1 | wc -c (print a single - arbitrary - character for each file, and count those)

    – steeldriver
    Jan 4 at 5:27
















  • 1





    Do you really want to count the total number of words in all the filenames, or do you actually want to count the number of files? if the latter, then you can avoid processing the names altogether e.g. find ~ -type f -printf 1 | wc -c (print a single - arbitrary - character for each file, and count those)

    – steeldriver
    Jan 4 at 5:27










1




1





Do you really want to count the total number of words in all the filenames, or do you actually want to count the number of files? if the latter, then you can avoid processing the names altogether e.g. find ~ -type f -printf 1 | wc -c (print a single - arbitrary - character for each file, and count those)

– steeldriver
Jan 4 at 5:27







Do you really want to count the total number of words in all the filenames, or do you actually want to count the number of files? if the latter, then you can avoid processing the names altogether e.g. find ~ -type f -printf 1 | wc -c (print a single - arbitrary - character for each file, and count those)

– steeldriver
Jan 4 at 5:27












1 Answer
1






active

oldest

votes


















6














It appears that some of your filenames have apostrophes (single quote) in their names.



Luckily, find and xargs have ways around this. find's -print0 option along with xargs's -0 option produce and consume a list of filenames separated by the NUL (00) character. Filenames in Linux may contain ANY character, EXCEPT NUL and /.



So, what you really want is:



 find ~ -type f -print0 | xargs -0 --no-run-if-empty wc -w


Read man find;man xargs.






share|improve this answer
























  • find ~ -type f | wc -l will work with more files, since xargs put all arguments on one command line and there is a limit in the number of args.

    – pim
    Jan 4 at 5:29













  • @pim While it may be correct that xargs can suffer from argument list too long error, in this answer -print0 and xargs -0 combination is perfectly acceptable. See unix.stackexchange.com/a/83803/85039

    – Sergiy Kolodyazhnyy
    Jan 4 at 8:38











  • I think the OP's use of wc -w may have led you to suppose they want to count the words inside the files - they're actually using xargs echo | wc -w which will count the number of words in the file names, which I think is more likely an attempt to count the number of files (although it doesn't take into account that filenames may contain whitespace). (Likewise, find ~ -type f | wc -l doesn't take into account that filenames may contain newlines.)

    – steeldriver
    Jan 4 at 13:34













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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1106805%2fxargs-unmatched-single-quote-by-default-quotes-are-special-to-xargs-unless-you%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














It appears that some of your filenames have apostrophes (single quote) in their names.



Luckily, find and xargs have ways around this. find's -print0 option along with xargs's -0 option produce and consume a list of filenames separated by the NUL (00) character. Filenames in Linux may contain ANY character, EXCEPT NUL and /.



So, what you really want is:



 find ~ -type f -print0 | xargs -0 --no-run-if-empty wc -w


Read man find;man xargs.






share|improve this answer
























  • find ~ -type f | wc -l will work with more files, since xargs put all arguments on one command line and there is a limit in the number of args.

    – pim
    Jan 4 at 5:29













  • @pim While it may be correct that xargs can suffer from argument list too long error, in this answer -print0 and xargs -0 combination is perfectly acceptable. See unix.stackexchange.com/a/83803/85039

    – Sergiy Kolodyazhnyy
    Jan 4 at 8:38











  • I think the OP's use of wc -w may have led you to suppose they want to count the words inside the files - they're actually using xargs echo | wc -w which will count the number of words in the file names, which I think is more likely an attempt to count the number of files (although it doesn't take into account that filenames may contain whitespace). (Likewise, find ~ -type f | wc -l doesn't take into account that filenames may contain newlines.)

    – steeldriver
    Jan 4 at 13:34


















6














It appears that some of your filenames have apostrophes (single quote) in their names.



Luckily, find and xargs have ways around this. find's -print0 option along with xargs's -0 option produce and consume a list of filenames separated by the NUL (00) character. Filenames in Linux may contain ANY character, EXCEPT NUL and /.



So, what you really want is:



 find ~ -type f -print0 | xargs -0 --no-run-if-empty wc -w


Read man find;man xargs.






share|improve this answer
























  • find ~ -type f | wc -l will work with more files, since xargs put all arguments on one command line and there is a limit in the number of args.

    – pim
    Jan 4 at 5:29













  • @pim While it may be correct that xargs can suffer from argument list too long error, in this answer -print0 and xargs -0 combination is perfectly acceptable. See unix.stackexchange.com/a/83803/85039

    – Sergiy Kolodyazhnyy
    Jan 4 at 8:38











  • I think the OP's use of wc -w may have led you to suppose they want to count the words inside the files - they're actually using xargs echo | wc -w which will count the number of words in the file names, which I think is more likely an attempt to count the number of files (although it doesn't take into account that filenames may contain whitespace). (Likewise, find ~ -type f | wc -l doesn't take into account that filenames may contain newlines.)

    – steeldriver
    Jan 4 at 13:34
















6












6








6







It appears that some of your filenames have apostrophes (single quote) in their names.



Luckily, find and xargs have ways around this. find's -print0 option along with xargs's -0 option produce and consume a list of filenames separated by the NUL (00) character. Filenames in Linux may contain ANY character, EXCEPT NUL and /.



So, what you really want is:



 find ~ -type f -print0 | xargs -0 --no-run-if-empty wc -w


Read man find;man xargs.






share|improve this answer













It appears that some of your filenames have apostrophes (single quote) in their names.



Luckily, find and xargs have ways around this. find's -print0 option along with xargs's -0 option produce and consume a list of filenames separated by the NUL (00) character. Filenames in Linux may contain ANY character, EXCEPT NUL and /.



So, what you really want is:



 find ~ -type f -print0 | xargs -0 --no-run-if-empty wc -w


Read man find;man xargs.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 4 at 5:19









waltinatorwaltinator

22k74169




22k74169













  • find ~ -type f | wc -l will work with more files, since xargs put all arguments on one command line and there is a limit in the number of args.

    – pim
    Jan 4 at 5:29













  • @pim While it may be correct that xargs can suffer from argument list too long error, in this answer -print0 and xargs -0 combination is perfectly acceptable. See unix.stackexchange.com/a/83803/85039

    – Sergiy Kolodyazhnyy
    Jan 4 at 8:38











  • I think the OP's use of wc -w may have led you to suppose they want to count the words inside the files - they're actually using xargs echo | wc -w which will count the number of words in the file names, which I think is more likely an attempt to count the number of files (although it doesn't take into account that filenames may contain whitespace). (Likewise, find ~ -type f | wc -l doesn't take into account that filenames may contain newlines.)

    – steeldriver
    Jan 4 at 13:34





















  • find ~ -type f | wc -l will work with more files, since xargs put all arguments on one command line and there is a limit in the number of args.

    – pim
    Jan 4 at 5:29













  • @pim While it may be correct that xargs can suffer from argument list too long error, in this answer -print0 and xargs -0 combination is perfectly acceptable. See unix.stackexchange.com/a/83803/85039

    – Sergiy Kolodyazhnyy
    Jan 4 at 8:38











  • I think the OP's use of wc -w may have led you to suppose they want to count the words inside the files - they're actually using xargs echo | wc -w which will count the number of words in the file names, which I think is more likely an attempt to count the number of files (although it doesn't take into account that filenames may contain whitespace). (Likewise, find ~ -type f | wc -l doesn't take into account that filenames may contain newlines.)

    – steeldriver
    Jan 4 at 13:34



















find ~ -type f | wc -l will work with more files, since xargs put all arguments on one command line and there is a limit in the number of args.

– pim
Jan 4 at 5:29







find ~ -type f | wc -l will work with more files, since xargs put all arguments on one command line and there is a limit in the number of args.

– pim
Jan 4 at 5:29















@pim While it may be correct that xargs can suffer from argument list too long error, in this answer -print0 and xargs -0 combination is perfectly acceptable. See unix.stackexchange.com/a/83803/85039

– Sergiy Kolodyazhnyy
Jan 4 at 8:38





@pim While it may be correct that xargs can suffer from argument list too long error, in this answer -print0 and xargs -0 combination is perfectly acceptable. See unix.stackexchange.com/a/83803/85039

– Sergiy Kolodyazhnyy
Jan 4 at 8:38













I think the OP's use of wc -w may have led you to suppose they want to count the words inside the files - they're actually using xargs echo | wc -w which will count the number of words in the file names, which I think is more likely an attempt to count the number of files (although it doesn't take into account that filenames may contain whitespace). (Likewise, find ~ -type f | wc -l doesn't take into account that filenames may contain newlines.)

– steeldriver
Jan 4 at 13:34







I think the OP's use of wc -w may have led you to suppose they want to count the words inside the files - they're actually using xargs echo | wc -w which will count the number of words in the file names, which I think is more likely an attempt to count the number of files (although it doesn't take into account that filenames may contain whitespace). (Likewise, find ~ -type f | wc -l doesn't take into account that filenames may contain newlines.)

– steeldriver
Jan 4 at 13:34




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1106805%2fxargs-unmatched-single-quote-by-default-quotes-are-special-to-xargs-unless-you%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Questions related to Moebius Transform of Characteristic Function of the Primes

List of scandals in India

Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?