There are several possible solutions:
Create an empty file
touch file
>file
echo -n > file
printf '' > file
The echo
version will work only if your version of echo
supports the -n
switch to suppress newlines. This is a non-standard addition. The other examples will all work in a POSIX shell.
Create a file containing a newline and nothing else
echo '' > file
printf '\n' > file
This is a valid "text file" because it ends in a newline.
Write text into a file
"$EDITOR" file
echo 'text' > file
cat > file <<END \
text
END
printf 'text\n' > file
These are equivalent. The $EDITOR
command assumes that you have an interactive text editor defined in the EDITOR environment variable and that you interactively enter equivalent text. The cat
version presumes a literal newline after the \
and after each other line. Other than that these will all work in a POSIX shell.
Of course there are many other methods of writing and creating files, too.
References
https://stackoverflow.com/a/9382303
제 글이 도움이 되셨다면 간단하게 '공감', '댓글' 부탁드립니다!
'Linux' 카테고리의 다른 글
특정 port를 사용하고 있는 프로세스 찾아서 죽이기 (0) | 2020.03.08 |
---|---|
LINUX UBUNTU에서 KAKAOTALK 설치하기 (0) | 2018.12.05 |
우분투 부팅 순서 변경하기(GRUB 설정, GRUB-CUSTOMIZER 이용) (0) | 2018.12.05 |
리눅스 멀티부팅 삽질기(LINUX MINT CINNAMON 18.2 SONYA, UBUNTU 16.04.3 LTS) (0) | 2018.12.05 |
댓글