Ubuntu 20.04 초기설정 및 알아두면 좋을 것들
시작하며
Windows 10과 Ubuntu 20.04를 멀티부팅으로 설치하며 정말 많이 삽질했다.
지금은 그 삽질의 결정체이다. (이덕에, kernel, bootloader 등등.. 많이도 공부했다.)
설치법은 조만간 다시 Format할때, 다루겠다.
해당 사이트(블로그 포함)의 글쓴이의 허락을 받지 않고 올립니다. 혹시 글쓴이 분 중에 본인 사이트를 지웠으면 하시는 분은 아래 비공개 댓글로 알려주시면 감사하겠습니다. 참고한 사이트들이 많다보니 각각 허락받지 못했습니다. 미리 양해를 구합니다.
I'm sorry that I linked your site without your permission. I have so lots of references so I couldn't get your permmision. I beg your forgiveness. If you want to delete your linked site from my post, please comment bellow.
1. git 설치
2. Swap File 크기 올리기 : hibernate(초절전모드)
Ubuntu는 hibernate를 할때, 현재 memory의 내용을 swap에 저장한다.
그래서 가끔 swap의 크기를 무시하고 hibernate를 하려고하면, swap의 크기부족으로인한 문제에 직면한다.
Ubuntu 18.04부터는 Swap partition 대신 /swapfile을 사용한다
이 swapfile의 크기를 늘려서 hibernate에 문제가 없도록한다.
필자의 경우, 32GIB의 Ram으로, swapfile의 크기를 33GIB로 하였다. 8GIB까지 올리라고 추천하는 사람도 있다. 참고하자(이는 추후에 더 자세히 알아본다.)
https://kibua20.tistory.com/40
을 참조하자
3. hibernate(초절전모드) 활성화
hibernate에서는 swapfile을 사용하지말고 swap partition을 사용하라는 ubuntu사용자도 있다. 이에 대해서는 추후에 자세히 다루어 보겠다.
여기서는 swapfile을 사용한 방법을 사용해보자
https://askubuntu.com/questions/1285207/how-do-you-hibernate-on-ubuntu-20-04
아래 Step은 위 링크를 참고한다.
+ 아래 Step을 수행하기 전에, Swapfile의 크기를 올리고 오자(본 글의 2번)
이때, UUID는 /etc/fstab에서 'mount point'가 '/'인 것을 의미한다.
Step
- sudo vi /etc/default/grub
- GRUB_CMDLINE_LINUX_DEFAULT="..." 의 맨 뒤에 resume=UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX resume_offset=XXXXX을 추가한다.
(간혹 ...의 내용이 quiet splash만이 아닌 경우가 있어 참고 사이트와는 다르게 설명한다.)- offset은 sudo filefrag -v /swapfile |grep " 0:"| awk '{print $4}' 의 결과를 사용한다.
- sudo update-grub
- sudo systemctl hibernate를 통해 정상작동을 확인한다.
- root 권한 없이(sudo 없이) hibernate 사용하는 것은
https://blog.ivansmirnov.name/how-to-set-up-hibernate-on-ubuntu-20-04/
의 Enable Hibernation without password를 참고하자(ctrl f로 검색하기)
4. python의 기본 버전 지정하기
python의 버전을 update-alternatives로 변경하다보면, 무려 terminal이 열리지 않는 문제가 발생한다.
그렇지만, version을 그대로 두고 python이나 pip를 사용하기는 무리가 있다.
이때, alias를 사용한다.
Step
- vi ~/.bashrc
vi에 익숙치 않다면, gedit ~/.bashrc 로 접근하자 - 맨 마지막줄로 이동
- 다음을 추가
alias pip='python{원하는 version} -m pip'
alias python='python{원하는 version}' - . ~/.bashrc
*혹은 source ~/.bashrc
*동작은 동일하다. - 정상 작동 되는지 확인한다.
5. xclip 사용하기 :terminal의 출력내용을 복사하기, system clipboard의 내용을 붙여넣기
terminal의 출력내용을 clipboard에 바로 저장하고 terminal에는 출력하고 싶지 않을 때
Step
- sudo apt install xclip
- vi !~/.bashrc
- 맨 마지막 줄에 alias copy='xclip -sel clip' 추가
- . ~/.bashrc
- ls | copy로 정상작동여부 확인
https://askubuntu.com/questions/184397/how-do-i-pipe-terminal-standard-output-stdout-to-the-clipboard
terminal의 출력내용을 clipboard에 바로 저장하고 terminal에는 출력하고 싶지 않을 때
Step
- sudo apt install xclip
- vi !~/.bashrc
- 맨 마지막 줄에 alias copy='tee >(xclip -selection clipboard)' 추가
- . ~/.bashrc
- ls | copy로 정상작동여부 확인
https://askubuntu.com/questions/687382/copy-string-to-clipboard-and-display-into-output-window-simultaeneously
추가적으로 이 방법도 있다. : terminal에 clipboard의 내용을 출력하는 방법
https://stackoverflow.com/questions/57415335/how-to-copy-on-xclip-and-see-the-command-output-on-the-shell
하지만, 그다지 추천하지 않는다.(개행 안됨)
xclip 더 알아보기
https://www.44bits.io/ko/post/connecting-terminal-and-gui-cliboard-in-linux-by-using-xclip
https://plzrun.tistory.com/entry/ubuntu%EC%97%90%EC%84%9C-pbcopy-%EC%93%B0%EA%B8%B0-xclip
6. terminal Prompt에 현재 경로만 보이기 또는 절대경로 다 보이기
간혹 directory명이 길 경우, prompt가 굉장히 지저분해보이기도한다. 이때 다음을 사용하자. prompt설정은 PS1이라는 환경변수가 수행한다.
PS1 ~ PS4에 관한 설명은 다음을 참고하자
https://phoenixnap.com/kb/change-bash-prompt-linux
Step
-
vi ~/.bashrc
-
맨 밑에 다음내용을 추가한다.
alias abpath='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]$"'alias rlpath='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]$"'
-
rlpath, abpath를 명령어로 실행하며 잘 작동하는지 확인한다.
설명 -
abpath : 절대경로를 표현한다. (absolute path)
-
rlpath : 상대경로를 표현한다. (relative path)
VIM editor 팁
- tab, shift tab하기(shift blocks)
https://stackoverflow.com/questions/4559896/how-to-tab-backwards-remove-a-tab-or-tab-spaces-in-vim/4560339
https://vim.fandom.com/wiki/Shifting_blocks_visually
https://stackoverflow.com/questions/4766230/map-shift-tab-in-vim-to-inverse-tab-in-vim/4766304
그 중 Visual Mode에서는 >, <을 이용한다.-
: tab
- < : inverse tab
- : <, >을 한 다음 .을 입력하면, 방금의 작업(tab or inverse tab)이 반복된다.
- : n<, n>을 통해(n은 자연수) tab, inverse tab을 반복할 수 있다.
-
추가적인 내용
-
umask는 file의 경우 666부터, directory의 경우 777부터 시작한다. 이 시작점은 변경 불가능하다. umask u=rwx,g=rwx,o=rwx로 해도, umask 값은 000으로 설정되며, file의 permission의 경우 이에따라 666이 된다. 바꾸려고 시도하지 말자. 삽질만 하고 시간낭비다. 안되는 건 안되는 거다.
https://stackoverflow.com/questions/15599951/making-new-files-automatically-executable
마지막 Jean사용자가 된다고 썼다가 혼났(?)다.(ㅎㅎ;;)
Umask관련 설명 +기본 setting은 022이다.- 기본개념
https://jhnyang.tistory.com/63
https://geek-university.com/linux/set-the-default-permissions-for-newly-created-files/ - 로그인과 관계없이 Umask 설정하기
https://askubuntu.com/questions/805862/how-to-change-umask-mode-permanently - 파일의 Ubuntu 기본 permission(외부저장소 포함)(What Are the Default Permissions for Files in Ubuntu?)
http://blog.iqandreas.com/ubuntu/what-are-the-default-permissions-for-files-in-ubuntu/ - Why is the default file and directory permission 644 and 755 in Linux? :serarch keyword - why default permission is 644
https://www.quora.com/Why-is-the-default-file-and-directory-permission-644-and-755-in-Linux - file permission을 775로 하도록 umask설정이 가능한가? :search keyword - umask file permissions 775
https://www.unix.com/shell-programming-and-scripting/123971-possible-use-umask-set-file-permission-775-a.html
- 기본개념
-
Ubuntu에 Python Selenium 설치하기
https://somjang.tistory.com/entry/Ubuntu-Ubuntu-%EC%84%9C%EB%B2%84%EC%97%90-Selenium-%EC%84%A4%EC%B9%98%ED%95%98%EA%B3%A0-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0 -
Vim 기본
- Vim 설치
https://byd0105.tistory.com/7 - Vim 기본 사용법
https://velog.io/@skyinocean/Vim-%EA%B8%B0%EC%B4%88-%EC%82%AC%EC%9A%A9%EB%B2%95-1 - Vim 외부 명령어 실행하기
https://www.joinc.co.kr/w/Site/Vim/Documents/Tip/ExternalCommand - Vim에서의 내용을 clipboard에 복사하기, clipboard를 붙여넣기
https://hyoje420.tistory.com/49
- Vim 설치
-
history의 사용 : terminal의 명령어 기록
https://webdir.tistory.com/106
+추가설명
!8하면, history에 저장된 8번 명령어를 실행한다.
!!하면, 마지막 명령을 실행한다.
!find하면, find로 시작하는 마지막 명령을 실행한다.history의 작동원리
https://askubuntu.com/questions/953334/how-does-the-history-command-work
: history는 임시저장되었다가. bash terminal을 종료할때, ~/.bash_history에 저장한다.
- ubuntu termianl 복사, 붙여넣기
복사 : shift ctrl c
붙여넣기 : shift ctrl v - Ubuntu find 명령어
https://recipes4dev.tistory.com/156