๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ–‹๏ธ Tools

[Git] Unix ๋ช…๋ น์–ด VS PowerShell

by OR15A 2023. 11. 20.
 
* ์œˆ๋„์šฐ๋ฉด PowerShell ์ตํžˆ๊ธฐ
* ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ๋ช…๋ น์–ด ๋น„๊ตํ•˜๋ฉฐ ์ตํžˆ๊ธฐ๊ธฐ

 


  • ์œ ๋‹‰์Šค์‰˜์„ ์ตํžˆ๋ฉด ๋ฆฌ๋ˆ…์Šค, ๋งฅ, ์œˆ๋„์šฐ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•จ
  • ๋‚˜์˜ ํ™˜๊ฒฝ(์œˆ๋„์šฐ)์—์„œ WSL์ด ์žˆ์œผ๋‚˜ ๋ฒ„์ „ ๋“ฑ ๊ด€๋ฆฌ ๊นŒ๋‹ค๋กœ์›€ → PowerShell์„ ์‚ฌ์šฉํ•˜์ž
  • PowerShell : CMD๋ณด๋‹ค ๊ฐ•๋ ฅํ•˜๋ฉฐ ์šด์˜์ฒด์ œ์˜ ๋ชจ๋“  ์„œ๋น„์Šค์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ถ”์ฒœ
  • ์ฐจ์ด์  : ์œ ๋‹‰์Šค์‰˜์€ TEXT๋กœ ์ด๋ฃจ์–ด์ง VS ํŒŒ์›Œ์‰˜์€ ๊ฐ์ฒด์œ„์ฃผ๋กœ ์ด๋ฃจ์–ด์ง
  • ๋‘˜ ๋‹ค ์„ฑ๊ฒฉ์ด ๋‹ค๋ฅด์ง€๋งŒ ํŒŒ์›Œ์‰˜์—์„œ Aliases๋ฅผ ์ œ๊ณตํ•ด์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•จ
  • PowerShell ๋‹ค์šด๋กœ๋“œ ๋งํฌ (๋‚˜๋Š” Window 64)

https://github.com/PowerShell/PowerShell/releases/tag/v7.3.7

 

 

PowerShell VS Unix ๋ช…๋ น์–ด

 
PowerShell
(aliases = ์‹ค์ œ๋ช…๋ น์–ด)
Unix
์„ค๋ช…
man = Get-Help
man
๋งค๋‰ด์–ผ man ๋‹จ์–ด ๋กœ ๊ฒ€์ƒ‰ํ•˜๋ฉด ํ•ด๋‹น ๋‹จ์–ด์— ๋Œ€ํ•œ ์„ค๋ช…์„ ๋ณผ ์ˆ˜ ์žˆ์Œ ex) man man / man clear
q
 
man ๋ชจ๋“œ์—์„œ ๋‚˜๊ฐˆ ์ˆ˜ ์žˆ์Œ
clear
clear
ํ„ฐ๋ฏธ๋„์˜ ํ…์ŠคํŠธ๋ฅผ ์ง€์›Œ์คŒ
 
 
 
pwd = Get-Location
pwd (Print Working Directory)
๋‚ด๊ฐ€ ํ˜„์žฌ ์žˆ๋Š” ๊ณณ์˜ ๊ฒฝ๋กœ
ls -name
ls (List)
ํ˜„์žฌ๊ฒฝ๋กœ์— ์žˆ๋Š” ํŒŒ์ผ ๋ชฉ๋ก
ls ํŠน์ •ํด๋”์ด๋ฆ„
ls ํŠน์ •ํด๋”์ด๋ฆ„
ํŠน์ •ํด๋” ์•ˆ์— ์žˆ๋Š” ํŒŒ์ผ ๋ชฉ๋ก
ls = Get-ChildItem
ls -l (Long Format Option)
๋” ์ž์„ธํ•œ ํŒŒ์ผ๋ชฉ๋ก
ls -force
ls -a (All)
UI์ƒ์— ๋ณด์ด์ง€ ์•Š๋Š” ์ˆจ๊ฒจ์ง„ ํŒŒ์ผ ๋ชฉ๋ก๋„ ๋ณผ ์ˆ˜ ์žˆ์Œ
 
ls -la (Long + All)
๋‘๊ฐ€์ง€ ์˜ต์…˜ ํ•œ ๋ฒˆ์— ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•จ
 
 
 
explorer
open .
ํ„ฐ๋ฏธ๋„ ์ƒ์˜ ํ˜„์žฌ ๊ฒฝ๋กœ๋ฅผ ํŒŒ์ผํƒ์ƒ‰๊ธฐ๋กœ ์—ด๊ณ  ์‹ถ์„ ๋•Œ
cd = Set-Location
cd ํŒŒ์ผ์ด๋ฆ„ (Change Directory)
ํ•ด๋‹นํŒŒ์ผ๋กœ ์ด๋™
cd .
cd .
ํ˜„์žฌ๊ฒฝ๋กœ๋กœ ์ด๋™
cd . .
cd . .
ํ˜„์žฌ๊ฒฝ๋กœ์˜ ์ƒ์œ„๊ฒฝ๋กœ๋กœ ์ด๋™
cd ~
cd ~
ํ˜„์žฌ ์‚ฌ์šฉ์ž์˜ ์ตœ์ƒ์œ„ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™
cd -
cd -
๋ฐฉ๊ธˆ ์ด๋™ ๋ฐ”๋กœ ์ „์˜ ๊ฒฝ๋กœ๋กœ ๋˜๋Œ์•„๊ฐ€๊ธฐ
 
 
 
get-childItem ์˜ต์…˜ (์•„์‰ฝ๊ฒŒ๋„ aliases ์—†์Œ)
find ์˜ต์…˜
๊ฒ€์ƒ‰ํ•˜๊ธฐ, ์ฐพ๊ธฐ
ex) get-childitem -File -Filter ”*.txt” -Recurse (Recurse: ํ•˜์œ„์•ˆ์˜ ํ•˜์œ„์•ˆ์˜… ์žฌ๊ท€์ )
ex) find . -type file -name “*.txt”
ex) ํ˜„์žฌํŒŒ์ผ ํ•˜์œ„์—์„œ / ํƒ€์ž…: ๋ชจ๋“ ํŒŒ์ผ / ์ด๋ฆ„: .txt๋กœ ๋๋‚˜๋Š” ๊ฒƒ ์ฐพ๊ธฐ
 
 
 
get-command = gcm
which
์‹คํ–‰ํ•˜๊ณ ์ž ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์ด ์–ด๋””์— ์„ค์น˜/์„ค์ •๋˜์–ด์žˆ๋Š”์ง€ ๊ฒฝ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Œ
ex) get-command ํ”„๋กœ๊ทธ๋žจ
ex) which ํ”„๋กœ๊ทธ๋žจ
 
 
 
 
๐Ÿ“๐Ÿ“๐Ÿ“๐Ÿ“ ํŒŒ์ผ ์ƒ์„ฑ ๋ฐ
๐Ÿ“๐Ÿ“๐Ÿ“๐Ÿ“ ๊ด€๋ฆฌํ•˜๊ธฐ
๐Ÿ“๐Ÿ“๐Ÿ“๐Ÿ“
new-item ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž
touch ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž
(ํŒŒ์ผ ์žˆ์œผ๋ฉด) → ์—…๋ฐ์ดํŠธ (ํŒŒ์ผ ์—†์œผ๋ฉด) → ์ƒˆ๋กœ ์ƒ์„ฑ
cat ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž
cat ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž
ํŒŒ์ผ์˜ ์ปจํ…์ธ  ํ™•์ธ
echo “๋ฌธ์ž์—ด”
echo “๋ฌธ์ž์—ด”
ํ„ฐ๋ฏธ๋„์ฐฝ์— ์ถœ๋ ฅ
echo “๋ฌธ์ž์—ด” > ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž
echo “๋ฌธ์ž์—ด” > ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž
(ํŒŒ์ผ ์—†์œผ๋ฉด) → ํ•ด๋‹น ๋ฌธ์ž์—ด์ด ํฌํ•จ๋œ ํŒŒ์ผ ์ƒ์„ฑ (ํŒŒ์ผ ์žˆ์œผ๋ฉด) → ํ•ด๋‹น ๋ฌธ์ž์—ด๋กœ ์ปจํ…์ธ  ๋ฎ์–ด์“ฐ๊ธฐ
 
 
 
mkdi r ์›ํ•˜๋Š”ํด๋”์ด๋ฆ„
mkdir ์›ํ•˜๋Š”ํด๋”์ด๋ฆ„ (make directory)
ํ˜„์žฌ ๊ฒฝ๋กœ์— ์ƒˆ ๋””๋ ‰ํ† ๋ฆฌ ๋งŒ๋“ค๊ธฐ
 
ex) mkdir -p dir4/subdir1/subdir2
-p ์˜ต์…˜์„ ์ด์šฉํ•ด์„œ ํ•œ๋ฒˆ์— ์—ฌ๋Ÿฌ ๋””๋ ‰ํ† ๋ฆฌ ๋งŒ๋“ค๊ธฐ(์ค‘๊ฐ„ํด๋”์ž๋™์ƒ์„ฑ)
 
 
 
cp ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž ์›ํ•˜๋Š”๊ฒฝ๋กœ/ =Copy-Item
cp ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž ์›ํ•˜๋Š”๊ฒฝ๋กœ (copy)
์›ํ•˜๋Š” ๊ฒฝ๋กœ๋กœ ํŒŒ์ผ ๋ณต์‚ฌ
mv ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž ์›ํ•˜๋Š”๊ฒฝ๋กœ/ (move)
mv ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž ์›ํ•˜๋Š”๊ฒฝ๋กœ (move)
์›ํ•˜๋Š” ๊ฒฝ๋กœ๋กœ ํŒŒ์ผ ์ด๋™
rm ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž (remove)
rm ํŒŒ์ผ์ด๋ฆ„.ํ™•์žฅ์ž (remove)
ํ•ด๋‹น ํŒŒ์ผ ์‚ญ์ œ
rm ํด๋”์ด๋ฆ„ -Recurse (remove)
rm -r ํด๋”์ด๋ฆ„ (remove)
ํ•ด๋‹น ํด๋” ์‚ญ์ œ
 
 
 
Select-String
grep (Grobal regular expresstion print)
ํ‚ค์›Œ๋“œ ๊ฒ€์ƒ‰
ex) Select-String *.ํ™•์žฅ์ž -pattern “ํ‚ค์›Œ๋“œ”
ex) grep “๊ฒ€์ƒ‰ํ‚ค์›Œ๋“œ” *.ํ™•์žฅ์ž
 
 
grep -n “๊ฒ€์ƒ‰ํ‚ค์›Œ๋“œ” *.ํ™•์žฅ์ž
-n์˜ต์…˜์ฃผ๋ฉด ๋ช‡๋ฒˆ์งธ ์ค„์— ์žˆ๋Š”์ง€๋„ ํ™•์ธ๊ฐ€๋Šฅ
 
grep -ni “๊ฒ€์ƒ‰ํ‚ค์›Œ๋“œ” *.ํ™•์žฅ์ž
-ni ์˜ต์…˜์ฃผ๋ฉด ๋ช‡๋ฒˆ์งธ ์ค„์— ์žˆ๋Š”์ง€, ๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„ ์—†์ด ๊ฐ€๋Šฅํ•จ
ex) ๊ฐ™์€ ๊ธฐ๋Šฅ ์—†์–ด์„œ ์ง์ ‘ ๋ช…์‹œํ•ด์ค˜์•ผํ•จ select-string *, */* -patter ”ํ‚ค์›Œ๋“œ” (* : ํ˜„์žฌ๊ฒฝ๋กœ */* : ํ˜„์žฌ๊ฒฝ๋กœ ์•ˆ์˜ ๋ชจ๋“ ํด๋”์˜ ํ•˜๋‚˜ ๋” ๋‚ฎ์€ ๋‹จ๊ณ„)
grep -nir “๊ฒ€์ƒ‰ํ‚ค์›Œ๋“œ” . (recursive์˜ต์…˜)
ํ˜„์žฌ๊ฒฝ๋กœ์™€, ๊ทธ ์„œ๋ธŒํด๋”์— ํ•œํ•ด์„œ ์ „์ฒด๊ฒ€์ƒ‰
Select-String -Pattern "ํ‚ค์›Œ๋“œ" -CaseSensitive $false
 
๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„ ์—†์ด ๊ฒ€์ƒ‰ํ•˜๊ธฐ (๊ฒ€์ƒ‰๋ฒ”์œ„ ์•ˆ ์ •ํ•ด์ฃผ๋ฉด ์ง€๊ธˆ ํด๋”๋‚ด์—์„œ๋งŒ)
 
 
 
 
 
 
 
 
 

 

ํ™˜๊ฒฝ๋ณ€์ˆ˜

  • ๋‚ด ์ปดํ“จํ„ฐ์—์„œ ํŠน์ •ํ•œ ํ‚ค์›Œ๋“œ ์–ด๋– ํ•œ ๊ฒฝ๋กœ๋ฅผ ๋‚˜ํƒ€๋‚ด๊ฑฐ๋‚˜ ์ €์žฅํ•˜๋Š” ๊ฒƒ
 
PowerShell
Unix
์„ค๋ช…
$env:ํ™˜๊ฒฝ๋ณ€์ˆ˜์ด๋ฆ„ = “ํด๋”์ด๋ฆ„”
export ํ™˜๊ฒฝ๋ณ€์ˆ˜์ด๋ฆ„=”ํด๋”์ด๋ฆ„”
ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ •ํ•˜๊ธฐ
ex) $env:MY_DIR = “dir1”
ex) export =”dir1”
dir1์ฃผ์†Œ๋ฅผ ๊ฐ€์ง„ ํ™˜๊ฒฝ๋ณ€์ˆ˜ MY_DIR ์ƒ์„ฑ
ex) $env:MY_DIR
ex) cd $MY_DIR
dir1ํด๋”๋กœ ๋ฐ”๋กœ ์ด๋™ ๊ฐ€๋Šฅํ•จ
$env:MY_DIR = “”
unset ํ™˜๊ฒฝ๋ณ€์ˆ˜์ด๋ฆ„
ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์‚ญ์ œํ•˜๊ธฐ
ls env:
env
๋ชจ๋“  ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋ณด๊ธฐ

 

Vim ์—๋””ํ„ฐ ์ข…๋ฃŒํ•˜๊ธฐ

i : ์ˆ˜์ •ํ•˜๊ธฐ

ESC ๋ˆ„๋ฅด๊ณ  :wq (write changes์ž‘์„ฑํ•œ๊ฑฐ ์ €์žฅํ•ด์ค˜ quit ์ด์ œ ๊บผ๋ผ) :wq ๋Š” ์ €์žฅ ์•ˆํ•˜๊ณ  ๊ทธ๋ƒฅ ๋„๊ธฐ