Bash find files and filter by date and sizeGet the source directory of a Bash script from within the script itselfHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How do I split a string on a delimiter in Bash?Extract filename and extension in BashHow to check if a variable is set in Bash?How to concatenate string variables in BashHow do I set a variable to the output of a command in Bash?How do I find all files containing specific text on Linux?
Understanding a part of the proof that sequence that converges to square root of two is decreasing.
What's a good pattern to calculate a variable only when it is used the first time?
What does 〇〇〇〇 mean when combined with おじさん?
Did Michelle Obama have a staff of 23; and Melania have a staff of 4?
Does Reckless Attack work with Multiattack when wild shaped?
What's the relationship betweeen MS-DOS and XENIX?
What is the question mark?
Why don't modern jet engines use forced exhaust mixing?
Is there any official ruling on how characters go from 0th to 1st level in a class?
Do I need to start off my book by describing the character's "normal world"?
Build a mob of suspiciously happy lenny faces ( ͡° ͜ʖ ͡°)
Scam? Phone call from "Department of Social Security" asking me to call back
Doesn't the speed of light limit imply the same electron can be annihilated twice?
Are there liquid fueled rocket boosters having coaxial fuel/oxidizer tanks?
Sum Square Difference, which way is more Pythonic?
Airline power sockets shut down when I plug my computer in. How can I avoid that?
How to get locks that are keyed alike?
A Magic Diamond
Meaning of だけはわからない
When did Bilbo and Frodo learn that Gandalf was a Maia?
How to prevent criminal gangs from making/buying guns?
Is the Microsoft recommendation to use C# properties applicable to game development?
Why does auto deduce this variable as double and not float?
Why are electric shavers specifically permitted under FAR §91.21
Bash find files and filter by date and size
Get the source directory of a Bash script from within the script itselfHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How do I split a string on a delimiter in Bash?Extract filename and extension in BashHow to check if a variable is set in Bash?How to concatenate string variables in BashHow do I set a variable to the output of a command in Bash?How do I find all files containing specific text on Linux?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a directory with a lot of files in it.
Each day, new files are added automatically.
The filenames are formatted like that :
[GROUP_ID]_[RANDOM_NUMBER].txt
Example : 012_1234.txt
For every day, for every GROUP_ID (032, 024, 044...etc), I want to keep only the biggest file of the day.
So for example, for the two days 27 and 28 march I have :
March 27 - 012_1234.txt - 12ko
March 27 - 012_0243.txt - 3000ko
March 27 - 016_5647.txt - 25ko
March 27 - 024_4354.txt - 20ko
March 27 - 032_8745.txt - 40ko
March 28 - 032_1254.txt - 16ko
March 28 - 036_0456.txt - 30ko
March 28 - 042_7645.txt - 500ko
March 28 - 042_2310.txt - 25ko
March 28 - 042_2125.txt - 34ko
March 28 - 044_4510.txt - 35ko
And I want to have :
March 27 - 012_0243.txt - 3000ko
March 27 - 016_5647.txt - 25ko
March 27 - 024_4354.txt - 20ko
March 27 - 032_8745.txt - 40ko
March 28 - 032_1254.txt - 16ko
March 28 - 036_0456.txt - 30ko
March 28 - 042_7645.txt - 500ko
March 28 - 044_4510.txt - 35ko
I don't find the right bash ls/find command to do that, somebody have an idea ?
With this command, I can display the biggest file for each day.
ls -l *.txt --time-style=+%s |
awk '$6 = int($6/86400); print' |
sort -nk6,6 -nrk5,5 | sort -sunk6,6
But I want the biggest file of each GROUP_ID file of each day.
So, if there is one file for "012" group_id file, of 10ko, I want to display it, even if there is bigger files for others group id...
bash shell find ls
|
show 5 more comments
I have a directory with a lot of files in it.
Each day, new files are added automatically.
The filenames are formatted like that :
[GROUP_ID]_[RANDOM_NUMBER].txt
Example : 012_1234.txt
For every day, for every GROUP_ID (032, 024, 044...etc), I want to keep only the biggest file of the day.
So for example, for the two days 27 and 28 march I have :
March 27 - 012_1234.txt - 12ko
March 27 - 012_0243.txt - 3000ko
March 27 - 016_5647.txt - 25ko
March 27 - 024_4354.txt - 20ko
March 27 - 032_8745.txt - 40ko
March 28 - 032_1254.txt - 16ko
March 28 - 036_0456.txt - 30ko
March 28 - 042_7645.txt - 500ko
March 28 - 042_2310.txt - 25ko
March 28 - 042_2125.txt - 34ko
March 28 - 044_4510.txt - 35ko
And I want to have :
March 27 - 012_0243.txt - 3000ko
March 27 - 016_5647.txt - 25ko
March 27 - 024_4354.txt - 20ko
March 27 - 032_8745.txt - 40ko
March 28 - 032_1254.txt - 16ko
March 28 - 036_0456.txt - 30ko
March 28 - 042_7645.txt - 500ko
March 28 - 044_4510.txt - 35ko
I don't find the right bash ls/find command to do that, somebody have an idea ?
With this command, I can display the biggest file for each day.
ls -l *.txt --time-style=+%s |
awk '$6 = int($6/86400); print' |
sort -nk6,6 -nrk5,5 | sort -sunk6,6
But I want the biggest file of each GROUP_ID file of each day.
So, if there is one file for "012" group_id file, of 10ko, I want to display it, even if there is bigger files for others group id...
bash shell find ls
1
Stack Overflow is not a code writing service. What have you searched for before asking, and what did you find? Based on that, what did you try, and how did it fail?
– tripleee
Mar 27 at 12:37
I edit my post. I just want some ideas, I don't ask for a clean and complete answer necessarly. Thanks
– user2178964
Mar 27 at 13:49
And "ko" is your language's abbreviation for kB I guess?
– tripleee
Mar 27 at 13:53
And*Zis actually a placeholder for*.txtor your files are actually named according to that wildcard?
– tripleee
Mar 27 at 13:56
yes, ko=kb , and I edit my post to replace *.Z by *.txt
– user2178964
Mar 27 at 14:02
|
show 5 more comments
I have a directory with a lot of files in it.
Each day, new files are added automatically.
The filenames are formatted like that :
[GROUP_ID]_[RANDOM_NUMBER].txt
Example : 012_1234.txt
For every day, for every GROUP_ID (032, 024, 044...etc), I want to keep only the biggest file of the day.
So for example, for the two days 27 and 28 march I have :
March 27 - 012_1234.txt - 12ko
March 27 - 012_0243.txt - 3000ko
March 27 - 016_5647.txt - 25ko
March 27 - 024_4354.txt - 20ko
March 27 - 032_8745.txt - 40ko
March 28 - 032_1254.txt - 16ko
March 28 - 036_0456.txt - 30ko
March 28 - 042_7645.txt - 500ko
March 28 - 042_2310.txt - 25ko
March 28 - 042_2125.txt - 34ko
March 28 - 044_4510.txt - 35ko
And I want to have :
March 27 - 012_0243.txt - 3000ko
March 27 - 016_5647.txt - 25ko
March 27 - 024_4354.txt - 20ko
March 27 - 032_8745.txt - 40ko
March 28 - 032_1254.txt - 16ko
March 28 - 036_0456.txt - 30ko
March 28 - 042_7645.txt - 500ko
March 28 - 044_4510.txt - 35ko
I don't find the right bash ls/find command to do that, somebody have an idea ?
With this command, I can display the biggest file for each day.
ls -l *.txt --time-style=+%s |
awk '$6 = int($6/86400); print' |
sort -nk6,6 -nrk5,5 | sort -sunk6,6
But I want the biggest file of each GROUP_ID file of each day.
So, if there is one file for "012" group_id file, of 10ko, I want to display it, even if there is bigger files for others group id...
bash shell find ls
I have a directory with a lot of files in it.
Each day, new files are added automatically.
The filenames are formatted like that :
[GROUP_ID]_[RANDOM_NUMBER].txt
Example : 012_1234.txt
For every day, for every GROUP_ID (032, 024, 044...etc), I want to keep only the biggest file of the day.
So for example, for the two days 27 and 28 march I have :
March 27 - 012_1234.txt - 12ko
March 27 - 012_0243.txt - 3000ko
March 27 - 016_5647.txt - 25ko
March 27 - 024_4354.txt - 20ko
March 27 - 032_8745.txt - 40ko
March 28 - 032_1254.txt - 16ko
March 28 - 036_0456.txt - 30ko
March 28 - 042_7645.txt - 500ko
March 28 - 042_2310.txt - 25ko
March 28 - 042_2125.txt - 34ko
March 28 - 044_4510.txt - 35ko
And I want to have :
March 27 - 012_0243.txt - 3000ko
March 27 - 016_5647.txt - 25ko
March 27 - 024_4354.txt - 20ko
March 27 - 032_8745.txt - 40ko
March 28 - 032_1254.txt - 16ko
March 28 - 036_0456.txt - 30ko
March 28 - 042_7645.txt - 500ko
March 28 - 044_4510.txt - 35ko
I don't find the right bash ls/find command to do that, somebody have an idea ?
With this command, I can display the biggest file for each day.
ls -l *.txt --time-style=+%s |
awk '$6 = int($6/86400); print' |
sort -nk6,6 -nrk5,5 | sort -sunk6,6
But I want the biggest file of each GROUP_ID file of each day.
So, if there is one file for "012" group_id file, of 10ko, I want to display it, even if there is bigger files for others group id...
bash shell find ls
bash shell find ls
edited Mar 27 at 14:01
user2178964
asked Mar 27 at 12:34
user2178964user2178964
415 gold badges14 silver badges27 bronze badges
415 gold badges14 silver badges27 bronze badges
1
Stack Overflow is not a code writing service. What have you searched for before asking, and what did you find? Based on that, what did you try, and how did it fail?
– tripleee
Mar 27 at 12:37
I edit my post. I just want some ideas, I don't ask for a clean and complete answer necessarly. Thanks
– user2178964
Mar 27 at 13:49
And "ko" is your language's abbreviation for kB I guess?
– tripleee
Mar 27 at 13:53
And*Zis actually a placeholder for*.txtor your files are actually named according to that wildcard?
– tripleee
Mar 27 at 13:56
yes, ko=kb , and I edit my post to replace *.Z by *.txt
– user2178964
Mar 27 at 14:02
|
show 5 more comments
1
Stack Overflow is not a code writing service. What have you searched for before asking, and what did you find? Based on that, what did you try, and how did it fail?
– tripleee
Mar 27 at 12:37
I edit my post. I just want some ideas, I don't ask for a clean and complete answer necessarly. Thanks
– user2178964
Mar 27 at 13:49
And "ko" is your language's abbreviation for kB I guess?
– tripleee
Mar 27 at 13:53
And*Zis actually a placeholder for*.txtor your files are actually named according to that wildcard?
– tripleee
Mar 27 at 13:56
yes, ko=kb , and I edit my post to replace *.Z by *.txt
– user2178964
Mar 27 at 14:02
1
1
Stack Overflow is not a code writing service. What have you searched for before asking, and what did you find? Based on that, what did you try, and how did it fail?
– tripleee
Mar 27 at 12:37
Stack Overflow is not a code writing service. What have you searched for before asking, and what did you find? Based on that, what did you try, and how did it fail?
– tripleee
Mar 27 at 12:37
I edit my post. I just want some ideas, I don't ask for a clean and complete answer necessarly. Thanks
– user2178964
Mar 27 at 13:49
I edit my post. I just want some ideas, I don't ask for a clean and complete answer necessarly. Thanks
– user2178964
Mar 27 at 13:49
And "ko" is your language's abbreviation for kB I guess?
– tripleee
Mar 27 at 13:53
And "ko" is your language's abbreviation for kB I guess?
– tripleee
Mar 27 at 13:53
And
*Z is actually a placeholder for *.txt or your files are actually named according to that wildcard?– tripleee
Mar 27 at 13:56
And
*Z is actually a placeholder for *.txt or your files are actually named according to that wildcard?– tripleee
Mar 27 at 13:56
yes, ko=kb , and I edit my post to replace *.Z by *.txt
– user2178964
Mar 27 at 14:02
yes, ko=kb , and I edit my post to replace *.Z by *.txt
– user2178964
Mar 27 at 14:02
|
show 5 more comments
1 Answer
1
active
oldest
votes
I found myself the solution:
ls -l | tail -n+2 |
awk ' split($0,var,"_"); group_id=var[5]; print $0" "group_id ' |
sort -k9,9 -k5,5nr |
awk '$10 != x print x = $10 '
This gives me the biggest file for each group_id, so now I just add to handle the day part.
For information:
tail -n+2: hide the "total" part of the ls command's output
First awk: get the group_id part (012, 036...) and display it after the original line ($0)
Sort: sort on filename and size
Take the biggest size of each group_id (column 10 added by awk at beginning)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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%2fstackoverflow.com%2fquestions%2f55377340%2fbash-find-files-and-filter-by-date-and-size%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
I found myself the solution:
ls -l | tail -n+2 |
awk ' split($0,var,"_"); group_id=var[5]; print $0" "group_id ' |
sort -k9,9 -k5,5nr |
awk '$10 != x print x = $10 '
This gives me the biggest file for each group_id, so now I just add to handle the day part.
For information:
tail -n+2: hide the "total" part of the ls command's output
First awk: get the group_id part (012, 036...) and display it after the original line ($0)
Sort: sort on filename and size
Take the biggest size of each group_id (column 10 added by awk at beginning)
add a comment |
I found myself the solution:
ls -l | tail -n+2 |
awk ' split($0,var,"_"); group_id=var[5]; print $0" "group_id ' |
sort -k9,9 -k5,5nr |
awk '$10 != x print x = $10 '
This gives me the biggest file for each group_id, so now I just add to handle the day part.
For information:
tail -n+2: hide the "total" part of the ls command's output
First awk: get the group_id part (012, 036...) and display it after the original line ($0)
Sort: sort on filename and size
Take the biggest size of each group_id (column 10 added by awk at beginning)
add a comment |
I found myself the solution:
ls -l | tail -n+2 |
awk ' split($0,var,"_"); group_id=var[5]; print $0" "group_id ' |
sort -k9,9 -k5,5nr |
awk '$10 != x print x = $10 '
This gives me the biggest file for each group_id, so now I just add to handle the day part.
For information:
tail -n+2: hide the "total" part of the ls command's output
First awk: get the group_id part (012, 036...) and display it after the original line ($0)
Sort: sort on filename and size
Take the biggest size of each group_id (column 10 added by awk at beginning)
I found myself the solution:
ls -l | tail -n+2 |
awk ' split($0,var,"_"); group_id=var[5]; print $0" "group_id ' |
sort -k9,9 -k5,5nr |
awk '$10 != x print x = $10 '
This gives me the biggest file for each group_id, so now I just add to handle the day part.
For information:
tail -n+2: hide the "total" part of the ls command's output
First awk: get the group_id part (012, 036...) and display it after the original line ($0)
Sort: sort on filename and size
Take the biggest size of each group_id (column 10 added by awk at beginning)
edited Mar 28 at 5:58
tripleee
102k15 gold badges150 silver badges204 bronze badges
102k15 gold badges150 silver badges204 bronze badges
answered Mar 27 at 15:45
user2178964user2178964
415 gold badges14 silver badges27 bronze badges
415 gold badges14 silver badges27 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f55377340%2fbash-find-files-and-filter-by-date-and-size%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
Stack Overflow is not a code writing service. What have you searched for before asking, and what did you find? Based on that, what did you try, and how did it fail?
– tripleee
Mar 27 at 12:37
I edit my post. I just want some ideas, I don't ask for a clean and complete answer necessarly. Thanks
– user2178964
Mar 27 at 13:49
And "ko" is your language's abbreviation for kB I guess?
– tripleee
Mar 27 at 13:53
And
*Zis actually a placeholder for*.txtor your files are actually named according to that wildcard?– tripleee
Mar 27 at 13:56
yes, ko=kb , and I edit my post to replace *.Z by *.txt
– user2178964
Mar 27 at 14:02