Hello,
To list all MP4 files with an extentions, eg. mp4 or MP4, I can run 'locate' and 'ls -lt' for a detailed and date ordered list.
locate -i .mp4|xargs ls -tl
[...]
Hello,
To list all MP4 files with an extentions, eg. mp4 or MP4, I can run 'locate' and 'ls -lt' for a detailed and date ordered list.
locate -i .mp4|xargs ls -tl
-rw-r--r-- 1 tuxedo users 96959180 Dec 8 2018 /home/tuxedo/Desktop/videos2018/MAH0055.MP4
-rw-r--r-- 1 tuxedo users 45972453 Dec 8 2018 /home/tuxedo/Desktop/videos2018/MAH0045.MP4
-rw-r--r-- 1 tuxedo users 10313044 Dec 7 2018 /home/tuxedo/Desktop/videos2018/MAH0020.mp4
-rw-r--r-- 1 tuxedo users 981765973 Dec 7 2018 /home/tuxedo/Desktop/videos2018/MAH0011.MP4
etc.
For local file browsing, I would like the output as follows:
-rw-r--r-- 1 tuxedo users 96959180 Dec 8 2018 <a href=/home/tuxedo/Desktop/videos2018/MAH0055.MP4>MAH0055</a>
-rw-r--r-- 1 tuxedo users 45972453 Dec 8 2018 <a href=/home/tuxedo/Desktop/videos2018/MAH0045.MP4>MAH0045</a>
-rw-r--r-- 1 tuxedo users 10313044 Dec 7 2018 <a href=/home/tuxedo/Desktop/videos2018/MAH0020.mp4>MAH0020</a>
-rw-r--r-- 1 tuxedo users 981765973 Dec 7 2018 <a href=/home/tuxedo/Desktop/videos2018/MAH0011.MP4>MAH0011</a>
etc.
In other words:
add '<a href=' before the file path and the
append '>' after
append the filename for each find
append '</a>' after the filename
How can this be done using any combination of commands and constructs?
Many thanks,
Tuxedo
On 12.08.2022 03:21, Tuxedo wrote:
Hello,
To list all MP4 files with an extentions, eg. mp4 or MP4, I can run
'locate' and 'ls -lt' for a detailed and date ordered list.
Are you sure that this is true?
locate -i .mp4|xargs ls -tl
Locate will not do the sorting, and xargs will sort only those entries
of the locate output that fits in the exec buffer. So in the general
case - i.e. if not all files fit in one invocation of xargs's ls - you
will get chunks of sorted subsets only.
Janis
[...]
On 12.08.2022 03:21, Tuxedo wrote:[...]
The filename is (e.g.) "MAH0011.MP4" but you want "MAH0011", it seems. Stripping any extension might not lead to sensible filenames, depending
on the naming rule. - Consider how files should be displayed, e.g., "f.tar.gz", or ".sh_profile", etc.
append '</a>' after the filename
How can this be done using any combination of commands and constructs?
One way can be along this principle approach...
locate -i .mp4 |
xargs stat -c'%Y <a href=%n>%n</a>' |
sort -n |
cut -d' ' -f2- |
sed 's/>[^<]\+\/\(.*\)[.][^.]\+</>\1</'
Here the stat command will add modification time in seconds since Epoch,
sort will do the numerical sorting of the entries, cut strips off that seconds field again, and sed will remove the unwanted parts from the file-path that will be visible in the HTML output.
Specifically the sed expression may be adjusted, depending on what the "filename" actually shall be (see note on top).
Janis
Many thanks,
Tuxedo
Janis Papanagnou wrote:
On 12.08.2022 03:21, Tuxedo wrote:[...]
The filename is (e.g.) "MAH0011.MP4" but you want "MAH0011", it seems.
Stripping any extension might not lead to sensible filenames, depending
on the naming rule. - Consider how files should be displayed, e.g.,
"f.tar.gz", or ".sh_profile", etc.
You're right. It's best not to hide the file extensions.
append '</a>' after the filename
How can this be done using any combination of commands and constructs?
One way can be along this principle approach...
locate -i .mp4 |
xargs stat -c'%Y <a href=%n>%n</a>' |
sort -n |
cut -d' ' -f2- |
sed 's/>[^<]\+\/\(.*\)[.][^.]\+</>\1</'
Here the stat command will add modification time in seconds since Epoch,
sort will do the numerical sorting of the entries, cut strips off that
seconds field again, and sed will remove the unwanted parts from the
file-path that will be visible in the HTML output.
Specifically the sed expression may be adjusted, depending on what the
"filename" actually shall be (see note on top).
Thanks for the stat, sort and sed tricks!
It outputs a list of the file name portions within the <a href=linkpath">filename</a>
But, as said, it's better to include the file extensions in the output. Systems which typically hide file extensions are for users who get confused by them.
Can anyone here also suggest how to include a part of the file path in the link name to add a visual indication of the whereabouts of each file in the HTML list output, something like follows:
<a href=/home/tuxedo/some/dir/MAH0045.MP4>~/some/dir/MAH0045.MP4</a>
This presumes all is somewhere in ~/ although it's not. Replacing the /home/tuxedo string with /~ is just meant to shorten the output a little.
Before the link, how can a date stamp best be added?
As in:
Dec 14 2018 <a href=/home/tuxedo/some/dir/MAH0045.MP4>~/some/dir/MAH0045.MP4</a>
Or maybe:
2018-12-14
<a href=/home/tuxedo/some/dir/MAH0045.MP4>~/some/dir/MAH0045.MP4</a>
And after the link, how can the file sizes be added to the final output?
As in "YY-MM-DD <a..>file.ext</a> (size)":
2018-12-14
<a href=/home/tuxedo/some/dir/MAH0045.MP4>~/some/dir/MAH0045.MP4</a> (15MB)
Or the size can appear before or between the date and file name. It doesn't really matter as long as it's somewhere.
Thanks for any additional ideas!
Tuxedo
Janis
Many thanks,
Tuxedo
Janis Papanagnou wrote:
On 12.08.2022 03:21, Tuxedo wrote:
Hello,
To list all MP4 files with an extentions, eg. mp4 or MP4, I can run
'locate' and 'ls -lt' for a detailed and date ordered list.
Are you sure that this is true?
locate -i .mp4|xargs ls -tl
Locate will not do the sorting, and xargs will sort only those entries
of the locate output that fits in the exec buffer. So in the general
case - i.e. if not all files fit in one invocation of xargs's ls - you
will get chunks of sorted subsets only.
Thanks for these vital bits of information!
With a bit over 2,000 files in the output, maybe it's below the limit of xargs' ls buffer sorting capability or maybe I'm missing many files in the output that do not fit in.
On 12.08.2022 09:33, Tuxedo wrote:
Janis Papanagnou wrote:
Without stripping the extension: sed 's/>[^<]\+\/\(.*\)</>\1</'
Can anyone here also suggest how to include a part of the file path in the >> link name to add a visual indication of the whereabouts of each file in the >> HTML list output, something like follows:
You could adjust the sed regexp by keeping a couple (two?) optional
'/' characters. After the \/ part of the pattern and within the \(
... \) subexpression add a couple to be expected as \/[^/]+\/[^/]+ (untested).
On 12.08.2022 10:07, Janis Papanagnou wrote:
On 12.08.2022 09:33, Tuxedo wrote:
Janis Papanagnou wrote:
Without stripping the extension: sed 's/>[^<]\+\/\(.*\)</>\1</'
Can anyone here also suggest how to include a part of the file path in
the link name to add a visual indication of the whereabouts of each file >>> in the HTML list output, something like follows:
You could adjust the sed regexp by keeping a couple (two?) optional
'/' characters. After the \/ part of the pattern and within the \(
... \) subexpression add a couple to be expected as \/[^/]+\/[^/]+
(untested).
I think the '+' regexp meta-symbol must be escaped '\+' as above;
you'll find out yourself if you try the most appropriate substring.
Janis
Janis Papanagnou wrote:
On 12.08.2022 10:07, Janis Papanagnou wrote:
On 12.08.2022 09:33, Tuxedo wrote:
Janis Papanagnou wrote:
Without stripping the extension: sed 's/>[^<]\+\/\(.*\)</>\1</'
Can anyone here also suggest how to include a part of the file path in >>>> the link name to add a visual indication of the whereabouts of each file >>>> in the HTML list output, something like follows:
You could adjust the sed regexp by keeping a couple (two?) optional
'/' characters. After the \/ part of the pattern and within the \(
... \) subexpression add a couple to be expected as \/[^/]+\/[^/]+
(untested).
I think the '+' regexp meta-symbol must be escaped '\+' as above;
you'll find out yourself if you try the most appropriate substring.
Janis
Thank you for all these magic tricks. It gives me plenty to experiment with for a while :-)
Tuxedo
I've just noticed that stat's %y creates a lot of probably undesired
time information (if you want only the date).
$ stat -c%y /var/games/slashem/record
2022-08-11 13:47:33.893058723 +0200
So here's some more hints with a test file to show how it works...
echo "/var/games/slashem/record" |
xargs stat -c'%Y %y <a href="%n">%n</a> %s' |
sort -n | cut -d' ' -f2- |
sed -e 's/ [0-9][0-9]:[^<]*</ </' \
-e 's/>[^<]\+\(\/[^/]\+\/[^/]\+\)</>...\1</
...will produce...
2022-08-11 <a href="/var/games/slashem/record">.../slashem/record</a>
10030
The first sed substitution expression removes the spurious time data
and the second one keeps just two path components and adds '...'.
Probably a better iteration to play with.
echo "/var/games/slashem/record" |
xargs stat -c'%Y %y <a href="%n">%n</a> %s' |
sort -n | cut -d' ' -f2- |
sed -e 's/ [0-9][0-9]:[^<]*</ </' \
-e 's/>[^<]\+\(\/[^/]\+\/[^/]\+\)</>...\1</
...will produce...
2022-08-11 <a href="/var/games/slashem/record">.../slashem/record</a> 10030
The first sed substitution expression removes the spurious time data
and the second one keeps just two path components and adds '...'.
Janis Papanagnou <[email protected]> writes:
echo "/var/games/slashem/record" |
xargs stat -c'%Y %y <a href="%n">%n</a> %s' |
sort -n | cut -d' ' -f2- |
sed -e 's/ [0-9][0-9]:[^<]*</ </' \
-e 's/>[^<]\+\(\/[^/]\+\/[^/]\+\)</>...\1</
...will produce...
2022-08-11 <a href="/var/games/slashem/record">.../slashem/record</a> 10030 >>
The first sed substitution expression removes the spurious time data
The first one is unnecessary if you instead use:
cut -d' ' -f2,5-
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (0 / 16) |
| Uptime: | 164:53:48 |
| Calls: | 12,096 |
| Calls today: | 4 |
| Files: | 15,001 |
| Messages: | 6,517,803 |