0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PowerShellでUnix/Linuxコマンドみたいなことがしたい!

Last updated at Posted at 2023-08-21

PowerShellでUnix/Linuxっぽいことがしたい人へ

head

cat log.txt | select -first 10 # head

tail

cat log.txt | select -last 10
cat -Tail 10 log.txt

less

cat log.txt | more

sort, uniq

cat hoge.txt | sort | Get-Unique

grep

Select-String foo.txt -Pattern 'hoge'

sed -i

(Get-Content hoge.txt) | foreach { $_ -replace "var","foo" } | Set-Content hoge.txt

rm -r -f

Remove-Item -Recurse -Force some_dir

tar tvf

zipを展開せずファイル一覧を取得

[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
foreach($sourceFile in (Get-ChildItem -filter '*.zip'))
{
    [IO.Compression.ZipFile]::OpenRead($sourceFile.FullName).Entries.FullName | %{ "$sourcefile`:$_" };
    $zip = [IO.Compression.ZipFile]::OpenRead($sourceFile); 
    $entries = $zip.Entries;
    $zip.Dispose()
}

こちらに他のコマンドなどかなり詳しく記載しています。発展内容もあり。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?