一時フォルダにあるファイルの中で更新日時が一番新しいファイルを得るワンライナー
((Get-ChildItem (Get-ChildItem env:TEMP).Value | where {$_ -is [System.IO.FileInfo]} | sort LastWriteTime -Desc)[0]).FullName
ファイルのみの抽出のところで where { $_.Attributes -eq 'Archive' } とすると、Archive だけのファイルだけになって [Archive, NotContentIndexed] のファイルとかが対象外になるので、型で抽出する。
ま、同じことやるのならバッチのほうが明らかに早いけどね。http://hail2u.net/blog/software/avoid-firefox-bug-in-view_source-external-editor.html
Windowsにおけるコピー/移動とACL
By default, an object inherits permissions from its parent object, either at the time of creation or when it is copied or moved to its parent folder. The only exception to this rule occurs when you move an object to a different folder on the same volume. In this case, the original permissions are retained.
http://support.microsoft.com/kb/310316/en
コピーの場合は、コピー先の親フォルダの権限を継承し、元のアクセス権ではなくなる。同じボリュームのフォルダを移動する場合のみ、元のアクセス権を引き継ぐ。
なお、レジストリをいぢって、挙動を変更することもできる。
pscp でログを落として、zip で固めて保存する
$PSCP = "C:\tools\putty\pscp.exe -p" # -p は timestamp を保持 $7Z = "C:\Program Files\7-Zip\7z.exe" @( @{ "host" = "192.168.0.1" "user" = "user" "pass" = "password" "src" = "/var/log/httpd/*.1" "dst" = "d:\backup\web1" }, @{ "host" = "192.168.0.2" "user" = "user" "pass" = "password" "src" = "/var/log/httpd/*.1" "dst" = "d:\backup\web2" } ) | foreach { # 出力先 $dst = Join-Path $_.dst (Get-Date).ToString('yyyyMMdd') mkdir $dst # C:\tools\putty\pscp.exe -p -pw password user@192.168.0.1:/var/log/httpd/*.1 d:\web1\20100728 $cmd = "$PSCP -pw {0} {1}@{2}:{3} {4}" -f $_.pass, $_.user, $_.host, $_.src, $dst Invoke-Expression $cmd cd $dst ls | foreach { $orig = $_.FullName $zip = $_.FullName + '.zip' & $7Z a -tzip $zip $orig rm $orig } }
指定したフォルダ配下の log を zip で固める
$7z = 'C:\Program Files\7-Zip\7z.exe' $dir = 'f:\Exchange\LogFiles' Get-ChildItem $dir -Recurse | foreach { if ($_.Name -match '.+log$') { $orig = $_.FullName $zip = $_.FullName + '.zip' & $7z a -tzip $zip $orig rm $orig } }
utf8フラグ
Encode::decode
#!/usr/bin/perl # utf8 で保存しとくこと use strict; use warnings; use Data::Dumper; use Encode; my $input = "あ"; print Dumper($input); #=> $VAR1 = '縺・; バイト列 print Dumper( decode("utf8", $input) ); #=> $VAR1 = "\x{3042}"; 内部文字列(Unicode)
use utf8
#!/usr/bin/perl # utf8 で保存しとくこと use strict; use warnings; use Data::Dumper; use utf8; # XXX my $input = "あ"; # 内部文字列(Unicode) print Dumper($input); #=> $VAR1 = "\x{3042}";