성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
[정성태] 저렇게 조각 코드 말고, 실제로 재현이 되는 예제 프로젝트를 압...
[정성태] Modules 창(Ctrl+Shift+U)을 띄워서, 해당 Op...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>Linux - ls 명령어로 출력되는 디렉터리 색상 변경 방법</h1> <p> 제 모니터가 이상한 건지, WSL로 실행한 우분투 리눅스의 ls 명령어로 출력되는 디렉터리의 색상이 파란색인데, 아래와 같이 가독성이 너무 안 좋습니다.<br /> <br /> <img alt='ls_color_1.png' src='/SysWebRes/bbs/ls_color_1.png' /><br /> <br /> 디렉터리 이름뿐만 아니라 명령 프롬프트에 출력된 "~/projects" 글자의 출력도 마찬가지로 파란색이어서 잘 안 읽힙니다.<br /> <br /> 다행히, 색상을 바꾸는 방법이 아래에 나오는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > How to Change Colors on LS in Bash ; <a target='tab' href='https://linuxhint.com/ls_colors_bash/'>https://linuxhint.com/ls_colors_bash/</a> </pre> <br /> 일단, 현재 지정된 컬러를 이렇게 확인할 수 있고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>echo $LS_COLORS</span> rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;...[생략]...:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36: </pre> <br /> 제가 원하는 것은 "directory"의 색상이므로 "di" 값을,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > di=01;34 di == 디렉터리 01 == bold 34 == blue </pre> <br /> 무난하게 "green"으로 이렇게 바꾸면 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > di=01;32 </pre> <br /> 이런 변경 사항은 .bashrc와 같은 파일에 적용하면 되므로 편집기를 열어 해당 파일의 마지막에 이렇게 추가합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > ...[생략]... # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi LS_COLORS='rs=0:<span style='color: blue; font-weight: bold'>di=01;32</span>:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=01;33:ow=01;97:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:'; export LS_COLORS </pre> <br /> 이후 .bashrc의 변경 사항을 반영하면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>source ~/.bashrc</span> </pre> <br /> ls의 출력이 이렇게 바뀝니다.<br /> <br /> <img alt='ls_color_2.png' src='/SysWebRes/bbs/ls_color_2.png' /><br /> <br /> <hr style='width: 50%' /><br /> <br /> 명령 프롬프트의 디렉터리 색상도 바꿔볼까요?<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Task: Displaying current BASH prompt (PS1) ; <a target='tab' href='https://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/'>https://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/</a> </pre> <br /> WSL 우분투의 경우 프롬프트 설정이 이렇게 되어 있고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>echo "$PS1"</span> \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ </pre> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > \u: Display the current username. \h: Display the hostname. \W: Print the base of current working directory. \$: Display # (indicates root user) if the effective UID is 0, otherwise display a $. </pre> <br /> 마찬가지로 파란색을 나타내는 34m의 값을 (green에 해당하는) 32m으로 바꿔 적용하면,<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='ls_color_3.png' src='/SysWebRes/bbs/ls_color_3.png' /><br /> <br /> 보는 바와 같이 "projects"의 색상이 파란색에서 녹색으로 바뀐 것을 볼 수 있습니다. 참고로, 이것 역시 우분투 WSL에서는 .bashrc에 포함돼 있는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > ...[생략]... if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi ...[생략]... </pre> <br /> 따라서 이곳의 코드를 다음과 같이 변경하면 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;<span style='color: blue; font-weight: bold'>32m</span>\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi </pre> <br /> <hr style='width: 50%' /><br /> <br /> 그런데, directory가 특수한 유형인 경우에는 또 색상명이 달라집니다. 가령 WSL의 경우 "ls /mnt" 명령을 내려보면 "c", "d"와 같은 드라이브 명의 디렉터리와 "wsl" 디렉터리의 색상이 다릅니다.<br /> <br /> 그런 것들은, 각각 "tw"와 "ow"에 해당하는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > ow = (OTHER_WRITABLE) Directory that is other-writable (o+w) and not sticky tw: (STICKY_OTHER_WRITABLE) Directory that is sticky and other-writable (+t,o+w) </pre> <br /> 그래서 그런 것들도 이렇게 바꿀 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > [이전 값] tw=30;42 [신규 값] tw=01;33 [이전 값] ow=34;42 [신규 값] ow=01;97 </pre> <br /> 그럼 이렇게 바뀌는 것을 확인할 수 있습니다.<br /> <br /> <img alt='ls_color_4.png' src='/SysWebRes/bbs/ls_color_4.png' /><br /> <br /> <hr style='width: 50%' /><br /> <br /> 참고로, 아래의 글에 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > How do I change the color for directories with ls in the console? ; <a target='tab' href='https://askubuntu.com/questions/466198/how-do-i-change-the-color-for-directories-with-ls-in-the-console'>https://askubuntu.com/questions/466198/how-do-i-change-the-color-for-directories-with-ls-in-the-console</a> </pre> <br /> 좀 더 자세한 정보가 나옵니다. 색상 관련 내용도 잘 정리돼 있고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 0 = default colour 1 = bold 4 = underlined 5 = flashing text (disabled on some terminals) 7 = reverse field (exchange foreground and background color) 8 = concealed (invisible) 40 = black background 41 = red background 42 = green background 43 = orange background 44 = blue background 45 = purple background 46 = cyan background 47 = grey background 100 = dark grey background 101 = light red background 102 = light green background 103 = yellow background 104 = light blue background 105 = light purple background 106 = turquoise background 107 = white background 30 = black 31 = red 32 = green 33 = orange 34 = blue 35 = purple 36 = cyan 37 = grey 90 = dark grey 91 = light red 92 = light green 93 = yellow 94 = light blue 95 = light purple 96 = turquoise 97 = white </pre> <br /> LSCOLORS의 키값에 대한 설명도 나옵니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > bd = (BLOCK, BLK) Block device (buffered) special file cd = (CHAR, CHR) Character device (unbuffered) special file di = (DIR) Directory do = (DOOR) [Door][1] ex = (EXEC) Executable file (ie. has 'x' set in permissions) fi = (FILE) Normal file ln = (SYMLINK, LINK, LNK) Symbolic link. If you set this to ‘target’ instead of a numerical value, the color is as for the file pointed to. mi = (MISSING) Non-existent file pointed to by a symbolic link (visible when you type ls -l) no = (NORMAL, NORM) Normal (non-filename) text. Global default, although everything should be something or = (ORPHAN) Symbolic link pointing to an orphaned non-existent file ow = (OTHER_WRITABLE) Directory that is other-writable (o+w) and not sticky pi = (FIFO, PIPE) Named pipe (fifo file) sg = (SETGID) File that is setgid (g+s) so = (SOCK) Socket file st = (STICKY) Directory with the sticky bit set (+t) and not other-writable su = (SETUID) File that is setuid (u+s) tw = (STICKY_OTHER_WRITABLE) Directory that is sticky and other-writable (+t,o+w) *.extension = Every file using this extension e.g. *.rpm = files with the ending .rpm </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
8631
(왼쪽의 숫자를 입력해야 합니다.)