Peter Ahn
Peter의 우아한 프로그래밍
Peter Ahn
전체 방문자
1,143,671
오늘
0
어제
201
  • 전체 (114)
    • 영어공부 (15)
    • 물생활 (9)
    • 독서 (2)
    • 일상 (1)
    • IT 소식 (15)
      • 최신 기술 소식 (10)
      • 보안 소식 (5)
    • 인공지능 (AI) (2)
    • OS (19)
      • Linux (19)
    • Web (0)
      • Vue.js (0)
    • 객체지향 (1)
      • 개념과 원리 (1)
      • 디자인패턴 (0)
    • 프로그래밍 (34)
      • C (14)
      • C++ (3)
      • C# (1)
      • Python (1)
      • Javascript (1)
      • Bash (4)
      • Vim (9)
    • Database (3)
      • DB2 (3)
      • MongoDB (0)
    • 프레임워크 (1)
      • Ionic (1)
    • Cloud (1)
      • AWS (1)
    • 3D Printer (2)
    • 기록보관소 (5)
    • 초대장 (2)

블로그 메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

공지사항

  • 프로그래밍의 세계에 오신 것을 환영합니다.

인기 글

  • [Linux] ps 로 실행 중인 프로세스 확인하기
    2020.08.05
    [Linux] ps 로 실행 중인 프로세스 확인하기
  • [bash 쉘 스크립트] 스크립트 실행하기
    2018.06.04
    [bash 쉘 스크립트] 스크립트 실행하기
  • [Linux] cp 또는 mv 로 파일 강제로 덮어쓰기
    2018.05.03
    [Linux] cp 또는 mv 로 파일 강제로 덮어쓰기
  • [bash 쉘 스크립트] 종료(exit)와 종료 상태 (e⋯
    2019.10.30
    [bash 쉘 스크립트] 종료(exit)와 종료 상태 (e⋯
  • [Vim] 문자열 검색 및 바꾸기
    2019.10.29
    [Vim] 문자열 검색 및 바꾸기

태그

  • 영어표현
  • 쉘 프로그래밍
  • C++
  • 딥러닝
  • C언어
  • 생활영어
  • 리눅스 검색
  • vim
  • 프로그래밍
  • vim 비주얼모드
  • call by reference
  • 리눅스 명령어
  • C언어 강좌
  • bash
  • 어항
  • 물생활
  • 4차 산업혁명
  • c강좌
  • 구피어항
  • bash shell
  • 인공지능
  • 영어 표현
  • 하프블랙구피
  • vim 강좌
  • Linux
  • 영어 회화
  • 랜섬웨어
  • AI
  • 리눅스
  • 구피

최근 댓글

  • 좋은 글 정말 감사합니다. 덕분에 얼추 감이 잡히네요 ㅠㅠ⋯
    김케이
  • 언 오더.. 얼어있다. 맞습니다. 해동해야하기 때문에 오⋯
    방구석경비원
  • 명령어뿐만 아니라 친절한 설명 감사드립니다 !!
    AYKO
  • 하트하고 가요.
    나리카페
  • 위키백과나 다른 웹사이트에서 설명 보고 아리송했는데.. ⋯
    국어척척석사

최근 글

  • C 언어와 C++ 의 차이
    2020.08.26
    C 언어와 C++ 의 차이
  • [Linux] nohup 세션이 끊겨도 계속 실행되도록 해⋯
    2020.08.18
    [Linux] nohup 세션이 끊겨도 계속 실행되도록 해⋯
  • [bash 쉘 스크립트] 변수 할당(assignment)과⋯
    2020.08.17
    [bash 쉘 스크립트] 변수 할당(assignment)과⋯
  • [객체지향] Object-Oriented Programmi⋯
    2020.08.14
    [객체지향] Object-Oriented Programmi⋯
  • [Linux] kill 프로세스를 '안전하게' 종료시켜보⋯
    2020.08.07
    [Linux] kill  프로세스를 '안전하게' 종료시켜보⋯

티스토리

hELLO · Designed By 정상우.
Peter Ahn

Peter의 우아한 프로그래밍

[Linux] touch 파일 생성하기
OS/Linux

[Linux] touch 파일 생성하기

2018. 5. 9. 15:14
반응형

개요

touch 명령어는 리눅스에서 파일을 생성하거나 갱신하는 명령어입니다.

새로운 파일을 만들 때는 존재하지 않는 파일명을 지정하면 지정된 파일명으로 파일이 생성되며 이미 존재하는 파일을 지정하면 파일의 수정시간이 업데이트 됩니다.


사용법

리눅스에서 사용되는 명령어는 모두 대소문자를 구분하니 주의해주세요.

touch 명령어에 대한 자세한 설명은 touch --help 명령어를 통해 볼 수 있습니다.


Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.

A FILE argument that does not exist is created empty, unless -c or -h
is supplied.

A FILE argument string of - is handled specially and causes touch to
change the times of the file associated with standard output.

Mandatory arguments to long options are mandatory for short options too.
  -a                     change only the access time
  -c, --no-create        do not create any files
  -d, --date=STRING      parse STRING and use it instead of current time
  -f                     (ignored)
  -h, --no-dereference   affect each symbolic link instead of any referenced
                         file (useful only on systems that can change the
                         timestamps of a symlink)
  -m                     change only the modification time
  -r, --reference=FILE   use this file's times instead of current time
  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time
      --time=WORD        change the specified time:
                           WORD is access, atime, or use: equivalent to -a
                           WORD is modify or mtime: equivalent to -m
      --help     display this help and exit
      --version  output version information and exit

Note that the -d and -t options accept different time-date formats.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'touch invocation'

기본 사용법은 아래와 같습니다.

touch [OPTION] filename


touch 로 기존에 존재하지 않는 파일명을 지정하면 크기가 0 byte인 파일을 생성합니다.

[root@peterdev test]# touch new_file
[root@peterdev test]# ls -l | grep new_file
-rw-r--r-- 1 root root    0 May  9 06:06 new_file
[root@peterdev test]#



이미 존재하는 파일을 touch 하게 되면 수정시간만 현재 시간으로 변경됩니다.

drwxr-xr-x 2 root root 4096 May  3 14:27 john
-rw-r--r-- 1 root root    0 May  8 14:40 mv_test.dat
drwxr-xr-x 2 root root 4096 May  3 14:27 peter
-rw-r--r-- 1 root root   33 May  3 14:48 test1.txt
-rw-r--r-- 1 root root   33 May  8 14:56 test2.txt
[root@peterdev test]#
[root@peterdev test]#
[root@peterdev test]#
[root@peterdev test]# touch test1.txt
[root@peterdev test]# ls -l
total 16
drwxr-xr-x 2 root root 4096 May  3 14:27 john
-rw-r--r-- 1 root root    0 May  8 14:40 mv_test.dat
drwxr-xr-x 2 root root 4096 May  3 14:27 peter
-rw-r--r-- 1 root root   33 May  9 05:59 test1.txt
-rw-r--r-- 1 root root   33 May  8 14:56 test2.txt

예제

ex) teacher.txt 라는 파일을 생성

touch teacher.txt



ex) 파일의 수정 시간을 지정한 timestamp 로 변경

[root@peterdev peter]# touch -t 201801010000 language.c
[root@peterdev peter]# ls -l
total 0
-rw-r--r-- 1 root root 0 May 3 14:27 language.bash
-rw-r--r-- 1 root root 0 Jan 1 00:00 language.c
-rw-r--r-- 1 root root 0 May 3 14:26 language.cpp
-rw-r--r-- 1 root root 0 May 3 14:27 language.delphi
-rw-r--r-- 1 root root 0 May 3 14:26 language.english
-rw-r--r-- 1 root root 0 May 3 14:27 language.java
-rw-r--r-- 1 root root 0 May 3 14:26 language.javascript
-rw-r--r-- 1 root root 0 May 3 14:27 language.korean
-rw-r--r-- 1 root root 0 May 3 14:26 language.python


번외

touch 명령어 외에도 아래와 같이 파일을 생성할 수 있습니다.


아래는 I/O 재지향으로 파일을 생성하고 내용 입력하는 방법입니다.

[root@peterdev test]# echo "test" > new.txt
[root@peterdev test]# ls -l | grep new.txt
-rw-r--r-- 1 root root    5 May  9 06:09 new.txt
[root@peterdev test]# cat new.txt
test
[root@peterdev test]#

만약에 이미 존재하는 파일에 내용을 추가(append)하고 싶을 때는

재지향 연산자 > 대신에 >>를 사용하면 됩니다.


 

 

-Peter의 우아한 프로그래밍

반응형
저작자표시 비영리 동일조건
  • 카카오스토리
  • 트위터
  • 페이스북

'OS > Linux' 카테고리의 다른 글

[Linux] 파이프(pipe)에 대한 이해  (4) 2018.05.15
[Linux] gcc, g++ 설치하기 (CentOS)  (1) 2018.05.10
[Linux] mv 파일 및 디렉토리 이동  (0) 2018.05.09
[Linux] find 로 파일 찾아서 지우기  (4) 2018.05.08
[Linux] find 로 파일 검색하기  (0) 2018.05.05
    'OS/Linux' 카테고리의 다른 글
    • [Linux] 파이프(pipe)에 대한 이해
    • [Linux] gcc, g++ 설치하기 (CentOS)
    • [Linux] mv 파일 및 디렉토리 이동
    • [Linux] find 로 파일 찾아서 지우기
    II/O 재지향, linux touch, linux 명령어, touch, 리눅스 파일 생성, 파일 생성, 파일 시간 변경
    Peter Ahn
    Peter Ahn
    IT 정보 공유, 프로그래밍 지식 공유
    댓글쓰기
    [Linux] gcc, g++ 설치하기 (CentOS)
    다음 글
    [Linux] gcc, g++ 설치하기 (CentOS)
    [Linux] mv 파일 및 디렉토리 이동
    이전 글
    [Linux] mv 파일 및 디렉토리 이동

    티스토리툴바