Skip to content
/ Tips Public

๐Ÿ”๋„์ ๋„์  ์œ ์šฉํ•œ ํŒ๋“ค

Notifications You must be signed in to change notification settings

hn04147/Tips

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 

Repository files navigation

Tips

๐Ÿ”๋„์ ๋„์  ์œ ์šฉํ•œ ํŒ๋“ค


  1. ๋งฅ์—์„œ ๋ถ„ํ•  ์••์ถ• ํ‘ธ๋Š” ๋ฐฉ๋ฒ•
  2. Mac ํ„ฐ๋ฏธ๋„ iterm2 ์ปค์Šคํ…€
  3. Ssh๋กœ remote server ์ ‘์† ์‹œ terminal ์ƒ‰๊น” ์ž…ํžˆ๊ธฐ
  4. Ssh ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ์ ‘์† ์„ค์ •ํ•˜๊ธฐ
  5. Ssh๋กœ remote server ์ ‘์† ์‹œ alias ๊ธฐ๋ณธ์œผ๋กœ ์„ค์ • ํ•˜๊ธฐ
  6. Ssh๋กœ remote server ์ ‘์† ์‹œ bashrc ๊ธฐ๋ณธ์œผ๋กœ ์‹คํ–‰ํ•˜๊ธฐ
  7. ํ•˜์œ„ ํด๋”์•ˆ์— ์žˆ๋Š” ํŒŒ์ผ ๊ฐœ์ˆ˜ ์ถœ๋ ฅ
  8. Ssh ์„œ๋ฒ„ ํŒŒ์ผ ์›๊ฒฉ ์ „์†กํ•˜๊ธฐ
  9. ํŒŒ์ด์ฌ ๋ฆฌ์ŠคํŠธ ํšŒ์ „ํ•˜๊ธฐ
  10. GPU์— ๋ฉ”๋ชจ๋ฆฌ๋Š” ํ• ๋‹น๋˜์–ด ์žˆ๋Š”๋ฐ nvidia-smi์—๋Š” ์•ˆ๋‚˜์˜ฌ ๋•Œ

1. ๋งฅ์—์„œ ๋ถ„ํ•  ์••์ถ• ํ‘ธ๋Š” ๋ฐฉ๋ฒ•

  1. zip -FF ๋ถ„ํ• ์••์ถ•๋œ์›๋ณธํŒŒ์ผ๋ช….zip --out ํ•œ๊ฐœ๋กœ์••์ถ•๋ ํŒŒ์ผ๋ช….zip
  2. unzip -qt ํ•œ๊ฐœ๋กœ์••์ถ•๋ ํŒŒ์ผ๋ช….zip

EX) ํŒŒ์ผ๋ช…์ด data.zip, data.z01, data.z02 ์ด๋ ‡๊ฒŒ ๋˜์–ด์žˆ์„ ๋•Œ

  1. zip -FF data.zip --out data_concat.zip ์œผ๋กœ ์••์ถ• ํŒŒ์ผ ํ•ฉ์น˜๊ธฐ
  2. unzip -qt data_concat.zip ์œผ๋กœ ํ•ฉ์นœ ํŒŒ์ผ ์••์ถ• ํ’€๊ธฐ

2. Mac ํ„ฐ๋ฏธ๋„ iterm2 ์ปค์Šคํ…€

oh-my-zsh ์‚ญ์ œ

์ด์ „์— ํ„ฐ๋ฏธ๋„์„ ์ปค์Šคํ…€ ํ•œ ์ ์ด ์žˆ์–ด Oh My Zsh๊ฐ€ ์ด๋ฏธ ๊น”๋ ค์žˆ๋Š” ์ƒํ™ฉ์ด๋ผ๋ฉด ์•„๋ž˜ ์ฝ”๋“œ๋กœ ํ„ฐ๋ฏธ๋„ ์ดˆ๊ธฐํ™”๋ฅผ ์‹œ์ผœ์ค€๋‹ค.

rm -rf ~/.oh-my-zsh
rm ~/.zshrc
cp ~/.zshrc.pre-oh-my-szh ~/.zshrc
source ~/.zshrc

์•„๋‚˜์ฝ˜๋‹ค zsh์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

.zshrc์— ๋“ค์–ด๊ฐ€์„œ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ • ์•„๋ž˜ ์ฝ”๋“œ๋“ค์„ ์ œ์ผ ๋ฐ‘์— ์ถ”๊ฐ€ํ•ด์ฃผ์ž

vi ~/.zshrc      // .zshrc ํŽธ์ง‘
                 // ์•„๋ž˜ ์ฝ”๋“œ ์ถ”๊ฐ€ 


export PATH=$HOME/bin:/usr/local/bin:/anaconda3:/anaconda3/bin:$PATH

# >>> conda initialize >>>
 # !! Contents within this block are managed by 'conda init' !!
 __conda_setup="$('/Users/Sangjin/opt/anaconda3/bin/conda' 'shell.zsh' 'hook'     2> /dev/null)"
 if [ $? -eq 0 ]; then
     eval "$__conda_setup"
 else
     if [ -f "/Users/Sangjin/opt/anaconda3/etc/profile.d/conda.sh" ]; then
         . "/Users/Sangjin/opt/anaconda3/etc/profile.d/conda.sh"
     else
         export PATH="/Users/Sangjin/opt/anaconda3/bin:$PATH"
     fi
 fi
 unset __conda_setup
 # <<< conda initialize <<<

3. Ssh๋กœ remote server ์ ‘์† ์‹œ terminal ์ƒ‰๊น” ์ž…ํžˆ๊ธฐ

  • ~/.bashrc ์— ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
# >>> enable color support of terminal directory >>>
export PS1="\[\e]0;\u@\h \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w #\[\033[00m\] "
# <<< enable color support of terminal directory <<<


# >>> enable color support of ls and also add handy aliases >>>
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi
# <<< enable color support of ls and also add handy aliases <<<
  • ์ดํ›„ source ~/.bashrc ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ์ ์šฉ์‹œ์ผœ์ค€๋‹ค.

4. Ssh ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ์ ‘์† ์„ค์ •ํ•˜๊ธฐ

  1. root ๊ถŒํ•œ์œผ๋กœ passwd root ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ Enter new UNIX passwd ์™€ Retype new UNIX passwd ์— ๋™์ผํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.
  2. root ๊ถŒํ•œ์œผ๋กœ vim /etc/ssh/sshd_config ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ /etc/ssh/sshd_config ํŒŒ์ผ์„ ์—ด์–ด์„œ PasswordAuthentication yes ๋กœ ๋ณ€๊ฒฝ์„ ํ•ด์ค€๋‹ค.
  3. ๋งˆ์ง€๋ง‰์œผ๋กœ root ๊ถŒํ•œ์œผ๋กœ service ssh restart๋ฅผ ํ•˜์—ฌ ssh ์žฌ๋ถ€ํŒ…์„ ์‹œ์ผœ์ค€๋‹ค.
  4. ์ดํ›„ ssh root@<your ip> -p <your port>๋กœ ์ ‘์†์„ ํ•˜๋ฉด ์„ค์ •ํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋‹ค.

5. Ssh๋กœ remote server ์ ‘์† ์‹œ alias ๊ธฐ๋ณธ์œผ๋กœ ์„ค์ • ํ•˜๊ธฐ

  • ~/.bash_aliases ์— ```alias`๋ฅผ ์ ์šฉํ•  ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ค€๋‹ค.
alias ll='ls -al'
  • ~/.bashrc ์— ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
# >>> enable '.bash_aliases' >>>
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
# <<< enable '.bash_aliases' <<<<

6. Ssh๋กœ remote server ์ ‘์† ์‹œ bashrc ๊ธฐ๋ณธ์œผ๋กœ ์‹คํ–‰ํ•˜๊ธฐ

  • ~/.bash_profile ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ณ  ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
if [ -f ~/.bashrc ]; then 
  . ~/.bashrc 
cd ~
fi

7. ํ•˜์œ„ ํด๋”์•ˆ์— ์žˆ๋Š” ํŒŒ์ผ ๊ฐœ์ˆ˜ ์ถœ๋ ฅ

for x in `ls` ; do echo $x: `find $x -type f | wc -l`; done

์ถ”๊ฐ€๋กœ ~/.bash_aliases ์— alias fn='for x in `ls` ; do echo $x: `find $x -type f | wc -l`; done' ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ํŽธํ•˜๊ฒŒ fn ๋ช…๋ น์–ด๋กœ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.


8. Ssh ์„œ๋ฒ„ ํŒŒ์ผ ์›๊ฒฉ ์ „์†กํ•˜๊ธฐ

  • Local์—์„œ ssh๋กœ ํŒŒ์ผ ์ „์†ก
scp -r {local ์„œ๋ฒ„ ์ฃผ์†Œ} {ssh ์„œ๋ฒ„ ์ฃผ์†Œ}
ex) scp -r [email protected]:/opt/ml/code /Users/Desktop/
  • Ssh์—์„œ local๋กœ ํŒŒ์ผ ์ „์†ก
scp -r {ssh ์„œ๋ฒ„ ์ฃผ์†Œ} {local ์„œ๋ฒ„ ์ฃผ์†Œ}
ex) scp -r /Users/Download/a.txt [email protected]:/opt/ml/code

9. ํŒŒ์ด์ฌ ๋ฆฌ์ŠคํŠธ ํšŒ์ „ํ•˜๊ธฐ

k = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]

# ์‹œ๊ณ„ ๋ฐฉํ–ฅ ํšŒ์ „
li = [list(k[::-1]) for k in zip(*k)]
# zip๋ฅผ ์จ์„œ ๊ฐ ์ธ๋ฑ์Šค์˜ ๋ชจ๋“  element๋ฅผ ํ•œ iterator์— ๋„ฃ๊ณ  asterisk๋ฅผ ์ด์šฉํ•˜์—ฌ ํ’€์–ด์„œ ํšŒ์ „ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ตฌํ˜„
# ex) k = [[1, 2, 3],     ->   ์›ํ•˜๋Š” ์ถœ๋ ฅ form: [[7, 4, 1],
#          [4, 5, 6],                          [8, 5, 2],
#          [7, 8, 9]]                          [9, 6, 3]]
# zip(*k) = [[1, 4, 7],
#            [2, 5, 8],
#            [3, 6, 9]]
print(li)

# ๋ฐ˜ ์‹œ๊ณ„ ๋ฐฉํ–ฅ ํšŒ์ „
li = [list(k) for k in reversed(tuple(zip(*k)))]
# ์‹œ๊ณ„ ๋ฐฉํ–ฅ๊ณผ ๋™์ผํ•œ ๋ฐฉ์‹์ด์ง€๋งŒ, reversed ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฐ์—ด์˜ ์—ญ์ˆœ ํƒ์ƒ‰์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•จ
# ex) k = [[1, 2, 3],     ->   ์›ํ•˜๋Š” ์ถœ๋ ฅ form: [[3, 6, 9],
#          [4, 5, 6],                          [2, 5, 8],
#          [7, 8, 9]]                          [1, 4, 7]]
# reversed(tuple(zip(*k))) = [[3, 6, 9],
#                             [2, 5, 8],
#                             [1, 4, 7]]
print(li)

10. GPU์— ๋ฉ”๋ชจ๋ฆฌ๋Š” ํ• ๋‹น๋˜์–ด ์žˆ๋Š”๋ฐ nvidia-smi์—๋Š” ์•ˆ๋‚˜์˜ฌ ๋•Œ

for i in $(ps aux | grep python | awk '{print $2}' | sort -u); do kill -9 $i; done

About

๐Ÿ”๋„์ ๋„์  ์œ ์šฉํ•œ ํŒ๋“ค

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published