How do I open latest file from list of files in a particular directory in aix
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
How do I open the latest file from list of files in a particular directory?
Same file name arrange in date wise with latest in last.
Currently I am using following commands:
ls -lrt filename*
tail -f filename
shell-script files date aix
add a comment |Â
up vote
1
down vote
favorite
How do I open the latest file from list of files in a particular directory?
Same file name arrange in date wise with latest in last.
Currently I am using following commands:
ls -lrt filename*
tail -f filename
shell-script files date aix
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
How do I open the latest file from list of files in a particular directory?
Same file name arrange in date wise with latest in last.
Currently I am using following commands:
ls -lrt filename*
tail -f filename
shell-script files date aix
How do I open the latest file from list of files in a particular directory?
Same file name arrange in date wise with latest in last.
Currently I am using following commands:
ls -lrt filename*
tail -f filename
shell-script files date aix
edited Jun 26 at 10:07
Jeff Schaller
30.8k846104
30.8k846104
asked Jun 26 at 6:33
Ajay mishra
61
61
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
If your shell is a Bourne-like shell and its [
builtin implements the -nt
test to test whether one file is newer than another, you may use
newest=
for file in ./* ./.*; do
if [ -f "$file" ]; then
if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
newest=$file
fi
fi
done
if [ -f "$newest" ]; then
printf 'The latest file is "%s"n' "$newest"
else
echo 'Could not find files here' >&2
exit 1
fi
This would iterate over all regular (and symlink to regular) files (including hidden ones) in the current directory and then tell you which one was found to be the newest file. You would replace the printf
statement with the actual command that you'd want to run on "$newest"
.
As a shell function, which additionally takes a list of files as its argument:
newest () (
newest=
for file do
if [ -f "$file" ]; then
if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
newest=$file
fi
fi
done
if [ -f "$newest" ]; then
printf '%sn' "$newest"
else
echo 'No files found' >&2
return 1
fi
)
Then
tail -f "$(newest ./filename*)"
add a comment |Â
up vote
0
down vote
You can use GNU find
, to print all files with their last modified time, sort
them in reverse order, get the latest modified file ( head -n 1
- top entry ) and then do a tail of the last modified file
find <Directory-name> -type f -printf '%TY-%Tm-%Td %TT %pn' | sort -r | head -n 1 | awk 'print $3' | xargs tail -f
add a comment |Â
up vote
0
down vote
If zsh
is installed, you can do in it:
tail -f filenameCtrl+xm
Ctrl+xm is a completer that expands to the latest file (according to last modification time).
In a script:
#! /usr/bin/env zsh
tail -f filename*(om[1])
Where om
sorts by modification time (most recent first) and [1]
selects the first.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
If your shell is a Bourne-like shell and its [
builtin implements the -nt
test to test whether one file is newer than another, you may use
newest=
for file in ./* ./.*; do
if [ -f "$file" ]; then
if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
newest=$file
fi
fi
done
if [ -f "$newest" ]; then
printf 'The latest file is "%s"n' "$newest"
else
echo 'Could not find files here' >&2
exit 1
fi
This would iterate over all regular (and symlink to regular) files (including hidden ones) in the current directory and then tell you which one was found to be the newest file. You would replace the printf
statement with the actual command that you'd want to run on "$newest"
.
As a shell function, which additionally takes a list of files as its argument:
newest () (
newest=
for file do
if [ -f "$file" ]; then
if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
newest=$file
fi
fi
done
if [ -f "$newest" ]; then
printf '%sn' "$newest"
else
echo 'No files found' >&2
return 1
fi
)
Then
tail -f "$(newest ./filename*)"
add a comment |Â
up vote
2
down vote
If your shell is a Bourne-like shell and its [
builtin implements the -nt
test to test whether one file is newer than another, you may use
newest=
for file in ./* ./.*; do
if [ -f "$file" ]; then
if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
newest=$file
fi
fi
done
if [ -f "$newest" ]; then
printf 'The latest file is "%s"n' "$newest"
else
echo 'Could not find files here' >&2
exit 1
fi
This would iterate over all regular (and symlink to regular) files (including hidden ones) in the current directory and then tell you which one was found to be the newest file. You would replace the printf
statement with the actual command that you'd want to run on "$newest"
.
As a shell function, which additionally takes a list of files as its argument:
newest () (
newest=
for file do
if [ -f "$file" ]; then
if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
newest=$file
fi
fi
done
if [ -f "$newest" ]; then
printf '%sn' "$newest"
else
echo 'No files found' >&2
return 1
fi
)
Then
tail -f "$(newest ./filename*)"
add a comment |Â
up vote
2
down vote
up vote
2
down vote
If your shell is a Bourne-like shell and its [
builtin implements the -nt
test to test whether one file is newer than another, you may use
newest=
for file in ./* ./.*; do
if [ -f "$file" ]; then
if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
newest=$file
fi
fi
done
if [ -f "$newest" ]; then
printf 'The latest file is "%s"n' "$newest"
else
echo 'Could not find files here' >&2
exit 1
fi
This would iterate over all regular (and symlink to regular) files (including hidden ones) in the current directory and then tell you which one was found to be the newest file. You would replace the printf
statement with the actual command that you'd want to run on "$newest"
.
As a shell function, which additionally takes a list of files as its argument:
newest () (
newest=
for file do
if [ -f "$file" ]; then
if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
newest=$file
fi
fi
done
if [ -f "$newest" ]; then
printf '%sn' "$newest"
else
echo 'No files found' >&2
return 1
fi
)
Then
tail -f "$(newest ./filename*)"
If your shell is a Bourne-like shell and its [
builtin implements the -nt
test to test whether one file is newer than another, you may use
newest=
for file in ./* ./.*; do
if [ -f "$file" ]; then
if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
newest=$file
fi
fi
done
if [ -f "$newest" ]; then
printf 'The latest file is "%s"n' "$newest"
else
echo 'Could not find files here' >&2
exit 1
fi
This would iterate over all regular (and symlink to regular) files (including hidden ones) in the current directory and then tell you which one was found to be the newest file. You would replace the printf
statement with the actual command that you'd want to run on "$newest"
.
As a shell function, which additionally takes a list of files as its argument:
newest () (
newest=
for file do
if [ -f "$file" ]; then
if [ -z "$newest" ] || [ "$file" -nt "$newest" ]; then
newest=$file
fi
fi
done
if [ -f "$newest" ]; then
printf '%sn' "$newest"
else
echo 'No files found' >&2
return 1
fi
)
Then
tail -f "$(newest ./filename*)"
edited Jun 26 at 10:12
Stéphane Chazelas
278k52513844
278k52513844
answered Jun 26 at 6:44
Kusalananda
101k13199312
101k13199312
add a comment |Â
add a comment |Â
up vote
0
down vote
You can use GNU find
, to print all files with their last modified time, sort
them in reverse order, get the latest modified file ( head -n 1
- top entry ) and then do a tail of the last modified file
find <Directory-name> -type f -printf '%TY-%Tm-%Td %TT %pn' | sort -r | head -n 1 | awk 'print $3' | xargs tail -f
add a comment |Â
up vote
0
down vote
You can use GNU find
, to print all files with their last modified time, sort
them in reverse order, get the latest modified file ( head -n 1
- top entry ) and then do a tail of the last modified file
find <Directory-name> -type f -printf '%TY-%Tm-%Td %TT %pn' | sort -r | head -n 1 | awk 'print $3' | xargs tail -f
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You can use GNU find
, to print all files with their last modified time, sort
them in reverse order, get the latest modified file ( head -n 1
- top entry ) and then do a tail of the last modified file
find <Directory-name> -type f -printf '%TY-%Tm-%Td %TT %pn' | sort -r | head -n 1 | awk 'print $3' | xargs tail -f
You can use GNU find
, to print all files with their last modified time, sort
them in reverse order, get the latest modified file ( head -n 1
- top entry ) and then do a tail of the last modified file
find <Directory-name> -type f -printf '%TY-%Tm-%Td %TT %pn' | sort -r | head -n 1 | awk 'print $3' | xargs tail -f
edited Jun 26 at 10:12
answered Jun 26 at 6:49
Arushix
9968
9968
add a comment |Â
add a comment |Â
up vote
0
down vote
If zsh
is installed, you can do in it:
tail -f filenameCtrl+xm
Ctrl+xm is a completer that expands to the latest file (according to last modification time).
In a script:
#! /usr/bin/env zsh
tail -f filename*(om[1])
Where om
sorts by modification time (most recent first) and [1]
selects the first.
add a comment |Â
up vote
0
down vote
If zsh
is installed, you can do in it:
tail -f filenameCtrl+xm
Ctrl+xm is a completer that expands to the latest file (according to last modification time).
In a script:
#! /usr/bin/env zsh
tail -f filename*(om[1])
Where om
sorts by modification time (most recent first) and [1]
selects the first.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
If zsh
is installed, you can do in it:
tail -f filenameCtrl+xm
Ctrl+xm is a completer that expands to the latest file (according to last modification time).
In a script:
#! /usr/bin/env zsh
tail -f filename*(om[1])
Where om
sorts by modification time (most recent first) and [1]
selects the first.
If zsh
is installed, you can do in it:
tail -f filenameCtrl+xm
Ctrl+xm is a completer that expands to the latest file (according to last modification time).
In a script:
#! /usr/bin/env zsh
tail -f filename*(om[1])
Where om
sorts by modification time (most recent first) and [1]
selects the first.
answered Jun 26 at 10:16
Stéphane Chazelas
278k52513844
278k52513844
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451921%2fhow-do-i-open-latest-file-from-list-of-files-in-a-particular-directory-in-aix%23new-answer', 'question_page');
);
Post as a guest
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
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
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