• cat 명령어 - 파일 내용 출력, 연결
    Linux 2023. 3. 1. 14:32

     

    cat

    터미널 창에 파일의 내용을 출력하거나, 다른 파일과 합치는(concatenate) 명령어

     

    $ cat > new_file.txt
    hello world
    ^C

    > : 명령어 실행 후 파일의 내용(hello world)을 입력하고 ctrl+c(^C)를 눌러 입력 종료.

    new_file.txt가 없을 경우 새로 생성, 존재할 경우 기존 내용을 덮어 씀.

     

    $ cat >> new_file.txt
    programmed to work and not to feel
    ^C

    >> : 명령어 실행 후 파일의 내용(programmed…)을 입력하고 ctrl+c(^C)를 눌러 입력 종료.

    new_file.txt가 없을 경우 새로 생성, 존재할 경우 기존 내용 뒤에 이어 씀.

     

    $ cat new_file.txt
    hello world
    programmed to work and not to feel

    new_file.txt의 내용을 출력.

     

    $ cat -n new_file.txt
         1	hello world
         2	programmed to work and not to feel

    -n option : new_file.txt의 내용을 출력하되, 라인 앞에 라인 번호 출력.

     

    $ cat new_file.txt | grep 'feel'
    programmed to work and not to feel

    grep 명령어와 함께 사용하여 문자열 필터링하기.

    new_file.txt 내에서 'feel'이 들어간 문자열을 출력함.

    ( | : 첫 번째 명령어의 출력 결과를 두 번째 명령어로 전달)

     

    $ cat new_file2.txt >> new_file.txt

    new_file.txt 파일의 내용 뒤에 new_file2.txt 파일의 내용을 이어 붙임.

     

    $ cat new_file.txt new_file2.txt > new_file3.txt

    new_file.txt 파일의 내용 뒤에 new_file2.txt 파일의 내용을 이어 붙여 new_file3.txt라는 새로운 파일 생성.

     

    댓글

ABOUT ME

공부한 것을 기록하기 위해 블로그를 개설했습니다. 관심 분야는 ROS와 머신러닝입니다.

VISIT

/