
LINUX 기반 운영 체제에서 파일 생성에 대해 알아야 할 모든 것
2022-10-19 last update
7 minutes reading tutorial opensource linux bashLinux 파일 시스템은 모든 것을 파일로 간주합니다. 텍스트/미디어/바이너리 파일 및 디렉토리에서 물리적으로 연결된 하드웨어 장치에 이르기까지 모든 것이 Linux에서 파일입니다. 파일이 아닌 경우 프로세스여야 합니다. Linux에서 파일은 데이터를 관리하기 위해 트리 구조를 형성합니다. 리눅스에서 파일을 생성하는 방법은 매우 다양하므로 이를 수행하는 몇 가지 일반적인 방법을 살펴보겠습니다.
Linux 파일 시스템에 파일이 존재하기 위한 규칙
파일은 *대소문자를 구분합니다*(Windows와 다름). 따라서 사용자는 상위 폴더에 파일을 생성할 수 있는 권한이 있어야 합니다.
사용자 또는 그룹에 속해 있는지 확인하십시오.
여백 등의 다른 특수문자도 사용할 수 있지만 사용하기 어려우므로 피하는 것이 좋다. 파일 이름은 점 기반 파일 이름 확장자를 사용하여 파일을 식별합니다. 예를 들어:
.sh = 셸 파일 .tar.gz = 압축된 아카이브
대부분의 최신 Linux 및 UNIX는 파일 이름을 255자(255바이트)로 제한합니다. 그러나 일부 이전 버전의 UNIX 시스템에서는 파일 이름을 14자로 제한합니다. 파일 이름은 디렉토리 내에서 고유해야 합니다. 예를 들어, 을 생성할 수 없습니다. 이러한 문자가 파일 이름에 포함되지 않도록 하십시오. 파일 이름을 작은따옴표로 묶습니다
Linux에서 파일을 만드는 실험의 작은 스니펫:
Linux에서 파일을 만드는 일반적인 방법
기본 파일 관리자(GUI)를 사용하여 파일을 쉽게 생성할 수 있습니다. 그러나 거기에는 재미가 없습니다. 파일을 만드는 몇 가지 흥미로운 명령줄 방법을 살펴보겠습니다.
모두의 방법 - 사전 사용.
텍스트 편집기 -
현재 타임스탬프에 파일을 생성합니다. 구문:
간단한 bash 트릭을 사용하여 구문:
멋진 비실용적 방법
하드웨어 장치를 Linux 장치에 삽입합니다. 파일이 생성됩니다. 고정 크기의 파일을 만듭니다. (10MB)
이 글을 읽어주셔서 감사합니다. 더 많은 것을 위해 나를 따르십시오!
Linux 파일 시스템에 파일이 존재하기 위한 규칙
temp.txt
, Temp.txt
및 TEMP.txt
모두 다른 파일입니다. ls -al
명령으로 권한을 확인하십시오. /
를 제외한 모든 문자를 포함할 수 있습니다. 이 문자는 경로 이름에서 파일과 디렉토리 사이의 구분 기호로 예약되어 있습니다. 널 문자는 사용할 수 없습니다. /root
디렉토리 안에는 file.txt
파일과 file.txt
디렉토리 이름/><|:&
'file.txt'
. Linux에서 파일을 만드는 실험의 작은 스니펫:
[email protected]:/# cd /root
[email protected]:~# touch '[email protected]#$%^&*(()_+-{}[]":></?><'
touch: cannot touch '[email protected]#$%^&*(()_+-{}[]":></?><': No such file or directory
[email protected]:~# touch '[email protected]#$%^&*(()_+-'
[email protected]:~# touch file.txt
[email protected]:~# touch File.txt
[email protected]:~# mkdir file.txt
mkdir: cannot create directory 'file.txt': File exists
[email protected]:~# ls -al
total 16
-rw-r--r-- 1 root root 0 Jul 16 11:19 '[email protected]#$%^&*(()_+-'
drwx------ 1 root root 4096 Jul 16 11:20 .
drwxr-xr-x 1 root root 4096 Jul 16 11:17 ..
-rw-r--r-- 1 root root 3106 Oct 15 2021 .bashrc
-rw-r--r-- 1 root root 161 Jul 9 2019 .profile
-rw-r--r-- 1 root root 0 Jul 16 11:20 File.txt
-rw-r--r-- 1 root root 0 Jul 16 11:20 file.txt
Linux에서 파일을 만드는 일반적인 방법
기본 파일 관리자(GUI)를 사용하여 파일을 쉽게 생성할 수 있습니다. 그러나 거기에는 재미가 없습니다. 파일을 만드는 몇 가지 흥미로운 명령줄 방법을 살펴보겠습니다.
touch
- 전용 명령을 사용하여 파일을 생성합니다.touch file.txt
. # Create a new empty file(s) or
# change the times for existing file(s) to the current time:
touch path/to/file
# Set the times on a file to a specific date and time:
touch -t YYYYMMDDHHMM.SS path/to/file
# Set the time on a file to one hour in the past:
touch -d "-1 hour" path/to/file
# Use the times from a file to set the times on a second file:
touch -r path/to/file1 path/to/file2
# Create multiple files:
touch path/to/file{1,2,3}.txt
Credit: cheat.sh
nano
, vim
, vi
, neovim
.text_editor path/to/file.txt
. cat
, echo
또는 >
또는 >>
연산자와 함께 다른 명령을 사용합니다. STDOUT을 사용하여 파일을 생성/추가할 수 있습니다.cat
/bat
를 사용하여 파일을 만들 수 있습니다. cat > file.txt
, cat >> file.txt
.[email protected]:~/dir_test# cat file.txt
cat: file.txt: No such file or directory
[email protected]:~/dir_test# cat > file.txt
Creating and writing a file with cat command is so cool.
Writing on 2nd line
^C
[email protected]:~/dir_test# cat file.txt
Creating and writing a file with cat command is so cool.
Writing on 2nd line
[email protected]:~/dir_test# cat >> file.txt
Writing on 3rd line
^C
[email protected]:~/dir_test# cat file.txt
Creating and writing a file with cat command is so cool.
Writing on 2nd line
Writing on 3rd line
[email protected]:~/dir_test# ls -al
total 12
drwxr-xr-x 2 root root 4096 Jul 16 11:55 .
drwx------ 1 root root 4096 Jul 16 11:55 ..
-rw-r--r-- 1 root root 97 Jul 16 11:57 file.txt
멋진 비실용적 방법
fallocate -l $((10*1024*1024)) file.txt
# This option doesn't use input/output overhead, the space will be allocated immediately.
truncate -s 10M file.txt
# This creates a file full of null bytes.
dd if=/dev/urandom of=ostechnix.txt bs=10MB count=1
# This command will create a non-sparse file full of null bytes.
head -c 10MB /dev/urandom > file.txt
# This command will create a non-sparse file full of null bytes.
이 글을 읽어주셔서 감사합니다. 더 많은 것을 위해 나를 따르십시오!