How to Display Modified Date Time with 'Find' Command

How to display modified date time with 'find' command?

You could use the -exec switch for find and define the output format of stat using the -c switch as follows:

find /var -maxdepth 2 -type d -exec stat -c "%n %y" {} \;

This should give the filename followed by its modification time on the same line of the output.

How to view file date of result of find command in bash

You need either xargs or -exec for this:

find . -ctime 1 -exec ls -l {} \;

find . -ctime 1 | xargs ls -l

(The first executes ls on every found file individually, the second bunches them up into one ore more big ls invocations, so that they may be formatted slightly better.)

use find command to display file last modified at a particular time

find <DIR> -newermt '<DATE1>' \! -newermt '<DATE2>'

for more details you can read the man page for find, search in it for newerXY option
.... ! means not.

So the above command is interpreted as: find files in <DIR> that are newer than <DATE1> and not newer than <DATE2>.

Also note that some older versions of find do not have -newerXY. In that case you have to create two files with touch (touch allows you to specify a date) and use find <DIR> -newer <your ref file > \! -newer <your ref file 2>

Finding most recent file from a list of directories from find command

I think you could:

find . -type d -name "Financials" -print0 |
xargs -0 -I{} find {} -type f -print0 |
xargs -0 stat -f "%m %N" | sort -rn | head -1 | cut -f2- -d" "

But if you want separately for each dir, then... why not just loop it:

find . -type d -name "Financials" |
while IFS= read -r dir; do
echo "newest file in $dir is $(
find "$dir" -type f -print0 |
xargs -0 stat -f "%m %N" | sort -rn | head -1 | cut -f2- -d" "
)"
done

How to change month format for ls -l custom command

By default, C programs run with the C locale. It looks as though you want a different locale, so use the setlocale() function with another locale. The simplest is specified by the empty string. (A value of "C" for locale specifies the minimal environment for C translation; a value of "" for locale specifies the locale-specific native environment. Other implementation-defined strings may be passed as the second argument to setlocale.):

setlocale(LC_TIME, “”);

This only affects time; you could use LC_ALL to change everything.

Finding modified date of a file/folder

If you run the Get-Item or Get-ChildItem commands these will output System.IO.FileInfo and System.IO.DirectoryInfo objects that contain this information e.g.:

Get-Item c:\folder | Format-List  

Or you can access the property directly like so:

Get-Item c:\folder | Foreach {$_.LastWriteTime}

To start to filter folders & files based on last write time you can do this:

Get-ChildItem c:\folder | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-7)}

How to get last modified date on Windows command line for a set of files?

In the code that follows, change % to %% for use in batch file, for %~ta syntax enter call /?

for %a in (MyFile.txt) do set FileDate=%~ta

Sample output:

for %a in (MyFile.txt) do set FileDate=%~ta
set FileDate=05/05/2020 09:47 AM

for %a in (file_not_exist_file.txt) do set FileDate=%~ta
set FileDate=

get modified date of subfolder within folder

I tried multiple times and below is the script that helped me. I need to verify it because it is still running.

$CSVFilePath = Get-Content "C:\RA\main.txt"
$outputsss = "C:\RA\output.csv"
foreach($fileName in $CSVFilePath)
{
echo $fileName;
If (Test-Path $fileName) {

$latest = Get-ChildItem -Recurse -Path $fileName | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$latest.LastWriteTime

#$d = Get-ItemProperty -path $fileName -Name LastWriteTime
$times = $fileName + " - " + $latest.LastWriteTime
$times
}
$times |Out-File $outputsss -Encoding utf8 -append

}

I hope it worth for someone.

How to Display Modified Time and Modified By Fields Correctly with Powershell

User Fields

Normally in server side code, accessing a user field value using array notation (eg myItem["Author"]) would return an object that you would cast to an appropriate type (Microsoft.SharePoint.SPFieldUserValue). Powershell, however, automatically casts these values to strings, which is why you're getting undesirable values.

Fortunately, there's a way around it! First, get the field itself as an object, then pass the field value into the field's GetFieldValue() method.

$userField = $item.Fields.GetField("Author");
$authorObject = $userField.GetFieldValue($item["Author"]);

You'll then have an object with properties you can access to retrieve the desired values, such as LookupValue for the user's display name on the site.

$authorName = $authorObject.LookupValue;

Date Fields

Date fields are little easier, because Powershell will actually hand them over to you as DateTime objects.

To format a DateTime object, you can just call .ToString() and pass in a parameter indicating the desired format.

$data = @{
...
"Modified Date" = $item["Modified"].ToString("MM/dd/yyyy h:mm tt");
...
}

Time Discrepancy

This is most likely attributable to your local timezone. The times displayed on a SharePoint site via the browser are determined by your PC's timezone settings. The times actually saved to SharePoint's underlying database are determined by the server's timezone settings.

To reconcile them, you can use the DateTime object's .ToUniversalTime() method to get a corresponding DateTime object in UTC time (and optionally offset it as desired until it aligns with the local timezone and daylight savings adjustments).

Edit: I'm guessing you're in US Eastern time (UTC-5) and it's giving you results in UTC time (Universal Coordinated Time, which is 5 hours ahead of you except during daylight saving time). You should be able to offset the hours manually to account for this.

$localOffset = -5;
$modified = $version["Modified"] -as [datetime];
if($modified.IsDaylightSavingTime()){$localOffset += 1;}
$modifiedLocal = $modified.addHours(-$localOffset);


Related Topics



Leave a reply



Submit