ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • How to display file contents in linux (cat)
    linux 2023. 2. 20. 16:57

    In Linux, the cat command is a utility that is used to concatenate files and display their contents on the terminal. It can also be used to create new files or to append text to an existing file. Here is a table of common options for the cat command in Linux:

    OptionDescription

    -n Number the output lines
    -b Number only the non-blank output lines
    -E Display a dollar sign ($) at the end of each line
    -T Display tabs as ^I
    -v Display non-printing characters except tabs and newlines
    -s Squeeze multiple adjacent empty lines into one line
    -A Combination of -v, -E, and -T

    And here are some simple examples of how to use the cat command:

     

    • To display the contents of a file on the terminal, use the following command
    cat filename
    • To concatenate two or more files and display their contents on the terminal, use the following command:
    cat file1 file2
    • To create a new file and add text to it, use the following command:
    cat > filename

    This will open a new blank file named filename and allow you to add text to it. Press Ctrl + D to save the changes and exit.

    •  To append text to an existing file, use the following command:
    cat >> filename

    This will allow you to add text to the end of the existing file. Press Ctrl + D to save the changes and exit.

    • To number the output lines, use the following command:
    cat -n filename
    • To display non-printing characters except tabs and newlines, use the following command:
    cat -v filename
     
    Note that the cat command is primarily used for displaying the contents of files on the terminal. If you need to edit or manipulate the contents of a file, it is recommended to use a text editor like nano, vim, or emacs.
     

    'linux' 카테고리의 다른 글

    What is inode  (0) 2023.02.20
    File addressing in Linux  (0) 2023.02.20
    How to remove directory in linux (rmdir)  (0) 2023.02.20
    How to create a file in linux (touch)  (0) 2023.02.20
    How to move file or directory in linux (mv)  (0) 2023.02.20
Designed by Tistory.