[완료]하드에 널린 수많은 txt및 cpp파일을 유니코드로 한번에 변환할 방법이 있나요?

noblepylon의 이미지

리눅스를 접한지 별로 되지 않은지라 제 하드에 저장된 txt나 cpp파일은 죄다 완성확장형(UHC)으로 저장돼있습니다. 리눅스에서 열면 한글이 다 깨져서 나오는군요.
물론 한두개라면 gedit로 열어서 "다른 이름으로 저장"을 해주면 되겠지만 이게 수백개라서 말입니다;

어떻게 유니코드로 일괄적으로 변환할 방법이 없나요?

ps. 아직 갈길이 먼가봅니다...

danskesb의 이미지

man iconv

iconv는 파일의 인코딩을 변환하는 도구이고, 여러 파일을 일괄적으로 변환하는 것은 다음 분에게 넘기겠습니다.

---- 절취선 ----
http://blog.peremen.name

mrjh76의 이미지

예전에 변환할 일이 있어서, 작성해둔 스크립트네요!~

./script 디렉토리

와 같이 실행하면, 하위디렉토리까지 전부 변환해 줄꺼예요...

#!/bin/sh
 
FROM=euckr
TO=utf8
 
[ -z "$1" ] && exit
 
for target in `find $1`
do
 
        if file $target | grep -q text; then
                iconv -f $FROM -t $TO $target >/dev/null 2>&1 && cp $target $target.$FROM
                if [ -f $target.$FROM ]; then
                        iconv -f $FROM -t $TO $target.$FROM > $target.$TO && echo "Converted $target"
                        rm -f $target.$FROM
                        mv -f $target.$TO $target
                fi
        fi
done
noblepylon의 이미지

파일 확장자에 따라서 골라내는 방법이 있나요?
그냥 궁금해서...
---
"The truth will make you free."(John 8:32)
"I am the way, and the truth, and the life: no one comes to the Father but through Me."(John 14:6)

---
“내게 능력주시는 자 안에서 내가 모든 것을 할 수 있느니라.”(빌립보서 4:13)

d3m3vilurr의 이미지

find에 인자로 -name "*.foo" 형태로 인자를 주면 확장자가 foo인 파일을 가져올겁니다.

cbangsae의 이미지

.

cbangsae

d3m3vilurr의 이미지

find ./ -type f|while read f; do iconv -f cp949 -t utf-8 "$f" -o "$f".conv; done

엥...그새 리플이 달렸네요(..)

noblepylon의 이미지

저녁 잠깐 먹고 왔더니 벌써 5개의 답변이 달려있네요:)
빠른 답변 감사합니다.

ps. 그런데 가만히 보니까 한글 이름을 가진 파일은 변환이 되질 않네요:( 어떻게 해야 하나요?
---
"The truth will make you free."(John 8:32)
"I am the way, and the truth, and the life: no one comes to the Father but through Me."(John 14:6)

---
“내게 능력주시는 자 안에서 내가 모든 것을 할 수 있느니라.”(빌립보서 4:13)

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.