사용자 도구

사이트 도구


windows:powershell

문서의 이전 판입니다!


Windows Powershell

기본 개인 profile 파일

  • $PROFILE 환경변수 값으로 프로필 파일 생성
    New-Item $profile -force -itemtype file
  • $Home\[My ]Documents\WindowsPowerShell\Profile.ps1

Powershell Core

sudo

Color ls

  • PowerShell Gallary 로 설치
  • $Home\[My ]Documents\WindowsPowerShell\Profile.ps1에 다음 추가하면 l, ls로 명령실행가능. 기존 명령은 dir로 가능
    # for colored ls
    Import-Module Get-ChildItemColor
    
    Set-Alias ls Get-ChildItemColor -option AllScope
    Set-Alias ll Get-ChildItemColorFormatWide -option AllScope

명령창 없이 명령 실행하기

powershell start-process '원하는명령(혹은 .bat)' -WindowStyle Hidden

Consoles

process 목록

ps *foo*
get-process | findstr foo
get-process | where ProcessName -like "*foo*"

환경변수 Environment Variable

#값 읽기
$Env:<variable-name>
$Env:PATH

# 값 지정
$Env:<variable-name> = "<new-value>"

$Env:path = $env:path + ";c:\temp"
Set-Item -Path Env:Path -Value ($Env:Path + ";C:\Temp")

기본명령

  • 디렉토리 삭제
    Remove-Item [dirname] -Force
  • Symoblic Link
    # 관리자 권한 필요
    New-Item -ItemType SymbolicLink -Name MySymLinkFile.txt -Target $pshome\profile.ps1
    New-Item -ItemType SymbolicLink -Path C:\Temp\MySymLinkFile.txt -Value $pshome\profile.ps1
  • grep 대체 Select-String
    # 문자열 filter
    "Hello","HELLO" | Select-String -Pattern "HELLO" -CaseSensitive
    # *.xml 파일들에서 문자열 탐색
    Select-String -Path "*.xml" -Pattern "the the"
    
    # 매칭이 안되는 부분 찾기
    Select-String -Path "process.txt" -Pattern "idle, svchost" -NotMatch
  • rename - Rename-Item
    Rename-Item -Path old_name -NewName new_name [-Force]

curl

  • Curl 을 사용하려면 cinst curl로 설치하고
  • $profile 파일에 PowerShell에 자체 curl alias를 지워야 실제 curl 명령이 실행된다.
    remove-item alias:curl

alias

# vi 를 vim.exe 실행하는 것으로 alias 걸기
set-alias -name vi -value vim.exe

참조

windows/powershell.1528952935.txt.gz · 마지막으로 수정됨: 2018/06/14 14:08 저자 kwon37xi