
OS: 쿠분투 22.04.4 LTS x86_64
위에 표시하려면:
neofetch --stdout |grep 'OS:'
.
파일 내용이 아닌 파일 이름을 간단히 정리하는 방법은 무엇입니까?
파일 이름에서 제거하여:
\n
개행 문자\t
탭- 인쇄할 수 없는 문자
- 공백
Microsoft Windows의 경우 < > : " \ / | ? *
파일 이름에 없습니다.
< (less than)
> (greater than)
: (colon - sometimes works, but is actually NTFS Alternate Data Streams)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)
.
예시 1:
문제의 파일명을 만드는 방법. 터미널에서
mv를 사용하여 파일 이름에 줄 바꿈을 추가합니다 .
touch a
mv a $'b\nc' # move (rename) files
ls # 'b'$'\n''c'
ls -b # b\nc
GUI를 사용하는 경우 F2를 누르십시오. = 이름 바꾸기:
b
c
.
예 2:
더 긴 이름.
touch 'This filename will have Tabs and Newlines_.txt'
mv 'This filename will have Tabs and Newlines_.txt' $'This\tfilename\twill\thave\tTabs\nand\nNewlines_.txt'
ls # 'This'$'\t''filename'$'\t''will'$'\t''have'$'\n''Tabs'$'\n''and'$'\n''Newlines_.txt'
ls -b # This\tfilename\twill\thave\nTabs\nand\nNewlines_.txt
GUI를 사용하는 경우 F2를 누르십시오. = 이름 바꾸기:
This filename will have Tabs
and
Newlines_.txt
.
예 3:
더 복잡합니다.
touch 'This filename will have Tabs and Newlines & SPACES & colon: _.txt'
mv 'This filename will have Tabs and Newlines & SPACES & colon: _.txt' $'This\tfilename\twill\thave\tTabs\nand\nNewlines & SPACES & colon: _.txt'
ls # 'This'$'\t''filename'$'\t''will'$'\t''have'$'\t''Tabs'$'\n''and'$'\n''Newlines & SPACES & colon: _.txt'
ls -b # This\tfilename\twill\thave\tTabs\nand\nNewlines\ &\ SPACES\ &\ colon:\ _.txt
GUI를 사용하는 경우 F2를 누르십시오. = 이름 바꾸기:
This filename will have Tabs
and
Newlines & SPACES & colon: _.txt
.
예제 3의 bash 정리 파일 이름:
#!/bin/bash
clear
# FILE : original_filename comes from inotifywait command, On access, auto detect a file in /home/xxx/Downloads to eventually do a CLAM virus scan on FILE.
filename1=$FILE
filename1=$'This\tfilename\twill\thave\tTabs\nand\nNewlines\ &\ SPACES\ &\ colon:\ _.txt'
echo "$filename1"
filename2="${filename1//[$'\t'$'\n'$'\e'$'\r'$'\f'$'\v'$'\b'$'\a'$'\0']/-}" # Replace Non Printable Characters with dash -
echo "$filename2"
filename3="${filename2//[$'\ ']/_}" # Replace space with underscore _
echo "$filename3"
filename4="${filename3//[$':']/_}" # Replace colon : with underscore _
echo "$filename4"
.
bash 결과 예 3:
This filename will have Tabs
and
Newlines\ &\ SPACES\ &\ colon:\ _.txt
This-filename-will-have-Tabs-and-Newlines\ &\ SPACES\ &\ colon:\ _.txt
This-filename-will-have-Tabs-and-Newlines__&__SPACES__&__colon:___.txt
This-filename-will-have-Tabs-and-Newlines__&__SPACES__&__colon____.txt
인쇄할 수 없는 문자를 대시로 대체 - 포함
\n
개행 문자\t
탭
공백을 밑줄로 대체 _
콜론을 밑줄로 대체:
_
.
참조 1:
인쇄할 수 없는 전체 문자 목록
https://fjolt.com/article/linux-non-printable-characters
Name Binary Decimal Hexadecimal Octal Caret Escape
Notation Sequence
Null 000 0000 0 00 000 ^@ \0
Beep(BEL) 000 0111 7 07 007 ^G \a
Backspace(BS) 000 1000 8 08 010 ^H \b
HorizontalTab(HT) 000 1001 9 09 011 ^I \t
LineFeed(LF) 000 1010 10 0A 012 ^J \n
VerticalTab(VT) 000 1011 11 0B 013 ^K \v
FormFeed(FF) 000 1100 12 0C 014 ^L \f
CarriageReturn(CR) 000 1101 13 0D 015 ^M \r
Escape(ESC) 001 1011 27 1B 033 ^[ \e
9 Escape Sequences:
\0
\a
\b
\t
\n
\v
\f
\r
\e
used:
column -t -o ' ' a.txt b.txt
.
orig_filename=$'TN1\tThis\nFileName\nHas\tTabsandNewlines'
echo test > "$orig_filename"
new_filename="${orig_filename//[$'\t'$'\n']/-}"
mv --no-clobber "$orig_filename" "$new_filename"
.
참조 3:
셸 매개변수 확장
${parameter//pattern/string}
https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
질문:
파일 이름을 간단히 정리하는 방법은 무엇입니까?
더 간단한 명령은 무엇입니까?
--