파일명에 개행문자 들어간 경우 어떻게 해야하나요?

ktlsu1231의 이미지

안녕하세요.

UNIX 쪽으로 FTP로 전송한 파일명이 "ABCDE222[cr].txt" 형태로 되었습니다.
CR 은 ASCII 입니다.
ls -a 을 해보면 아래와 같이 나타납니다.

.TXTr-xr-x 1 user users 557 Sep 10 08:08 ABCDE222

ls -al > list.txt 저장하여 보면 [CR]이 들어 있다는 것을 알 수 있었습니다.

특정경로의 파일명을 읽어 [CR] 이 있을 경우 없앤 파일명으로
rename() 을 사용하여 이름을 변경하고 싶습니다.

opendir(pDirent->d_name) 식으로 읽어보려 했는데요.
.TXT 만 보이고 앞의 ABCDE222 는 보이지 않았습니다.

어떻게 읽어야 하는지 모르겠습니다.
도와주세요.

aero의 이미지

inode를 통해서 이름을 변경하는 방법입니다.

ls -il
명령으로 파일리스트를 본다.
파일리스트에서 t.txt 란 파일을 예를 들면
184719260 -rw-r--r-- 1 aero users 0 2007-09-12 08:39 t.txt

위에서 맨 왼쪽 184719260 이 해당 파일의 inode 번호이다.
inode 번호를 다음과 같이 지정하여 명령을 내린다.

find . -inum 184719260 -exec mv {} new.txt \;

위 명령의 결과로 t.txt는 new.txt 로 이름이 바뀐다.

ktlsu1231의 이미지

변경되네요.
틈틈히 시간날 때 쉘 스크립트로 자동변환되도록 한 번 해봐야겠습니다.
감사합니다. ^^

하지만 C 에서 처리할 수 있는 방법은 없을까요? ^^;

익명 사용자의 이미지

ls *.txt | grep '^M' | sed 's/\(.*\).^M\(.*\)/mv & \1_\2/' | sh

^M 는 (ctrl+v, ctrl+j) 로 입력하시면 됩니다..
파일 중에서 특수문자 ^M 하나를 _ (underbar) 로 바꾸는 예입니다..

C 로 짜시려면.. opendir/readdir 류의 함수를 써서..
직접 file 명을 가져오시는게 나을 것 같습니다..
쉘로 처리하려면 좀 고달프네요..

익명 사용자의 이미지

ls *.txt | grep '^M' | sed 's/\(.*\).^M\(.*\)/mv & \1_\2/' | sh
에서.. sed 부분의 .^M 은 ^M 으로... ;;;

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.