๐Ÿ’ป Command Line์„ ์‰ฝ๊ฒŒ! Alias ์ปค๋งจ๋“œ!

ALL TERMINAL LINUX WINDOWS Posted by Sunio on January 22, 2021 · 3 mins read

๊ฒŒ์œผ๋ฅธ ๊ฐœ๋ฐœ์ž์˜ ์‹ค์ „ ์••์ถ• ๊ทผ์œก ๊ธฐ๋ฅด๊ธฐ (thx zeroistfilm)

Tools

  • Ubuntu 18.04, Windows / bash, powershell, alias command, CLI

1. Prologue & Issue


์ •๊ธ€์˜ ๊ณฐ ๊ฐ™์€ ๋™๋ฃŒ์—๊ฒŒ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ… ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์•˜๋‹ค.

"์ด๊ฑฐ ๋ช…๋ น์–ด ๋ณ„๋ช… ์ง€์–ด์ฃผ๋ฉด ์‰ฝ๊ฒŒ ํ•˜๊ฒ ๋Š”๋ฐ์š”?"๐Ÿง

5๋ถ„ ๋’ค์— ๋š๋”ฑ ํ•ด๊ฒฐํ•˜๋”๋‹ˆ, ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด aws์˜ instance-id ์ฐพ์•„๋ณผ ํ•„์š”๋„ ์—†๊ณ  ์ปค๋งจ๋“œ ์ž์ฒด๋„ ์งง์•„์ ธ์„œ ๋„ˆ๋ฌด ๊ฐ„ํŽธํ•˜๋‹ค๋Š” ์‚ฌ์‹ค์„ ๋ชธ์†Œ ์ฆ๋ช…ํ•ด์ฃผ์—ˆ๋‹ค.
๊ทธ๋ ‡๋‹ค. ๋‚˜๋Š” ๋ถˆ๊ณผ 6์ผ ์ „์— ๋ฐฐ์šด ์ปค๋งจ๋“œ๋„ ์‹ค์ „์— ์•ˆ์“ฐ๊ณ  ์žˆ๋˜ ๋ฉ์ฒญํ•œ ๊ฐœ๋ฐœ์ž์˜€๋‹ค.

2. Alias Command


์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ ์•„์ฃผ ๊ฐ„๋‹จํ•œ Command alias ๋˜์‹œ๊ฒ ๋‹ค.
alias๋Š” ์–ด๋– ํ•œ ๋ช…๋ น์–ด์— ๋ณ„์นญ(๋ณ„๋ช…)์„ ์ง€์–ด์ฃผ๋Š” ๋ฌด์–ธ๊ฐ€(ํ”„๋กœ๊ทธ๋žจ ์ธ๊ฐ€?)์ด๋‹ค.
ํฌ์ŠคํŒ…(aws ec2 cli ์ ์šฉํ•˜๋Š” ๋ญ ๊ทธ๋Ÿฐ ์ด์•ผ๊ธฐ) ์— ์“ฐ์—ฌ์ง„ ๋‚ด์šฉ์„ ํ† ๋Œ€๋กœ ์ง€๋ฆ„๊ธธ์„ ๋Œ์•„๊ฐ€๋Š” ๋ถˆ์ƒ์‚ฌ๋ฅผ ๋ง‰์•„๋ณด์ž!

3. On Command Line


# powershell
$profile # bashrc์™€ equivalantํ•œ powershell์˜ ๋ฌด์–ธ๊ฐ€์˜ ์œ„์น˜๋ฅผ ์ฐพ๋Š”๋‹ค.
function awsbegin aws ec2 start-instances --instance-ids {'id'}
function awsend aws ec2 stop-instances --instance-ids {'id'}
Set-Alias awsstart awsbegin
Set-Alias awsstop awsend

Windows Powershell์—์„œ๋Š” bashrc๋ฅผ ๋Œ€์‹ ํ•˜๋Š” profile ํŒŒ์ผ์„ ์ฐพ์•„ ์ˆ˜์ •ํ•ด์•ผํ•œ๋‹ค.
profile์˜ ๋‚ด์šฉ์€ powershell์ด init๋˜๋Š” ์ˆœ๊ฐ„์— ๋ช…๋ น์–ด๋ฅผ ๋ชจ๋‘ ๋™์ž‘ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ƒ๊ฐ๋œ๋‹ค.
์ด๋ฅผ ํ†ตํ•ด, ๋ช…๋ น์–ด๋ฅผ ๋งค๋ฒˆ ์ž…๋ ฅํ•˜์—ฌ Alias๋ฅผ ๋“ฑ๋กํ•ด์•ผํ•˜๋Š” ์ˆ˜๊ณ ๋ฅผ ๋œ๊ฒŒ ๋˜์—ˆ๋‹ค.

# bash shell
vim ~/.bashrc
alias awsstart=โ€˜aws ec2 start-instances --instance-ids {'id'}โ€™ 
alias awsstop=โ€˜aws ec2 stop-instances --instance-ids {'id' }'

์œ„๋Š” AWS linux bash์—์„œ Alias๋ฅผ ๋“ฑ๋กํ•˜๋Š” ๊ณผ์ •์ด๋‹ค.

4. Result


  • awss function์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

  • awsstart ๋ผ๋Š” ๋ณ„๋ช…์— awss function์„ ์ ์šฉํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

  • Get-Alias command๋กœ ๋ช…๋ น์–ด ๋“ฑ๋ก์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • awsstart๋ฅผ ์‹คํ–‰ํ•ด๋ด…๋‹ˆ๋‹ค.

  • $profile์„ ํ†ตํ•ด ๋ช…๋ น์–ด๊ฐ€ ๋งค๋ฒˆ powershell์„ ๋ถ€ํŒ…ํ•  ๋•Œ, ์ ์šฉ๋˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. (save)

  • AWS EC2 Ubuntu shell ์ƒ์—์„œ awsstop ๋ช…๋ น์„ ์‹คํ–‰ํ•œ ๋ชจ์Šต์ด๋‹ค.

5. Epilogue


๊ธฐ์ˆ ์€ ์จ๋จน์–ด์•ผ ์˜๋ฏธ๊ฐ€ ์žˆ๋Š”๊ฑฐ์•ผ.

6. Reference


Thank For ์˜๋™zeroist๐Ÿคฉ

powershell์—์„œ .bashrc๋ฅผ? :: Does Powershell have any sort of .bashrc equivalent?
windows powershell alias commands :: powershell alias
powershell :: Creating aliases in PowerShell for git commands?


โ€ข 0 Comments