Dev Blog

스크립트 & 소스코드 공유

실무에서 유용하게 쓰는 스크립트와 코드 조각을 블로그 게시판으로 저장하고 공유합니다.

9건의 글

리눅스 서버에서 폴더별 용량 확인 및 삭제 방법 (du, rm)

리눅스 서버에서 du 명령어로 폴더별 디스크 사용량을 확인하는 방법을 정리했다. du -sh로 각 폴더 요약 확인, 특정 경로의 하위 폴더별 용량, 재귀적 용량 표시, sort -hr로 큰 폴더 순 정렬을 설명하고, rm -rf로 폴더를 삭제할 때 되돌릴 수 없으므로 백업 후 신중하게 사용해야 한다는 주의사항을 강조한다.

리눅스 서버에서 폴더별 용량을 확인하려면 주로 du 명령어를 사용합니다. 예를 들어:

  1. 현재 디렉토리 내 각 폴더 용량 확인:
    du -sh */ 
  • du : 디스크 사용량(disk usage)을 표시하는 명령어
  • -s : 각각의 디렉토리에 대해 합계만 출력 (요약)
  • -h : 사람이 읽기 쉬운 형식(human-readable), KB/MB/GB 단위로 표시
  • */ : 현재 디렉토리 내 폴더들만 대상으로 함
  1. 특정 경로 내 폴더별 용량 확인:
    du -sh /path/to/directory/*/ 
  2. 하위 폴더까지 재귀적으로 모두 용량 표시:
    du -h /path/to/directory 
  3. 용량이 큰 폴더부터 정렬해서 보고 싶다면:
    du -sh /path/to/directory/* | sort -hr 
  • sort -hr : 숫자를 크기 순서로 역정렬(human-readable 숫자도 인식)

리눅스 서버에서 /www/css/images 폴더를 삭제하려면 rm 명령어를 사용합니다. 폴더(디렉토리)를 삭제하려면 -r 옵션(재귀적 삭제)과 -f 옵션(강제 삭제)을 함께 쓰는 것이 일반적입니다.

다음 명령어를 터미널에 입력하세요:

rm -rf /www/css/images 

설명:

  • rm : 파일/폴더 삭제 명령어
  • -r : 디렉토리 및 그 안의 모든 파일과 하위 디렉토리를 재귀적으로 삭제
  • -f : 강제로 삭제, 삭제 확인 메시지 없이 처리

주의:

  • 해당 폴더와 그 안의 모든 파일이 완전히 삭제되므로 매우 신중히 사용하세요.
  • 삭제 후에는 복구가 어렵습니다.
  • 필요하다면 삭제 전에 백업을 권장합니다.

삭제 권한 문제가 있으면 sudo를 붙여 관리자로 실행하세요:

sudo rm -rf /www/css/images 

CSS로 웹폰트 글자 계단 현상(안티앨리어싱) 해결하기

낮은 버전 IE 등 일부 브라우저에서 웹폰트 글자가 계단처럼 보이는 안티앨리어싱 문제를 해결하는 CSS 팁이다. 육안으로 구분되지 않는 미세한 기울기 transform: skew(0.001deg)를 글자에 적용하면 렌더링이 부드러워지며, .font_sel 클래스에 적용하는 예제 코드를 함께 소개한다.

使用WEBFONT时,低版本的IE浏览器以及其他浏览器显示字体有锯齿现象解决方。

.font_sel {transform:skew(-0.001deg);}

给些肉眼看不出来的斜度

그누보드 업로드 이미지에 워터마크 일괄 적용하기

그누보드 게시판의 write_update.skin.php를 아래 소스로 교체하면 업로드되는 모든 이미지에 워터마크가 일괄 적용된다. PHP GD 함수로 원본 이미지 위에 워터마크를 합성하며, 함께 포함된 이미지 리사이즈 기능이 필요 없으면 주석 처리된 부분을 참고해 제거할 수 있다.

적용하고 싶은 게시판의 "write_update.skin.php"를 아래 소스로 바꾸시면 됩니다.

아래 소스는 이미지 리사이즈 적용 소스이니..원치 않으시면 주석달린곳을 참고 하시면 됩니다.

<?
// 자신만의 코드를 넣어주세요.
$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';
$sql2=" select * from $g4[board_file_table] where  bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no asc";
$results2 = sql_query($sql2);
for ($d=0; $row2=sql_fetch_array($results2); $d++)  {
if ($_FILES[bf_file][name][$d]){
$file = $data_path .'/'. $row2[bf_file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file)) {
$size = getimagesize($file);
if ($size[2] == 1) $src = imagecreatefromgif($file);
else if ($size[2] == 2) $src = imagecreatefromjpeg($file);
else if ($size[2] == 3) $src = imagecreatefrompng($file);
else break;
$rate = $board[bo_image_width] / $size[0]; // 리사이즈를 원치않으면 여기서부터~~~
$height = (int)($size[1] * $rate);
if ($size[0] > $board[bo_image_width]){
@unlink($data_path.'/'.$row2[bf_file]);
$dst = imagecreatetruecolor($board[bo_image_width], $height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $board[bo_image_width], $height, $size[0], $size[1]);
imagejpeg($dst, $data_path.'/'.$row2[bf_file], $board[bo_2]); //혹 업로드 이미지 깨지면 여긴 주석처리하시고 바로 아래 껄 이용하세요..
// imagepng($dst, $data_path.'/'.$row2[bf_file], $board[bo_2]); //주석 해제
chmod($data_path.'/'.$row2[bf_file], 0606);
$temp = @getimagesize(addslashes($file));

} // 리사이즈를 원치않으면 여기까지 삭제 & 주석처리하면 됨.
$wmFile = $g4[path]."/img/logo_mark.gif"; // 워터마크 이미지 주소
$wmImg  = imageCreateFromGIF($wmFile);
$size = getimagesize($file);
if ($size[2] == 1)  $jpegImg = imagecreatefromgif($file);
else if ($size[2] == 2)  $jpegImg = imagecreatefromjpeg($file);
else if ($size[2] == 3)  $jpegImg = imagecreatefrompng($file);
else break;
$wmX=imageSX($jpegImg) - imageSX($wmImg);
$wmY=imageSY($jpegImg) - imageSY($wmImg);
imageCopyMerge($jpegImg, $wmImg, $wmX, $wmY, 0, 0, imageSX($wmImg), imageSY($wmImg), 90);
ImageJPEG($jpegImg, $file, 90);
}
}
}
?>

PHP 엑셀 다운로드 시 숫자 앞자리 0이 사라지지 않게 하기

PHP에서 웹페이지 데이터를 엑셀 형식으로 내보낼 때 셀의 앞자리 0(예: 010...)이 사라지는 문제를 해결하는 방법이다. MIME 타입을 application/vnd.ms-excel로 설정하고, 데이터를 감싸는 td 태그에 vnd.ms-excel.numberformat:@ 스타일을 지정하면 셀이 텍스트 형식으로 출력되어 0이 유지된다. 날짜·숫자·통화·퍼센트 형식도 정리했다.

“首先,我们了解一下excel从web页面上导出的原理。

当我们把这些数据发送到客户端时,我们想让客户端程序(浏览器)以excel的格式读取它,

所以把mime类型设为:application/vnd.ms-excel,当excel读取文件时会以每个cell的格式呈现数据,如果cell没有规定的格式,则excel会以默认的格式去呈现该cell的数据。

这样就给我们提供了自定义数据格式的空间,当然我们必须使用excel支持的格式。

下面就列出常用的一些格式:

1) 文本:vnd.ms-excel.numberformat:@

2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd

3) 数字:vnd.ms-excel.numberformat:#,##0.00

4) 货币:vnd.ms-excel.numberformat:¥#,##0.00

5) 百分比:vnd.ms-excel.numberformat: #0.00%

这些格式你也可以自定义,比如年月你可以定义为:yy-mm等等。

那么知道了这些格式,怎么去把这些格式添加到cell中呢?很简单,我们只需要把样式添加到对应的标签对(即闭合标签)即可。

如,给标签对添加样式,如下:<td style="vnd.ms-excel.numberformat:@">410522198402161833</td>

순수 CSS로 radio·checkbox 스타일 예쁘게 꾸미기

JavaScript 없이 순수 CSS만으로 라디오 버튼과 체크박스를 예쁘게 스타일링하는 방법이다. 기본 input을 숨기고 label과 가상 요소(::before, ::after)를 활용해 커스텀 UI를 구성하며, 체크 상태에 따라 색상과 모양이 바뀌도록 하는 CSS와 HTML 구조 예제를 제공한다.

css

/* 체크박스 스타일시트 */
.ck_style{margin:0 10px 0 0;display:inline-block;}
.ck_style input[type="radio"] , .ck_style input[type="checkbox"]{display:none}
.ck_style i{background-color:#fff;border:1px solid rgba(0,0,0,0.15);border-radius:100%;display:inline-block;height:18px;margin-right:6px;margin-top:-1px;vertical-align:middle;width:18px;line-height:1}
.ck_style input[type="radio"]:checked + i:after{background-color:#2fa2dd;border-radius:100%;content:"";display:inline-block;height:12px;margin:2px;width:12px}
.ck_style input[type="checkbox"] + i{border-radius:0}
.ck_style input[type="checkbox"]:checked + i:after{background-color:#2fa2dd;border-radius:0;content:"";display:inline-block;height:12px;margin:2px;width:12px}

HTML

<label class="ck_style"><input type="radio" name="demo-radio"><i></i> 여</label>
<label class="ck_style"><input type="radio" name="demo-radio"><i></i>부</label>

<label class="ck_style"><input type="checkbox" name="demo-radio"><i></i> 기술이전</label>
<label class="ck_style"><input type="checkbox" name="demo-radio"><i></i> 공동연구</label>
<label class="ck_style"><input type="checkbox" name="demo-radio"><i></i> 위탁연구</label>
<label class="ck_style"><input type="checkbox" name="demo-radio"><i></i> 가족기업</label>


Let's create something great together.

프로젝트 문의 및 견적 요청은 언제든 환영합니다.