How to count the characters of jar files by wcCount occurrences of line in multiple filesList files with line...
What are "industrial chops"?
How did Ancient Greek 'πυρ' become English 'fire?'
Simple text-based tic-tac-toe
What's a good word to describe a public place that looks like it wouldn't be rough?
How can animals be objects of ethics without being subjects as well?
Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?
Can a person refuse a presidential pardon?
Explain the objections to these measures against human trafficking
Cookies - Should the toggles be on?
Does SQL Server 2017, including older versions, support 8k disk sector sizes?
Citing paywalled articles accessed via illegal web sharing
what does しにみえてる mean?
Making him into a bully (how to show mild violence)
Publishing research using outdated methods
MAC Address learning process
Can we use the stored gravitational potential energy of a building to produce power?
Why did other German political parties disband so fast when Hitler was appointed chancellor?
Can I string the D&D Starter Set campaign into another module, keeping the same characters?
What is the purpose of easy combat scenarios that don't need resource expenditure?
Difference between i++ and (i)++ in C
Why do stocks necessarily drop during a recession?
Why are these T-SQL jobs from different SQL Server instances executed on the same instance (AlwaysOn Availability Groups)
How do you funnel food off a cutting board?
How to count the characters of jar files by wc
How to count the characters of jar files by wc
Count occurrences of line in multiple filesList files with line count and dateHow to append word count of file to file without adding the totalHow to count the number of words of each sentences in a file using shell command?How do I count the number of files in all subdirectories and add the counts togetherCount and compare files in LinuxCombined Word Count for Files in DirectoriesLinux Hadoop shell script giving .class errorsed count lines between pattern - multiple filesHow to use “wc -l ” on this line? Count rows within shell script and output the count value only
Under the folder /usr/hdp/2.6.4.0-91/tez_hive2/lib/
We have .jar files as the following
$ ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar"
async-http-client-1.8.16.jar
azure-data-lake-store-sdk-2.1.4.jar
commons-cli-1.2.jar
commons-codec-1.4.jar
commons-collections-3.2.2.jar
commons-collections4-4.1.jar
commons-io-2.4.jar
commons-lang-2.6.jar
commons-math3-3.1.1.jar
guava-11.0.2.jar
hadoop-aws-2.7.3.2.6.4.0-91.jar
hadoop-azure-2.7.3.2.6.4.0-91.jar
hadoop-azure-datalake-2.7.3.2.6.4.0-91.jar
hadoop-mapreduce-client-common-2.7.3.2.6.4.0-91.jar
hadoop-mapreduce-client-core-2.7.3.2.6.4.0-91.jar
hadoop-yarn-server-timeline-pluginstorage-2.7.3.2.6.4.0-91.jar
jersey-client-1.9.jar
jersey-json-1.9.jar
jettison-1.3.4.jar
jetty-6.1.26.hwx.jar
jetty-util-6.1.26.hwx.jar
jsr305-3.0.0.jar
metrics-core-3.1.0.jar
protobuf-java-2.5.0.jar
RoaringBitmap-0.4.9.jar
servlet-api-2.5.jar
slf4j-api-1.7.10.jar
I want to count all characters from the .jar files by wc , in order to understand if .jar files renamed
So I do the following command in order to count all characters from all .jar files
ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" | sed s'/// /g' | awk '{print $NF}' | wc | awk '{print $NF}'
758
So in this case we get 758 characters from all .jars
But the command isn’t elegant
How we can improve the command to be better?
bash shell-script awk sed wc
|
show 4 more comments
Under the folder /usr/hdp/2.6.4.0-91/tez_hive2/lib/
We have .jar files as the following
$ ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar"
async-http-client-1.8.16.jar
azure-data-lake-store-sdk-2.1.4.jar
commons-cli-1.2.jar
commons-codec-1.4.jar
commons-collections-3.2.2.jar
commons-collections4-4.1.jar
commons-io-2.4.jar
commons-lang-2.6.jar
commons-math3-3.1.1.jar
guava-11.0.2.jar
hadoop-aws-2.7.3.2.6.4.0-91.jar
hadoop-azure-2.7.3.2.6.4.0-91.jar
hadoop-azure-datalake-2.7.3.2.6.4.0-91.jar
hadoop-mapreduce-client-common-2.7.3.2.6.4.0-91.jar
hadoop-mapreduce-client-core-2.7.3.2.6.4.0-91.jar
hadoop-yarn-server-timeline-pluginstorage-2.7.3.2.6.4.0-91.jar
jersey-client-1.9.jar
jersey-json-1.9.jar
jettison-1.3.4.jar
jetty-6.1.26.hwx.jar
jetty-util-6.1.26.hwx.jar
jsr305-3.0.0.jar
metrics-core-3.1.0.jar
protobuf-java-2.5.0.jar
RoaringBitmap-0.4.9.jar
servlet-api-2.5.jar
slf4j-api-1.7.10.jar
I want to count all characters from the .jar files by wc , in order to understand if .jar files renamed
So I do the following command in order to count all characters from all .jar files
ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" | sed s'/// /g' | awk '{print $NF}' | wc | awk '{print $NF}'
758
So in this case we get 758 characters from all .jars
But the command isn’t elegant
How we can improve the command to be better?
bash shell-script awk sed wc
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
1 hour ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
51 mins ago
1) Wouldn't it make sense to get the length of "each" filename? 2) That wouldn't really tell you a whole lot as it can be renamed to something with the same amount of letters. 3) There really isn't a way to tell if any of the files have been renamed unless a script runs something likels -l | awk '{print $NF} > jarlog.txt
so that you can compare the filenames.
– Nasir Riley
46 mins ago
look only I want is to improve the cli - ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" | sed s'/// /g' | awk '{print $NF}' | wc | awk '{print $NF}'
– yael
43 mins ago
1
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.
– Kamil Maciorowski
35 mins ago
|
show 4 more comments
Under the folder /usr/hdp/2.6.4.0-91/tez_hive2/lib/
We have .jar files as the following
$ ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar"
async-http-client-1.8.16.jar
azure-data-lake-store-sdk-2.1.4.jar
commons-cli-1.2.jar
commons-codec-1.4.jar
commons-collections-3.2.2.jar
commons-collections4-4.1.jar
commons-io-2.4.jar
commons-lang-2.6.jar
commons-math3-3.1.1.jar
guava-11.0.2.jar
hadoop-aws-2.7.3.2.6.4.0-91.jar
hadoop-azure-2.7.3.2.6.4.0-91.jar
hadoop-azure-datalake-2.7.3.2.6.4.0-91.jar
hadoop-mapreduce-client-common-2.7.3.2.6.4.0-91.jar
hadoop-mapreduce-client-core-2.7.3.2.6.4.0-91.jar
hadoop-yarn-server-timeline-pluginstorage-2.7.3.2.6.4.0-91.jar
jersey-client-1.9.jar
jersey-json-1.9.jar
jettison-1.3.4.jar
jetty-6.1.26.hwx.jar
jetty-util-6.1.26.hwx.jar
jsr305-3.0.0.jar
metrics-core-3.1.0.jar
protobuf-java-2.5.0.jar
RoaringBitmap-0.4.9.jar
servlet-api-2.5.jar
slf4j-api-1.7.10.jar
I want to count all characters from the .jar files by wc , in order to understand if .jar files renamed
So I do the following command in order to count all characters from all .jar files
ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" | sed s'/// /g' | awk '{print $NF}' | wc | awk '{print $NF}'
758
So in this case we get 758 characters from all .jars
But the command isn’t elegant
How we can improve the command to be better?
bash shell-script awk sed wc
Under the folder /usr/hdp/2.6.4.0-91/tez_hive2/lib/
We have .jar files as the following
$ ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar"
async-http-client-1.8.16.jar
azure-data-lake-store-sdk-2.1.4.jar
commons-cli-1.2.jar
commons-codec-1.4.jar
commons-collections-3.2.2.jar
commons-collections4-4.1.jar
commons-io-2.4.jar
commons-lang-2.6.jar
commons-math3-3.1.1.jar
guava-11.0.2.jar
hadoop-aws-2.7.3.2.6.4.0-91.jar
hadoop-azure-2.7.3.2.6.4.0-91.jar
hadoop-azure-datalake-2.7.3.2.6.4.0-91.jar
hadoop-mapreduce-client-common-2.7.3.2.6.4.0-91.jar
hadoop-mapreduce-client-core-2.7.3.2.6.4.0-91.jar
hadoop-yarn-server-timeline-pluginstorage-2.7.3.2.6.4.0-91.jar
jersey-client-1.9.jar
jersey-json-1.9.jar
jettison-1.3.4.jar
jetty-6.1.26.hwx.jar
jetty-util-6.1.26.hwx.jar
jsr305-3.0.0.jar
metrics-core-3.1.0.jar
protobuf-java-2.5.0.jar
RoaringBitmap-0.4.9.jar
servlet-api-2.5.jar
slf4j-api-1.7.10.jar
I want to count all characters from the .jar files by wc , in order to understand if .jar files renamed
So I do the following command in order to count all characters from all .jar files
ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" | sed s'/// /g' | awk '{print $NF}' | wc | awk '{print $NF}'
758
So in this case we get 758 characters from all .jars
But the command isn’t elegant
How we can improve the command to be better?
bash shell-script awk sed wc
bash shell-script awk sed wc
edited 10 mins ago
jimmij
32k874108
32k874108
asked 1 hour ago
yaelyael
2,64422571
2,64422571
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
1 hour ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
51 mins ago
1) Wouldn't it make sense to get the length of "each" filename? 2) That wouldn't really tell you a whole lot as it can be renamed to something with the same amount of letters. 3) There really isn't a way to tell if any of the files have been renamed unless a script runs something likels -l | awk '{print $NF} > jarlog.txt
so that you can compare the filenames.
– Nasir Riley
46 mins ago
look only I want is to improve the cli - ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" | sed s'/// /g' | awk '{print $NF}' | wc | awk '{print $NF}'
– yael
43 mins ago
1
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.
– Kamil Maciorowski
35 mins ago
|
show 4 more comments
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
1 hour ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
51 mins ago
1) Wouldn't it make sense to get the length of "each" filename? 2) That wouldn't really tell you a whole lot as it can be renamed to something with the same amount of letters. 3) There really isn't a way to tell if any of the files have been renamed unless a script runs something likels -l | awk '{print $NF} > jarlog.txt
so that you can compare the filenames.
– Nasir Riley
46 mins ago
look only I want is to improve the cli - ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" | sed s'/// /g' | awk '{print $NF}' | wc | awk '{print $NF}'
– yael
43 mins ago
1
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.
– Kamil Maciorowski
35 mins ago
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
1 hour ago
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
1 hour ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
51 mins ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
51 mins ago
1) Wouldn't it make sense to get the length of "each" filename? 2) That wouldn't really tell you a whole lot as it can be renamed to something with the same amount of letters. 3) There really isn't a way to tell if any of the files have been renamed unless a script runs something like
ls -l | awk '{print $NF} > jarlog.txt
so that you can compare the filenames.– Nasir Riley
46 mins ago
1) Wouldn't it make sense to get the length of "each" filename? 2) That wouldn't really tell you a whole lot as it can be renamed to something with the same amount of letters. 3) There really isn't a way to tell if any of the files have been renamed unless a script runs something like
ls -l | awk '{print $NF} > jarlog.txt
so that you can compare the filenames.– Nasir Riley
46 mins ago
look only I want is to improve the cli - ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" | sed s'/// /g' | awk '{print $NF}' | wc | awk '{print $NF}'
– yael
43 mins ago
look only I want is to improve the cli - ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" | sed s'/// /g' | awk '{print $NF}' | wc | awk '{print $NF}'
– yael
43 mins ago
1
1
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.– Kamil Maciorowski
35 mins ago
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.– Kamil Maciorowski
35 mins ago
|
show 4 more comments
4 Answers
4
active
oldest
votes
Most probably you are looking for
basename -a /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar | wc -c
The path with wildcard list all jar files, the basename
command strips directories (-a
is needed to accept many arguments), and wc -c
just counts bytes (if some filenames consist of 2 byte characters then perhaps wc -m
(characters count) would be a better choice).
However, to if the goal is to check if files have been modified then perhaps stat
(for modification time) or md5sum
/shasum
for checksum would be a better tools.
wc -c
counts the number of bytes, not characters.wc -m
counts the number of characters. Also note that you're also counting one extra newline character per file.
– Stéphane Chazelas
20 mins ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
16 mins ago
1
@yael,wc -m
counts the number of characters,wc -c
the number of bytes. That makes a difference in the case of characters made of more than one byte (in UTF-8, that's all the non-ASCII ones (over a million of them)). Compareprintf € | wc -c
withprintf € | wc -m
.
– Stéphane Chazelas
14 mins ago
add a comment |
To just get the number of characters in the (non-hidden) jar
filenames, I would do
cd /usr/hdp/2.6.4.0-91/tez_hive2/lib/ && printf %s *.jar | wc -m
This will not count any newlines, just the filename characters (replace wc -m
with wc -c
for the number of bytes instead of characters).
Purposefully, I'm not parsing ls
output.
Note that in shells likebash
, if there's no.jar
file in the current directory, that will output5
(the number of characters in*.jar
). Inbash
, you can doshopt -s nullglob
to get 0 in that case.
– Stéphane Chazelas
16 mins ago
add a comment |
Counting the number of letters in the filenames would not be a safe way of detecting a renamed filename.
Instead, create a simple file listing of the names, and compare it to an existing list. By using diff
, you would be shown exactly which line in the list had changed.
#!/bin/sh
LC_ALL=C
newlist=$HOME/filelist.new
oldlist=$HOME/filelist.old
echo /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar >"$newlist"
if [ -f "$oldlist" ]; then
diff -u "$oldlist" "$newlist"
fi
mv "$newlist" "$oldlist"
Obviously, the first time you do this, filelist.old
would not exist, so the diff
would not run.
Change echo
to ls -l
if you want to also compare timestamps etc. Change it to stat
if you want to compare even more meta data. Install wdiff
and change diff
to wdiff
to get a word-based diff rather than a line-based one.
The LC_ALL=C
is to guarantee a consistent sorting of the expansion of the shell glob.
@StéphaneChazelas Sorted, thanks.
– Kusalananda
8 mins ago
add a comment |
I don't understand the point of the sed
command, you are replacing a slash with a space? Why?
Aside from that, it seems that you want to count the total number of characters in all the file names of the .jar files. IF so, try this:ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar | sed s'/// /g' | wc -c
Two other possibilities for your sed command: sed "s|/| |g"
-- or -- tr '/' ' '
Since your ls command won't show directory names, I am not sure you need it.
This will also count the LF at the end of each file name. Is that OK?
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f503621%2fhow-to-count-the-characters-of-jar-files-by-wc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Most probably you are looking for
basename -a /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar | wc -c
The path with wildcard list all jar files, the basename
command strips directories (-a
is needed to accept many arguments), and wc -c
just counts bytes (if some filenames consist of 2 byte characters then perhaps wc -m
(characters count) would be a better choice).
However, to if the goal is to check if files have been modified then perhaps stat
(for modification time) or md5sum
/shasum
for checksum would be a better tools.
wc -c
counts the number of bytes, not characters.wc -m
counts the number of characters. Also note that you're also counting one extra newline character per file.
– Stéphane Chazelas
20 mins ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
16 mins ago
1
@yael,wc -m
counts the number of characters,wc -c
the number of bytes. That makes a difference in the case of characters made of more than one byte (in UTF-8, that's all the non-ASCII ones (over a million of them)). Compareprintf € | wc -c
withprintf € | wc -m
.
– Stéphane Chazelas
14 mins ago
add a comment |
Most probably you are looking for
basename -a /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar | wc -c
The path with wildcard list all jar files, the basename
command strips directories (-a
is needed to accept many arguments), and wc -c
just counts bytes (if some filenames consist of 2 byte characters then perhaps wc -m
(characters count) would be a better choice).
However, to if the goal is to check if files have been modified then perhaps stat
(for modification time) or md5sum
/shasum
for checksum would be a better tools.
wc -c
counts the number of bytes, not characters.wc -m
counts the number of characters. Also note that you're also counting one extra newline character per file.
– Stéphane Chazelas
20 mins ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
16 mins ago
1
@yael,wc -m
counts the number of characters,wc -c
the number of bytes. That makes a difference in the case of characters made of more than one byte (in UTF-8, that's all the non-ASCII ones (over a million of them)). Compareprintf € | wc -c
withprintf € | wc -m
.
– Stéphane Chazelas
14 mins ago
add a comment |
Most probably you are looking for
basename -a /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar | wc -c
The path with wildcard list all jar files, the basename
command strips directories (-a
is needed to accept many arguments), and wc -c
just counts bytes (if some filenames consist of 2 byte characters then perhaps wc -m
(characters count) would be a better choice).
However, to if the goal is to check if files have been modified then perhaps stat
(for modification time) or md5sum
/shasum
for checksum would be a better tools.
Most probably you are looking for
basename -a /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar | wc -c
The path with wildcard list all jar files, the basename
command strips directories (-a
is needed to accept many arguments), and wc -c
just counts bytes (if some filenames consist of 2 byte characters then perhaps wc -m
(characters count) would be a better choice).
However, to if the goal is to check if files have been modified then perhaps stat
(for modification time) or md5sum
/shasum
for checksum would be a better tools.
edited 13 mins ago
answered 28 mins ago
jimmijjimmij
32k874108
32k874108
wc -c
counts the number of bytes, not characters.wc -m
counts the number of characters. Also note that you're also counting one extra newline character per file.
– Stéphane Chazelas
20 mins ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
16 mins ago
1
@yael,wc -m
counts the number of characters,wc -c
the number of bytes. That makes a difference in the case of characters made of more than one byte (in UTF-8, that's all the non-ASCII ones (over a million of them)). Compareprintf € | wc -c
withprintf € | wc -m
.
– Stéphane Chazelas
14 mins ago
add a comment |
wc -c
counts the number of bytes, not characters.wc -m
counts the number of characters. Also note that you're also counting one extra newline character per file.
– Stéphane Chazelas
20 mins ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
16 mins ago
1
@yael,wc -m
counts the number of characters,wc -c
the number of bytes. That makes a difference in the case of characters made of more than one byte (in UTF-8, that's all the non-ASCII ones (over a million of them)). Compareprintf € | wc -c
withprintf € | wc -m
.
– Stéphane Chazelas
14 mins ago
wc -c
counts the number of bytes, not characters. wc -m
counts the number of characters. Also note that you're also counting one extra newline character per file.– Stéphane Chazelas
20 mins ago
wc -c
counts the number of bytes, not characters. wc -m
counts the number of characters. Also note that you're also counting one extra newline character per file.– Stéphane Chazelas
20 mins ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
16 mins ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
16 mins ago
1
1
@yael,
wc -m
counts the number of characters, wc -c
the number of bytes. That makes a difference in the case of characters made of more than one byte (in UTF-8, that's all the non-ASCII ones (over a million of them)). Compare printf € | wc -c
with printf € | wc -m
.– Stéphane Chazelas
14 mins ago
@yael,
wc -m
counts the number of characters, wc -c
the number of bytes. That makes a difference in the case of characters made of more than one byte (in UTF-8, that's all the non-ASCII ones (over a million of them)). Compare printf € | wc -c
with printf € | wc -m
.– Stéphane Chazelas
14 mins ago
add a comment |
To just get the number of characters in the (non-hidden) jar
filenames, I would do
cd /usr/hdp/2.6.4.0-91/tez_hive2/lib/ && printf %s *.jar | wc -m
This will not count any newlines, just the filename characters (replace wc -m
with wc -c
for the number of bytes instead of characters).
Purposefully, I'm not parsing ls
output.
Note that in shells likebash
, if there's no.jar
file in the current directory, that will output5
(the number of characters in*.jar
). Inbash
, you can doshopt -s nullglob
to get 0 in that case.
– Stéphane Chazelas
16 mins ago
add a comment |
To just get the number of characters in the (non-hidden) jar
filenames, I would do
cd /usr/hdp/2.6.4.0-91/tez_hive2/lib/ && printf %s *.jar | wc -m
This will not count any newlines, just the filename characters (replace wc -m
with wc -c
for the number of bytes instead of characters).
Purposefully, I'm not parsing ls
output.
Note that in shells likebash
, if there's no.jar
file in the current directory, that will output5
(the number of characters in*.jar
). Inbash
, you can doshopt -s nullglob
to get 0 in that case.
– Stéphane Chazelas
16 mins ago
add a comment |
To just get the number of characters in the (non-hidden) jar
filenames, I would do
cd /usr/hdp/2.6.4.0-91/tez_hive2/lib/ && printf %s *.jar | wc -m
This will not count any newlines, just the filename characters (replace wc -m
with wc -c
for the number of bytes instead of characters).
Purposefully, I'm not parsing ls
output.
To just get the number of characters in the (non-hidden) jar
filenames, I would do
cd /usr/hdp/2.6.4.0-91/tez_hive2/lib/ && printf %s *.jar | wc -m
This will not count any newlines, just the filename characters (replace wc -m
with wc -c
for the number of bytes instead of characters).
Purposefully, I'm not parsing ls
output.
edited 19 mins ago
Stéphane Chazelas
307k57581939
307k57581939
answered 21 mins ago
glenn jackmanglenn jackman
51.9k572112
51.9k572112
Note that in shells likebash
, if there's no.jar
file in the current directory, that will output5
(the number of characters in*.jar
). Inbash
, you can doshopt -s nullglob
to get 0 in that case.
– Stéphane Chazelas
16 mins ago
add a comment |
Note that in shells likebash
, if there's no.jar
file in the current directory, that will output5
(the number of characters in*.jar
). Inbash
, you can doshopt -s nullglob
to get 0 in that case.
– Stéphane Chazelas
16 mins ago
Note that in shells like
bash
, if there's no .jar
file in the current directory, that will output 5
(the number of characters in *.jar
). In bash
, you can do shopt -s nullglob
to get 0 in that case.– Stéphane Chazelas
16 mins ago
Note that in shells like
bash
, if there's no .jar
file in the current directory, that will output 5
(the number of characters in *.jar
). In bash
, you can do shopt -s nullglob
to get 0 in that case.– Stéphane Chazelas
16 mins ago
add a comment |
Counting the number of letters in the filenames would not be a safe way of detecting a renamed filename.
Instead, create a simple file listing of the names, and compare it to an existing list. By using diff
, you would be shown exactly which line in the list had changed.
#!/bin/sh
LC_ALL=C
newlist=$HOME/filelist.new
oldlist=$HOME/filelist.old
echo /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar >"$newlist"
if [ -f "$oldlist" ]; then
diff -u "$oldlist" "$newlist"
fi
mv "$newlist" "$oldlist"
Obviously, the first time you do this, filelist.old
would not exist, so the diff
would not run.
Change echo
to ls -l
if you want to also compare timestamps etc. Change it to stat
if you want to compare even more meta data. Install wdiff
and change diff
to wdiff
to get a word-based diff rather than a line-based one.
The LC_ALL=C
is to guarantee a consistent sorting of the expansion of the shell glob.
@StéphaneChazelas Sorted, thanks.
– Kusalananda
8 mins ago
add a comment |
Counting the number of letters in the filenames would not be a safe way of detecting a renamed filename.
Instead, create a simple file listing of the names, and compare it to an existing list. By using diff
, you would be shown exactly which line in the list had changed.
#!/bin/sh
LC_ALL=C
newlist=$HOME/filelist.new
oldlist=$HOME/filelist.old
echo /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar >"$newlist"
if [ -f "$oldlist" ]; then
diff -u "$oldlist" "$newlist"
fi
mv "$newlist" "$oldlist"
Obviously, the first time you do this, filelist.old
would not exist, so the diff
would not run.
Change echo
to ls -l
if you want to also compare timestamps etc. Change it to stat
if you want to compare even more meta data. Install wdiff
and change diff
to wdiff
to get a word-based diff rather than a line-based one.
The LC_ALL=C
is to guarantee a consistent sorting of the expansion of the shell glob.
@StéphaneChazelas Sorted, thanks.
– Kusalananda
8 mins ago
add a comment |
Counting the number of letters in the filenames would not be a safe way of detecting a renamed filename.
Instead, create a simple file listing of the names, and compare it to an existing list. By using diff
, you would be shown exactly which line in the list had changed.
#!/bin/sh
LC_ALL=C
newlist=$HOME/filelist.new
oldlist=$HOME/filelist.old
echo /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar >"$newlist"
if [ -f "$oldlist" ]; then
diff -u "$oldlist" "$newlist"
fi
mv "$newlist" "$oldlist"
Obviously, the first time you do this, filelist.old
would not exist, so the diff
would not run.
Change echo
to ls -l
if you want to also compare timestamps etc. Change it to stat
if you want to compare even more meta data. Install wdiff
and change diff
to wdiff
to get a word-based diff rather than a line-based one.
The LC_ALL=C
is to guarantee a consistent sorting of the expansion of the shell glob.
Counting the number of letters in the filenames would not be a safe way of detecting a renamed filename.
Instead, create a simple file listing of the names, and compare it to an existing list. By using diff
, you would be shown exactly which line in the list had changed.
#!/bin/sh
LC_ALL=C
newlist=$HOME/filelist.new
oldlist=$HOME/filelist.old
echo /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar >"$newlist"
if [ -f "$oldlist" ]; then
diff -u "$oldlist" "$newlist"
fi
mv "$newlist" "$oldlist"
Obviously, the first time you do this, filelist.old
would not exist, so the diff
would not run.
Change echo
to ls -l
if you want to also compare timestamps etc. Change it to stat
if you want to compare even more meta data. Install wdiff
and change diff
to wdiff
to get a word-based diff rather than a line-based one.
The LC_ALL=C
is to guarantee a consistent sorting of the expansion of the shell glob.
edited 3 mins ago
answered 12 mins ago
KusalanandaKusalananda
133k17253416
133k17253416
@StéphaneChazelas Sorted, thanks.
– Kusalananda
8 mins ago
add a comment |
@StéphaneChazelas Sorted, thanks.
– Kusalananda
8 mins ago
@StéphaneChazelas Sorted, thanks.
– Kusalananda
8 mins ago
@StéphaneChazelas Sorted, thanks.
– Kusalananda
8 mins ago
add a comment |
I don't understand the point of the sed
command, you are replacing a slash with a space? Why?
Aside from that, it seems that you want to count the total number of characters in all the file names of the .jar files. IF so, try this:ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar | sed s'/// /g' | wc -c
Two other possibilities for your sed command: sed "s|/| |g"
-- or -- tr '/' ' '
Since your ls command won't show directory names, I am not sure you need it.
This will also count the LF at the end of each file name. Is that OK?
add a comment |
I don't understand the point of the sed
command, you are replacing a slash with a space? Why?
Aside from that, it seems that you want to count the total number of characters in all the file names of the .jar files. IF so, try this:ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar | sed s'/// /g' | wc -c
Two other possibilities for your sed command: sed "s|/| |g"
-- or -- tr '/' ' '
Since your ls command won't show directory names, I am not sure you need it.
This will also count the LF at the end of each file name. Is that OK?
add a comment |
I don't understand the point of the sed
command, you are replacing a slash with a space? Why?
Aside from that, it seems that you want to count the total number of characters in all the file names of the .jar files. IF so, try this:ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar | sed s'/// /g' | wc -c
Two other possibilities for your sed command: sed "s|/| |g"
-- or -- tr '/' ' '
Since your ls command won't show directory names, I am not sure you need it.
This will also count the LF at the end of each file name. Is that OK?
I don't understand the point of the sed
command, you are replacing a slash with a space? Why?
Aside from that, it seems that you want to count the total number of characters in all the file names of the .jar files. IF so, try this:ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/*.jar | sed s'/// /g' | wc -c
Two other possibilities for your sed command: sed "s|/| |g"
-- or -- tr '/' ' '
Since your ls command won't show directory names, I am not sure you need it.
This will also count the LF at the end of each file name. Is that OK?
answered 29 mins ago
Scottie HScottie H
245
245
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f503621%2fhow-to-count-the-characters-of-jar-files-by-wc%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
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
1 hour ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
51 mins ago
1) Wouldn't it make sense to get the length of "each" filename? 2) That wouldn't really tell you a whole lot as it can be renamed to something with the same amount of letters. 3) There really isn't a way to tell if any of the files have been renamed unless a script runs something like
ls -l | awk '{print $NF} > jarlog.txt
so that you can compare the filenames.– Nasir Riley
46 mins ago
look only I want is to improve the cli - ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" | sed s'/// /g' | awk '{print $NF}' | wc | awk '{print $NF}'
– yael
43 mins ago
1
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.– Kamil Maciorowski
35 mins ago