Find the age of the oldest file in one line or return zeroDetermining number of files in a directory without counting themCheck for subdirectoryAdd mtime to grep -c output and sort the output by mtimehow to find files of current date in remote server and copy those file to local server using rcp using shell scripting (ksh)?Search for files that contain a string and list their names sorted by the modified daterecursive search and print most recent tar.gz file in each dirFind and rm command deleted the files inside the directory and the directory itselfHow do I change the sorting method of files used by asterisk (*) in bash?Find files, print creation date and file namescp <source>:<filepath> <dest> works from command line, but cp: cannot stat error from script. Why?
Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?
How much of data wrangling is a data scientist's job?
Why is consensus so controversial in Britain?
NMaximize is not converging to a solution
What defenses are there against being summoned by the Gate spell?
Languages that we cannot (dis)prove to be Context-Free
Definite integral giving negative value as a result?
Why can't I see bouncing of a switch on an oscilloscope?
What is a clear way to write a bar that has an extra beat?
tikz convert color string to hex value
Java Casting: Java 11 throws LambdaConversionException while 1.8 does not
Approximately how much travel time was saved by the opening of the Suez Canal in 1869?
Is it inappropriate for a student to attend their mentor's dissertation defense?
Add text to same line using sed
Why can't we play rap on piano?
LaTeX: Why are digits allowed in environments, but forbidden in commands?
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
strTok function (thread safe, supports empty tokens, doesn't change string)
Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?
How does quantile regression compare to logistic regression with the variable split at the quantile?
Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?
Why is 150k or 200k jobs considered good when there's 300k+ births a month?
Why doesn't H₄O²⁺ exist?
How can bays and straits be determined in a procedurally generated map?
Find the age of the oldest file in one line or return zero
Determining number of files in a directory without counting themCheck for subdirectoryAdd mtime to grep -c output and sort the output by mtimehow to find files of current date in remote server and copy those file to local server using rcp using shell scripting (ksh)?Search for files that contain a string and list their names sorted by the modified daterecursive search and print most recent tar.gz file in each dirFind and rm command deleted the files inside the directory and the directory itselfHow do I change the sorting method of files used by asterisk (*) in bash?Find files, print creation date and file namescp <source>:<filepath> <dest> works from command line, but cp: cannot stat error from script. Why?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to find the age of the oldest file in a certain directory or return 0 if there aren't any files in this directory. I also need a one-line command doing it. So far this is my command for finding the age in seconds of the oldest file in the directory:
expr $(($(date +%s) - $(stat -c %Y $(ls -lt /path/to/dir/ | tail -1 | awk 'print $NF'))))
The problem is that if there are no files it is returning the following error:
$ expr $(($(date +%s) - $(stat -c %Y $(ls -lt /path/to/dir/ | tail -1 | awk 'print $NF'))))
stat: cannot stat ‘0’: No such file or directory
-bash: 1554373460 - : syntax error: operand expected (error token is "- ")
So in this case I want the command to return just 0 and to suppress the error printout.
shell-script files directory
add a comment |
I want to find the age of the oldest file in a certain directory or return 0 if there aren't any files in this directory. I also need a one-line command doing it. So far this is my command for finding the age in seconds of the oldest file in the directory:
expr $(($(date +%s) - $(stat -c %Y $(ls -lt /path/to/dir/ | tail -1 | awk 'print $NF'))))
The problem is that if there are no files it is returning the following error:
$ expr $(($(date +%s) - $(stat -c %Y $(ls -lt /path/to/dir/ | tail -1 | awk 'print $NF'))))
stat: cannot stat ‘0’: No such file or directory
-bash: 1554373460 - : syntax error: operand expected (error token is "- ")
So in this case I want the command to return just 0 and to suppress the error printout.
shell-script files directory
2
Out of curiosity, why does it have to be in one line? It's much less readable & maintainable that way.
– Jeff Schaller♦
yesterday
I am passing this line to specialized software. Then according to the output of the command, I can trigger an alarm and if I make it on more than a single line, I need to write more complex logic. The idea is to check a specific directory where there should not be any files for more than 20 seconds, I want to trigger an alarm if the age of the oldest file is more than 30 seconds.
– Georgе Stoyanov
yesterday
also I would be very happy if you have any ideas, how I can simplify my command for finding the age of the oldest file
– Georgе Stoyanov
yesterday
ls -lt | tail -1
will give you the oldest file; you can parse out the date or go through thestat
stuff without having to do a single line shell loop
– mpez0
yesterday
@mpez0 this is exactly what I am doing, check my original post.
– Georgе Stoyanov
20 hours ago
add a comment |
I want to find the age of the oldest file in a certain directory or return 0 if there aren't any files in this directory. I also need a one-line command doing it. So far this is my command for finding the age in seconds of the oldest file in the directory:
expr $(($(date +%s) - $(stat -c %Y $(ls -lt /path/to/dir/ | tail -1 | awk 'print $NF'))))
The problem is that if there are no files it is returning the following error:
$ expr $(($(date +%s) - $(stat -c %Y $(ls -lt /path/to/dir/ | tail -1 | awk 'print $NF'))))
stat: cannot stat ‘0’: No such file or directory
-bash: 1554373460 - : syntax error: operand expected (error token is "- ")
So in this case I want the command to return just 0 and to suppress the error printout.
shell-script files directory
I want to find the age of the oldest file in a certain directory or return 0 if there aren't any files in this directory. I also need a one-line command doing it. So far this is my command for finding the age in seconds of the oldest file in the directory:
expr $(($(date +%s) - $(stat -c %Y $(ls -lt /path/to/dir/ | tail -1 | awk 'print $NF'))))
The problem is that if there are no files it is returning the following error:
$ expr $(($(date +%s) - $(stat -c %Y $(ls -lt /path/to/dir/ | tail -1 | awk 'print $NF'))))
stat: cannot stat ‘0’: No such file or directory
-bash: 1554373460 - : syntax error: operand expected (error token is "- ")
So in this case I want the command to return just 0 and to suppress the error printout.
shell-script files directory
shell-script files directory
asked yesterday
Georgе StoyanovGeorgе Stoyanov
164421
164421
2
Out of curiosity, why does it have to be in one line? It's much less readable & maintainable that way.
– Jeff Schaller♦
yesterday
I am passing this line to specialized software. Then according to the output of the command, I can trigger an alarm and if I make it on more than a single line, I need to write more complex logic. The idea is to check a specific directory where there should not be any files for more than 20 seconds, I want to trigger an alarm if the age of the oldest file is more than 30 seconds.
– Georgе Stoyanov
yesterday
also I would be very happy if you have any ideas, how I can simplify my command for finding the age of the oldest file
– Georgе Stoyanov
yesterday
ls -lt | tail -1
will give you the oldest file; you can parse out the date or go through thestat
stuff without having to do a single line shell loop
– mpez0
yesterday
@mpez0 this is exactly what I am doing, check my original post.
– Georgе Stoyanov
20 hours ago
add a comment |
2
Out of curiosity, why does it have to be in one line? It's much less readable & maintainable that way.
– Jeff Schaller♦
yesterday
I am passing this line to specialized software. Then according to the output of the command, I can trigger an alarm and if I make it on more than a single line, I need to write more complex logic. The idea is to check a specific directory where there should not be any files for more than 20 seconds, I want to trigger an alarm if the age of the oldest file is more than 30 seconds.
– Georgе Stoyanov
yesterday
also I would be very happy if you have any ideas, how I can simplify my command for finding the age of the oldest file
– Georgе Stoyanov
yesterday
ls -lt | tail -1
will give you the oldest file; you can parse out the date or go through thestat
stuff without having to do a single line shell loop
– mpez0
yesterday
@mpez0 this is exactly what I am doing, check my original post.
– Georgе Stoyanov
20 hours ago
2
2
Out of curiosity, why does it have to be in one line? It's much less readable & maintainable that way.
– Jeff Schaller♦
yesterday
Out of curiosity, why does it have to be in one line? It's much less readable & maintainable that way.
– Jeff Schaller♦
yesterday
I am passing this line to specialized software. Then according to the output of the command, I can trigger an alarm and if I make it on more than a single line, I need to write more complex logic. The idea is to check a specific directory where there should not be any files for more than 20 seconds, I want to trigger an alarm if the age of the oldest file is more than 30 seconds.
– Georgе Stoyanov
yesterday
I am passing this line to specialized software. Then according to the output of the command, I can trigger an alarm and if I make it on more than a single line, I need to write more complex logic. The idea is to check a specific directory where there should not be any files for more than 20 seconds, I want to trigger an alarm if the age of the oldest file is more than 30 seconds.
– Georgе Stoyanov
yesterday
also I would be very happy if you have any ideas, how I can simplify my command for finding the age of the oldest file
– Georgе Stoyanov
yesterday
also I would be very happy if you have any ideas, how I can simplify my command for finding the age of the oldest file
– Georgе Stoyanov
yesterday
ls -lt | tail -1
will give you the oldest file; you can parse out the date or go through the stat
stuff without having to do a single line shell loop– mpez0
yesterday
ls -lt | tail -1
will give you the oldest file; you can parse out the date or go through the stat
stuff without having to do a single line shell loop– mpez0
yesterday
@mpez0 this is exactly what I am doing, check my original post.
– Georgе Stoyanov
20 hours ago
@mpez0 this is exactly what I am doing, check my original post.
– Georgе Stoyanov
20 hours ago
add a comment |
2 Answers
2
active
oldest
votes
If it must be one line:
stat -c %Y ./* 2>/dev/null | awk -v d="$(date +%s)" 'BEGIN m=d $0 < m m = $0 END print d - m'
stat -c %Y ./* 2>/dev/null
print the timestamp of all files, ignoring errors (so no files results in no output)With awk:
-v d="$(date +%s)"
save the current timestamp in a variabled
BEGIN m=d
initializem
tod
$0 < m m = $0
keeping track of the minimum inm
END print d - m
print the difference.
unfortunately, it does return 0 no matter if the directory is empty or it has more than one file
– Georgе Stoyanov
yesterday
@George ah, oops, I inverted the check for min
– muru
yesterday
add a comment |
With zsh
and perl
:
perl -le 'print 0+-M $ARGV[0]' /path/to/dir/*(N-Om[1])
(add the D
glob qualifier if you also want to consider hidden files (but not .
nor ..
)).
Note that for symlinks, that considers the modification time of the file it resolves to. Remove the -
in the glob qualifiers to consider the modification time of the symlink instead (and use (lstat$ARGV[0] && -M _)
in perl
to get the age of the symlink).
That gives the age in days. Multiply by 86400 to get a number of seconds:
perl -le 'print 86400*-M $ARGV[0]' /path/to/dir/*(N-Om[1])
(N-Om[1])
: glob qualifier:N
: turns onnullglob
for that glob. So if there's no file in the directory, expands to nothing causingperl
's-M
to returnundef
.-
: causes next glob qualifiers to apply on the target of symlinksOm
: reverse (capital) order by modification time (so from oldest to newest likels -rt
)[1]
: select first matching file only
-M file
: gets the age of the content of the file.0+
or86400*
force a conversion to number (for theundef
case).
I am getting just 0 as an output even though it should show me a couple of thousands of seconds, both commands actually gives me the same output and on another machine I am getting an error:-bash: syntax error near unexpected token '('
, the one giving me an error is running a rather old version of perl:v5.16.3
– Georgе Stoyanov
yesterday
2
@GeorgеStoyanov, the syntax is forzsh
, notbash
.
– Stéphane Chazelas
yesterday
I missed that part :) Thanks for the answer @Stephane
– Georgе Stoyanov
20 hours ago
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%2f510472%2ffind-the-age-of-the-oldest-file-in-one-line-or-return-zero%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If it must be one line:
stat -c %Y ./* 2>/dev/null | awk -v d="$(date +%s)" 'BEGIN m=d $0 < m m = $0 END print d - m'
stat -c %Y ./* 2>/dev/null
print the timestamp of all files, ignoring errors (so no files results in no output)With awk:
-v d="$(date +%s)"
save the current timestamp in a variabled
BEGIN m=d
initializem
tod
$0 < m m = $0
keeping track of the minimum inm
END print d - m
print the difference.
unfortunately, it does return 0 no matter if the directory is empty or it has more than one file
– Georgе Stoyanov
yesterday
@George ah, oops, I inverted the check for min
– muru
yesterday
add a comment |
If it must be one line:
stat -c %Y ./* 2>/dev/null | awk -v d="$(date +%s)" 'BEGIN m=d $0 < m m = $0 END print d - m'
stat -c %Y ./* 2>/dev/null
print the timestamp of all files, ignoring errors (so no files results in no output)With awk:
-v d="$(date +%s)"
save the current timestamp in a variabled
BEGIN m=d
initializem
tod
$0 < m m = $0
keeping track of the minimum inm
END print d - m
print the difference.
unfortunately, it does return 0 no matter if the directory is empty or it has more than one file
– Georgе Stoyanov
yesterday
@George ah, oops, I inverted the check for min
– muru
yesterday
add a comment |
If it must be one line:
stat -c %Y ./* 2>/dev/null | awk -v d="$(date +%s)" 'BEGIN m=d $0 < m m = $0 END print d - m'
stat -c %Y ./* 2>/dev/null
print the timestamp of all files, ignoring errors (so no files results in no output)With awk:
-v d="$(date +%s)"
save the current timestamp in a variabled
BEGIN m=d
initializem
tod
$0 < m m = $0
keeping track of the minimum inm
END print d - m
print the difference.
If it must be one line:
stat -c %Y ./* 2>/dev/null | awk -v d="$(date +%s)" 'BEGIN m=d $0 < m m = $0 END print d - m'
stat -c %Y ./* 2>/dev/null
print the timestamp of all files, ignoring errors (so no files results in no output)With awk:
-v d="$(date +%s)"
save the current timestamp in a variabled
BEGIN m=d
initializem
tod
$0 < m m = $0
keeping track of the minimum inm
END print d - m
print the difference.
edited yesterday
Stéphane Chazelas
313k57592948
313k57592948
answered yesterday
murumuru
37.2k589164
37.2k589164
unfortunately, it does return 0 no matter if the directory is empty or it has more than one file
– Georgе Stoyanov
yesterday
@George ah, oops, I inverted the check for min
– muru
yesterday
add a comment |
unfortunately, it does return 0 no matter if the directory is empty or it has more than one file
– Georgе Stoyanov
yesterday
@George ah, oops, I inverted the check for min
– muru
yesterday
unfortunately, it does return 0 no matter if the directory is empty or it has more than one file
– Georgе Stoyanov
yesterday
unfortunately, it does return 0 no matter if the directory is empty or it has more than one file
– Georgе Stoyanov
yesterday
@George ah, oops, I inverted the check for min
– muru
yesterday
@George ah, oops, I inverted the check for min
– muru
yesterday
add a comment |
With zsh
and perl
:
perl -le 'print 0+-M $ARGV[0]' /path/to/dir/*(N-Om[1])
(add the D
glob qualifier if you also want to consider hidden files (but not .
nor ..
)).
Note that for symlinks, that considers the modification time of the file it resolves to. Remove the -
in the glob qualifiers to consider the modification time of the symlink instead (and use (lstat$ARGV[0] && -M _)
in perl
to get the age of the symlink).
That gives the age in days. Multiply by 86400 to get a number of seconds:
perl -le 'print 86400*-M $ARGV[0]' /path/to/dir/*(N-Om[1])
(N-Om[1])
: glob qualifier:N
: turns onnullglob
for that glob. So if there's no file in the directory, expands to nothing causingperl
's-M
to returnundef
.-
: causes next glob qualifiers to apply on the target of symlinksOm
: reverse (capital) order by modification time (so from oldest to newest likels -rt
)[1]
: select first matching file only
-M file
: gets the age of the content of the file.0+
or86400*
force a conversion to number (for theundef
case).
I am getting just 0 as an output even though it should show me a couple of thousands of seconds, both commands actually gives me the same output and on another machine I am getting an error:-bash: syntax error near unexpected token '('
, the one giving me an error is running a rather old version of perl:v5.16.3
– Georgе Stoyanov
yesterday
2
@GeorgеStoyanov, the syntax is forzsh
, notbash
.
– Stéphane Chazelas
yesterday
I missed that part :) Thanks for the answer @Stephane
– Georgе Stoyanov
20 hours ago
add a comment |
With zsh
and perl
:
perl -le 'print 0+-M $ARGV[0]' /path/to/dir/*(N-Om[1])
(add the D
glob qualifier if you also want to consider hidden files (but not .
nor ..
)).
Note that for symlinks, that considers the modification time of the file it resolves to. Remove the -
in the glob qualifiers to consider the modification time of the symlink instead (and use (lstat$ARGV[0] && -M _)
in perl
to get the age of the symlink).
That gives the age in days. Multiply by 86400 to get a number of seconds:
perl -le 'print 86400*-M $ARGV[0]' /path/to/dir/*(N-Om[1])
(N-Om[1])
: glob qualifier:N
: turns onnullglob
for that glob. So if there's no file in the directory, expands to nothing causingperl
's-M
to returnundef
.-
: causes next glob qualifiers to apply on the target of symlinksOm
: reverse (capital) order by modification time (so from oldest to newest likels -rt
)[1]
: select first matching file only
-M file
: gets the age of the content of the file.0+
or86400*
force a conversion to number (for theundef
case).
I am getting just 0 as an output even though it should show me a couple of thousands of seconds, both commands actually gives me the same output and on another machine I am getting an error:-bash: syntax error near unexpected token '('
, the one giving me an error is running a rather old version of perl:v5.16.3
– Georgе Stoyanov
yesterday
2
@GeorgеStoyanov, the syntax is forzsh
, notbash
.
– Stéphane Chazelas
yesterday
I missed that part :) Thanks for the answer @Stephane
– Georgе Stoyanov
20 hours ago
add a comment |
With zsh
and perl
:
perl -le 'print 0+-M $ARGV[0]' /path/to/dir/*(N-Om[1])
(add the D
glob qualifier if you also want to consider hidden files (but not .
nor ..
)).
Note that for symlinks, that considers the modification time of the file it resolves to. Remove the -
in the glob qualifiers to consider the modification time of the symlink instead (and use (lstat$ARGV[0] && -M _)
in perl
to get the age of the symlink).
That gives the age in days. Multiply by 86400 to get a number of seconds:
perl -le 'print 86400*-M $ARGV[0]' /path/to/dir/*(N-Om[1])
(N-Om[1])
: glob qualifier:N
: turns onnullglob
for that glob. So if there's no file in the directory, expands to nothing causingperl
's-M
to returnundef
.-
: causes next glob qualifiers to apply on the target of symlinksOm
: reverse (capital) order by modification time (so from oldest to newest likels -rt
)[1]
: select first matching file only
-M file
: gets the age of the content of the file.0+
or86400*
force a conversion to number (for theundef
case).
With zsh
and perl
:
perl -le 'print 0+-M $ARGV[0]' /path/to/dir/*(N-Om[1])
(add the D
glob qualifier if you also want to consider hidden files (but not .
nor ..
)).
Note that for symlinks, that considers the modification time of the file it resolves to. Remove the -
in the glob qualifiers to consider the modification time of the symlink instead (and use (lstat$ARGV[0] && -M _)
in perl
to get the age of the symlink).
That gives the age in days. Multiply by 86400 to get a number of seconds:
perl -le 'print 86400*-M $ARGV[0]' /path/to/dir/*(N-Om[1])
(N-Om[1])
: glob qualifier:N
: turns onnullglob
for that glob. So if there's no file in the directory, expands to nothing causingperl
's-M
to returnundef
.-
: causes next glob qualifiers to apply on the target of symlinksOm
: reverse (capital) order by modification time (so from oldest to newest likels -rt
)[1]
: select first matching file only
-M file
: gets the age of the content of the file.0+
or86400*
force a conversion to number (for theundef
case).
edited yesterday
answered yesterday
Stéphane ChazelasStéphane Chazelas
313k57592948
313k57592948
I am getting just 0 as an output even though it should show me a couple of thousands of seconds, both commands actually gives me the same output and on another machine I am getting an error:-bash: syntax error near unexpected token '('
, the one giving me an error is running a rather old version of perl:v5.16.3
– Georgе Stoyanov
yesterday
2
@GeorgеStoyanov, the syntax is forzsh
, notbash
.
– Stéphane Chazelas
yesterday
I missed that part :) Thanks for the answer @Stephane
– Georgе Stoyanov
20 hours ago
add a comment |
I am getting just 0 as an output even though it should show me a couple of thousands of seconds, both commands actually gives me the same output and on another machine I am getting an error:-bash: syntax error near unexpected token '('
, the one giving me an error is running a rather old version of perl:v5.16.3
– Georgе Stoyanov
yesterday
2
@GeorgеStoyanov, the syntax is forzsh
, notbash
.
– Stéphane Chazelas
yesterday
I missed that part :) Thanks for the answer @Stephane
– Georgе Stoyanov
20 hours ago
I am getting just 0 as an output even though it should show me a couple of thousands of seconds, both commands actually gives me the same output and on another machine I am getting an error:
-bash: syntax error near unexpected token '('
, the one giving me an error is running a rather old version of perl: v5.16.3
– Georgе Stoyanov
yesterday
I am getting just 0 as an output even though it should show me a couple of thousands of seconds, both commands actually gives me the same output and on another machine I am getting an error:
-bash: syntax error near unexpected token '('
, the one giving me an error is running a rather old version of perl: v5.16.3
– Georgе Stoyanov
yesterday
2
2
@GeorgеStoyanov, the syntax is for
zsh
, not bash
.– Stéphane Chazelas
yesterday
@GeorgеStoyanov, the syntax is for
zsh
, not bash
.– Stéphane Chazelas
yesterday
I missed that part :) Thanks for the answer @Stephane
– Georgе Stoyanov
20 hours ago
I missed that part :) Thanks for the answer @Stephane
– Georgе Stoyanov
20 hours ago
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%2f510472%2ffind-the-age-of-the-oldest-file-in-one-line-or-return-zero%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
2
Out of curiosity, why does it have to be in one line? It's much less readable & maintainable that way.
– Jeff Schaller♦
yesterday
I am passing this line to specialized software. Then according to the output of the command, I can trigger an alarm and if I make it on more than a single line, I need to write more complex logic. The idea is to check a specific directory where there should not be any files for more than 20 seconds, I want to trigger an alarm if the age of the oldest file is more than 30 seconds.
– Georgе Stoyanov
yesterday
also I would be very happy if you have any ideas, how I can simplify my command for finding the age of the oldest file
– Georgе Stoyanov
yesterday
ls -lt | tail -1
will give you the oldest file; you can parse out the date or go through thestat
stuff without having to do a single line shell loop– mpez0
yesterday
@mpez0 this is exactly what I am doing, check my original post.
– Georgе Stoyanov
20 hours ago