항상 윈도우와 리눅스를 오가며 작업을 하다 보니, 명령어가 자주 헷갈려서 실수하는 경우가 많았습니다.
아오
rm -rf빠직 💢 PowerShell에서는 진짜 적응 안되는고만...
그래서 이번 기회에 리눅스와 Windows PowerShell 둘다 비슷하게/공통적으로 사용할 수 있는 명령어들을 한데 모아 포스팅 형식으로 정리해보았습니다.

저처럼 다양한 운영체제를 넘나들며 작업하시는 분들께도 유용한 쉘 명령어 참고서가 되기를 바랍니다 😎
ls-a: 숨김 파일 포함-l: 상세 정보linux
$ ls # 파일 목록만 출력
$ ls -a # 숨김 파일 포함 출력
$ ls -l # 상세 정보 출력
$ ls -al # 숨김 파일 + 상세 정보 출력
windows
Get-ChildItem이라는 명령어의 별칭(Alias) 으로 ls가 매핑되어 있습니다.> Get-ChildItem
> ls
PowerShell에서는 옵션을 붙일 때 -l, -a 식으로 안 됩니다.매개변수(Parameter) 라는 방식을 사용합니다.ls -l 하면 되는 게 아니라, 다른 문법이 필요한 것입니다.> ls | Format-List
OR
> Get-ChildItem | Format-List
💡 참고로, 위와 같이 함수를 돌리면 너무 TMI가 많이 나옴...
- 추가로 함수를 써야하는데, 아래와 같이 함수를 입력하여, 리눅스 ls -l처럼 "이름, 사이즈, 수정시간" 정보만을 출력할 수 있습니다.
# 이름, 길이(사이즈), 마지막 수정시간만 보기
> Get-ChildItem | Select-Object Name, Length, LastWriteTime | Format-Table
OR
> ls | Select-Object Name, Length, LastWriteTime | Format-Table
mkdir-p: 중첩 디렉토리 생성linux
$ mkdir test
$ mkdir -p /home/test/test1/test2
windows
> mkdir test
> mkdir C:\Users\user\test1\test2
cd.: 현재 경로, ..: 상위 폴더, -: 이전 경로 복귀linux
$ cd test
$ cd ..
$ cd -
windows
> cd test
> cd ..
> cd -
cp-r: 디렉토리 복사linux
$ cp file1.txt file2.txt
$ cp -r test test_backup
windows
Copy-Item은 복사할 대상, 대상 경로를 별도 지정하는 구조입니다.-Destination을 명시해야 합니다.> Copy-Item file1.txt -Destination file2.txt
> Copy-Item test -Recurse -Destination test_backup
mv-v: verbose 출력linux
$ mv a.txt b.txt
$ mv -v a.txt folder/b.txt
windows
> Move-Item a.txt b.txt
> Move-Item -Verbose a.txt b.txt
rm-r: 폴더, -f: 강제linux
$ rm file1.txt file2.txt
$ rm -rf folder/
windows
> Remove-Item file1.txt,file2.txt
> Remove-Item folder -Recurse -Force
pwdlinux
$ pwd
windows
> pwd
catlinux
$ cat file.txt
$ cat > new.txt << EOF
Hello
World
EOF
windows
> Get-Content file.txt
> "Hello`nWorld" | Out-File new.txt
단, -Encoding 옵션을 주지 않으면 기본 UTF-16 LE 인코딩이 될 수 있습니다.
-Encoding utf8을 옵션 추가를 권장합니다.> "Hello`nWorld" | Out-File new.txt -Encoding utf8
touchlinux
$ touch file.txt
windows
> New-Item file.txt -ItemType File
which windowslinux
$ which mv
windows
> Get-Command notepad | Select-Object -ExpandProperty Definition
> gcm notepad
find-type f: 파일, -type d: 디렉토리linux
$ find /home/user/ -type f -name "*.txt"
$ find . -name "*.log" -exec rm {} \;
windows
> Get-ChildItem -Recurse -Filter *.txt
※ PowerShell에서 -Filter는 매우 빠른 검색을 지원합니다.
greplinux
$ ls | grep log
$ find . -name "*.txt" | grep sample
windows
> ls | Select-String log
df / du / lsblklinux
$ df -h
$ du -h --total | grep total
$ lsblk
windows
> Get-PSDrive
Get-PSDrive는 디스크 볼륨 정보를 가져오긴 하지만, df -h처럼 사용/여유 공간을 명확히 보여주지는 않습니다.아래 함수는 Windows 10 이상에서 디스크 용량 및 사용량 정보를 더 명확히 표시합니다.
> Get-Volume
difflinux
$ diff file1.txt file2.txt
windows
> Compare-Object (Get-Content file1.txt) (Get-Content file2.txt)
chmod / chownlinux
$ chmod 600 file.txt
$ chown user:group file.txt
$ chmod -R 755 folder/
$ chown -R user:group folder/
windows
# windowss는 icacls 또는 Set-Acl 명령어 사용
> icacls file.txt /grant user:F
jobs / pkilllinux
$ jobs
$ pkill -9 vim
windows
> Get-Job
> Stop-Process -Name vim
🔵 PowerShell의
Get-Job은 PowerShell에서 실행한 백그라운드 Job만 보여줍니다. Stop-Process는 실제로 프로세스를 죽이는 거라 약간 다른 개념입니다.
pkill(kill) = Windows Stop-Processjobs = Windows Get-Job※ 프로세스 이름으로 죽일 때는 -Name, PID로 죽일 때는 -Id를 사용합니다.
pinglinux
$ ping google.com -a
windows
> ping google.com -a
※ -a 옵션은 Windows에서는 "IP를 호스트 이름으로 바꿔서 표시" 의미입니다.
wgetlinux
$ wget http://example.com/file.zip
windows
> Invoke-WebRequest http://example.com/file.zip -OutFile file.zip
※ Invoke-WebRequest는 iwr 별칭으로도 사용 가능합니다.
top / htophtop은 설치 필요)linux
$ top
$ htop
windows
> Get-Process
※ Get-Process | Out-GridView를 추가하면 GUI 기반으로도 볼 수 있습니다.
clear: 화면 정리 (단축키 Ctrl + L)Ctrl + C: 현재 작업 강제 종료Ctrl + Z: 작업 일시 중지fg: 중지된 작업 재개Tab: 자동완성↑: 이전 명령어 반복※ Windows Terminal에서도 Ctrl+L, Ctrl+C, Ctrl+Z 잘 작동합니다.
aliaslinux
$ alias ll='ls -alF'
$ alias gs='git status'
windows
> Set-Alias ll Get-ChildItem
※ PowerShell은 Alias 등록 시 세션마다 초기화되기 때문에, 영구 저장은 $PROFILE 수정이 필요합니다.
xargslinux
$ find . -name "*.log" | xargs rm
→ find로 찾은 파일 목록을 rm에 인자로 한꺼번에 넘겨서 빠르게 삭제.
windows
PowerShell은 기본적으로 "파이프라인 객체(Object)" 를 사용하기 때문에,
그래서 xargs처럼 한 번에 여러 개를 한꺼번에 처리하지 못하지만, 하나씩은 처리할 수 있습니다.
> Get-Content files.txt | ForEach-Object { Remove-Item $_ }
Get-Content → 파일 목록을 한 줄씩 읽어오고ForEach-Object → 한 줄씩 받아서 Remove-Item 실행PowerShell 7 이상에서는
ForEach-Object -Parallel사용 가능
Get-Content files.txt | ForEach-Object -Parallel { Remove-Item $_ }
teelinux
$ echo "log message" | tee log.txt
windows
> "log message" | Tee-Object -FilePath log.txt
head / taillinux
$ head -n 10 file.txt
$ tail -n 20 file.txt
$ tail -f /var/log/syslog
windows
> Get-Content file.txt -TotalCount 10
> Get-Content file.txt | Select-Object -Last 20
historylinux
$ history
$ history | grep ssh
$ !45
$ !git
windows
> Get-History
이상으로 자주 쓰는 터미널 함수 25선 정리를 마칩니다!!
읽어주셔서 감사합니다 💻
생각보다 파워쉘이랑 공유하는 커멘드가 꽤 많네요, 진짜 적응 저도 안되었었는데.. 글 잘읽었습니다! 정리 잘해주셔서 감사합니다!
다름이 아니라, 오탈자가 있는 것 같아요! "이번 기회에 리눅스와 windowss PowerShell 양쪽에서" -> windowss 에 s 가 두개 붙었네요 ㅎㅎ