How to count the characters of jar files by wcCount occurrences of line in multiple filesCount the number of...
Why do no American passenger airlines still operate dedicated cargo flights?
How to solve a large system of linear algebra?
Pronunciation of umlaut vowels in the history of German
A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?
Can you tell from a blurry photo if focus was too close or too far?
Can we use the stored gravitational potential energy of a building to produce power?
Would a National Army of mercenaries be a feasible idea?
Why exactly do action photographers need high fps burst cameras?
Eww, those bytes are gross
Why publish a research paper when a blog post or a lecture slide can have more citation count than a journal paper?
What is 6÷2×(1+2) =?
How much mayhem could I cause as a sentient fish?
Why is working on the same position for more than 15 years not a red flag?
How to prevent cleaner from hanging my lock screen in Ubuntu 16.04
Avoiding morning and evening handshakes
Writing a character who is going through a civilizing process without overdoing it?
How to remove lines through the legend markers in ListPlot?
Who is this Ant Woman character in this image alongside the Wasp?
Why do members of Congress in committee hearings ask witnesses the same question multiple times?
Cookies - Should the toggles be on?
Why isn't there a non-conducting core wire for high-frequency coil applications
Finding a mistake using Mayer-Vietoris
Are there any modern advantages of a fire piston?
Digits in an algebraic irrational number
How to count the characters of jar files by wc
Count occurrences of line in multiple filesCount the number of characters in all filesCount number of characters per listed filenameHow can I count the number of whitespace characters in a file?How 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 files
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 5 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
1
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
11 hours ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
11 hours 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
11 hours 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
11 hours ago
1
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.
– Kamil Maciorowski
10 hours ago
|
show 5 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 hours ago
jimmij
32k874108
32k874108
asked 11 hours ago
yaelyael
2,66422571
2,66422571
1
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
11 hours ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
11 hours 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
11 hours 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
11 hours ago
1
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.
– Kamil Maciorowski
10 hours ago
|
show 5 more comments
1
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
11 hours ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
11 hours 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
11 hours 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
11 hours ago
1
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.
– Kamil Maciorowski
10 hours ago
1
1
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
11 hours 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
11 hours ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
11 hours ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
11 hours 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
11 hours 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
11 hours 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
11 hours 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
11 hours ago
1
1
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.– Kamil Maciorowski
10 hours ago
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.– Kamil Maciorowski
10 hours ago
|
show 5 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
10 hours ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
10 hours 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
10 hours 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(s) 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.
Note that I save the full path to each file in the output file. This does not matter since the directory path is static.
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 (this would generate diff output when even the last-access timestamp on a file changed). 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.
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
10 hours 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
10 hours ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
10 hours 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
10 hours 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
10 hours ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
10 hours 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
10 hours 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 10 hours ago
answered 10 hours 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
10 hours ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
10 hours 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
10 hours 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
10 hours ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
10 hours 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
10 hours 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
10 hours 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
10 hours ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
10 hours ago
what is the diff between wc -c to wc -m ? ( because on both I get the same results )
– yael
10 hours 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
10 hours 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
10 hours 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(s) 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.
Note that I save the full path to each file in the output file. This does not matter since the directory path is static.
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 (this would generate diff output when even the last-access timestamp on a file changed). 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.
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(s) 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.
Note that I save the full path to each file in the output file. This does not matter since the directory path is static.
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 (this would generate diff output when even the last-access timestamp on a file changed). 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.
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(s) 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.
Note that I save the full path to each file in the output file. This does not matter since the directory path is static.
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 (this would generate diff output when even the last-access timestamp on a file changed). 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(s) 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.
Note that I save the full path to each file in the output file. This does not matter since the directory path is static.
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 (this would generate diff output when even the last-access timestamp on a file changed). 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 9 hours ago
answered 10 hours ago
KusalanandaKusalananda
133k17253416
133k17253416
add a comment |
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
10 hours 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
10 hours 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 10 hours ago
Stéphane Chazelas
308k57581939
308k57581939
answered 10 hours ago
glenn jackmanglenn jackman
52k572112
52k572112
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
10 hours 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
10 hours 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
10 hours 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
10 hours 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 10 hours ago
Scottie HScottie H
366
366
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
1
You want to get total string length of all the filename? That sounds like a strange request. Smells like an XY problem.
– glenn jackman
11 hours ago
what I want it to count all characters from the output by wc or any other suggestion
– yael
11 hours 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
11 hours 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
11 hours ago
1
printf '%sn' *.jar | md5sum
wouldn't be blind to renaming to something with the same amount of letters.– Kamil Maciorowski
10 hours ago