J
J
jidckii2015-07-29 16:58:59
linux
jidckii, 2015-07-29 16:58:59

How to find and show the content of the file with the highest name value?

How to find and show the contents of the file with the highest value name ?
Condition :
The directory /opt/1/ contains files with names like

1436811088_1
1436811088_15
1436813877_7

...
There are 100,000 such files. The files are named in ascending order of date. Thus, when comparing the names of two files in a string, the name of the file created later will have a greater value.
Specify the bash command, which can display the contents of the last file in the /opt/1/ directory.
I sorted and found the largest using
ls -1v | sort | tail -n 1
but somehow I don’t understand how to do it in 1 command in such a way that it would display the contents of the resulting output file.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2015-07-29
@jidckii

cat `ls -1v | sort | tail -n 1`
right?

A
Andrey Burov, 2015-07-29
@BuriK666

ls -1c | head

-c with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and sort by name; otherwise: sort by ctime, newest first
--sort=WORD
sort by WORD instead of name: none (-U), size (-S), time (-t), version (-v), extension (-X)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question