ম্যাকোএস টার্মিনাল ডিরেক্টরিতে সর্বাধিক সাম্প্রতিক ফাইল সন্ধান করে [সদৃশ]


0

ডিএসএলআর থেকে bashঅ্যাপলের স্ট্যান্ডার্ডে আমদানি করা সর্বাধিক সাম্প্রতিক ছবি শনাক্ত করার জন্য আমি একটি দ্রুত সামান্য ফাংশন লিখছি (যা আমি ভেবেছিলাম) Photos.app

এখনও পর্যন্ত এটি দেখতে এরকম কিছু দেখাচ্ছে:

find ~/Pictures/Photos\ Library.photoslibrary/Masters -type f

বেশ সহজ. এটি যেমন রয়েছে, এটি আমদানিকৃত ফটোগুলির পুরো লাইব্রেরিটি তালিকাভুক্ত করে। আমার প্রথম প্রবৃত্তিটি ছিল সহজভাবে | tail -n 1, তবে ফাইলগুলি কোনও বোধগম্য ক্রমে তালিকাভুক্ত করা হয়নি।

আমি বিবেচনা করেছি | sort -V, কিন্তু ফাইলের নামগুলি (যেমন IMG_0123.CR2) অর্ডার অফ হওয়া অস্বাভাবিক নয় ।

এফওয়াইআই: এই বিএসডি সংস্করণটি জিএনইউ সংস্করণে পাওয়া বিকল্পটিকে findসমর্থন করে না -printf


তালিকা কমান্ড হয় ls -lt dir | head -n 1আপনি প্রথম ফাইলটি পায় কিন্তু আমি ফাইল ফরম্যাট অর্থাত * .jpg যে ফটো তাই ব্যবহার অনেক বেশী সুনিদৃষ্ট হতে পারে না জানি না
মার্ক

উত্তর:


2

আমি অনুরূপ প্রশ্নের উত্তর পেয়েছি, পরিবর্তনের তারিখ অনুসারে অর্ডার ফাইন্ড-ফলাফলগুলি

আপনার ক্ষেত্রে এটি এমন কিছু হওয়া উচিত:

find ~/Pictures/Photos\ Library.photoslibrary/Masters -type f -print0 | xargs -0 ls -tl

এটি কীভাবে ইন্টারেক্ট করে সে সম্পর্কে আরও তথ্য উপরের লিঙ্কটিতে পাওয়া যাবে।


1

এই পার্ল স্ক্রিপ্টটি আপনার অনুসন্ধানের কোথাও সংরক্ষণ করুন - chmodএটি কার্যকর করার যোগ্য করার জন্য , এটি কেবল চালনা করুন। এটি আপনাকে নাম বা তারিখ অনুসারে বাছাই সহ কয়েকটি বিকল্পের জন্য অনুরোধ করবে। এটি একটি পুরানো স্ক্রিপ্ট যা আমি বছর কয়েক আগে লিখেছি, এটিকে খুব বেশি আবর্জনা ফেলবেন না; এটা কাজ করে!

#!/usr/bin/perl -w

# This script finds files or folders that have been modified "recently"
# (as determined by the timeframe specified in the arguments).
# Just run the script to get the full usage instructions.

use strict;
use File::Find;
use Config;

my $time;
my $units;
my $dir;
my $order = "time";
my @validUnits = qw(sec min hours days);
my @results;
my %results;

if ($#ARGV < 1) {
  print "\nUSAGE: $0 [-f] <time> <units> [dir]\n\n";
  print "Search for recently modified files or folders located\nin (or under) dir (which is \".\" if not specified).\n";
  print "\nResults are sorted by timestamp, in ascending order, unless the '-f' option is used\n";
  print "to specify sorting by filename.\n";
  print "\nPlease enter the time (just a number): ";
  $time = <>;
  chomp $time;
  print "Please enter the units (@validUnits): ";
  $units = <>;
  chomp $units;
  print "Please enter the directory: [.] ";
  $dir = <>;
  chomp $dir;
  if ($dir eq "") { $dir = "." }
  print "Sort order (file or time): [time] ";
  $order = <>;
  chomp $order;
  if ($order eq "") { $order = "time" }
  print "\n";
}
else {
  if ($ARGV[0] eq "-f") {
    $order = "filename";
    shift;
  }
  $time = shift;
  $units = shift;
  if ($#ARGV > -1) {
    $dir = shift;
  }
  else {
    $dir = ".";
  }
}

# Check the time entered.
if (!($time) || !($time =~ m/^[0-9]*$/)) {
  print "You must enter an integer for the length of time.\n";
  exit 1;
}

# Check the units entered.
my $validUnits = grep m/$units/, @validUnits;
if (!($units) || !($validUnits)) {
  print "You must use one of the valid units: @validUnits\n";
  exit 1;
}

if ("min" eq $units) { $time *= 60 }
if ("hours" =~ m/$units/) { $time *= 60 * 60 }
if ("days" =~ m/$units/) { $time *= 60 * 60 * 24 }
my $now = time();
my $then = $now - $time;

find
  (
     sub {
       # If you can't get the mtime for a file, it's probably a dead link.
       # Set $mtime back to "0", to remove this dead link from consideration.
       # NOTE: all links are resolved, so $mtime reflects the mtime of the
       # link target, not the link itself.
       my $mtime = (stat)[9] || "0";
       if ($mtime > $then) {
     # If the $mtime is more recent than the target ($then),
     # add the mtime to the %results hash,
     # keyed by filename (w/ relative path)
     $results{$File::Find::name} = $mtime;
       }
     }
     , $dir
  );

# Get all the keys (filenames) of the %results hash.
# If we're sorting by "time", re-sort @results by the timestamp.
@results = sort keys %results;
if ($order eq "time") {
  @results = sort { $results{$a} <=> $results{$b} } @results;
}

foreach my $key (@results) {
  # If we're sorting by "time", print the time first, followed by filename.
  # Else, print filename first, followed by time.
  if ($order eq "time") {
    print localtime($results{$key}) . ": $key\n";
  }
  else {
    print "$key: " . localtime($results{$key}) . "\n";
  }
}

if ($Config{'osname'} eq "MSWin32") {
  print "\nPress RETURN to exit.\n";
  <>;
}
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.