[Linux command] cat command option list [Must-see for beginners]

[Linux command] cat command option list [Must-see for beginners]

Summary Linux command list

What is the cat command?

This command outputs the file contents as standard. "cat" is an abbreviation for "concatenate". Since "concatenate" = "concatenate", it should be It may be more polite to say "concatenate file contents and output as standard" rather than "output file contents as standard".

How to use the cat command

/home/hoge


$cat target file

Cat command option list

option Description
-n Output with line numbers
-b blank(Blank line)Output with line numbers without
-s Output consecutive blank lines as one blank line
-E At the end of each line"$"Output with
-T Tab"^I"Replace with and output

-n option

Output with line numbers.

Without options

/home/hoge/test


$ cat test.txt
hoge
hogehoge

hogehogehoge



hogehogehogehoge

With the -n option, the output is as follows.

/home/hoge/test


$ cat -n test.txt
     1	hoge
     2	hogehoge
     3
     4	hogehogehoge
     5
     6
     7
     8	hogehogehogehoge
     9

-b option

Output with line numbers without blanks.

/home/hoge/test


$ cat -b test.txt
     1	hoge
     2	hogehoge

     3	hogehogehoge



     4	hogehogehogehoge

-s option

Output consecutive blank lines as one blank line

/home/hoge/test


$ cat -s test.txt
hoge
hogehoge

hogehogehoge

hogehogehogehoge

By the way, if you combine -s and -n ↓

/home/hoge/test


$ cat -ns test.txt
     1	hoge
     2	hogehoge
     3
     4	hogehogehoge
     5
     6	hogehogehogehoge
     7

-E option

Output with "" at the end of each line It's useful later when you replace "" with a comma to make an array.

/home/hoge/test


$ cat test.txt
hoge$
hogehoge$
$
hogehogehoge$
$
$
$
hogehogehogehoge$
$

-E option

Replace tab with "^ I" and output

In the following cases

/home/hoge/test


$ cat ex.txt
hoge
    hogehoge
        hogehogehoge

↓ It will be like this.

/home/hoge/test


$ cat ex.txt
hoge
^Ihogehoge
^I^Ihogehogehoge

Concatenated output of cat command

Output by concatenating multiple files. (Original cat)

/home/hoge/test


$ cat hoge.txt
hoge

$ cat hoge2.txt
hogehoge

$ cat hoge3.txt
hogehogehoge


$ cat hoge.txt hoge2.txt hoge3.txt
hoge
hogehoge
hogehogehoge

You can also create a new file that is concatenated.

/home/hoge/test


$ cat hoge.txt
hoge

$ cat hoge2.txt
hogehoge

$ cat hoge3.txt
hogehogehoge

#Create 3 files as superhoge
$ cat hoge.txt hoge2.txt hoge3.txt > superhoge

$ cat superhoge
hoge
hogehoge
hogehogehoge

List of options for other Linux commands

pwd, mkdir, cd , cat, cp, ls, touch, less, mv, rm, ssh, man, ** Adding at any time **

Advertising space

We undertake various development and construction contracts and mentor work for beginners. If you are interested, please go to ** here **

Recommended Posts

[Linux command] cat command option list [Must-see for beginners]
[Linux command] ls command option list [Must-see for beginners]
[Linux command] touch command option list [Must-see for beginners]
[Linux command] less command option list [Must-see for beginners]
[Linux command] pwd command option list [Must-see for beginners]
[Linux command] rm command option list [Must-see for beginners]
[Linux command] cd command option list [Must-see for beginners]
[Linux command] mv command option list [Must-see for beginners]
[Linux command] man command option list [Must-see for beginners]
[Linux command] ssh command option list [Must-see for beginners]
[Linux command] mkdir command option list [Must-see for beginners]
[Linux command summary] Command list [Must-see for beginners]
Linux command memorandum [for beginners]
[Must-see for beginners] Basics of Linux
Linux command list
Linux operation for beginners Basic command summary
Linux command for self-collection
What is Linux? [Command list]
Linux distribution recommended for beginners
Linux Command Dictionary (for myself)
Python #list for super beginners
Convenient Linux shortcuts (for beginners)
Frequently used Linux commands (for beginners)
Linux command # 4
Linux command # 3
Linux command # 5
How to create a shortcut command for LINUX
linux at command
[Linux] Search command
Roadmap for beginners
Linux command <Basic 2>
Linux [directory command]
Linux server command
Linux # Command Memo 1
Linux command [read]
Linux Command Summary
[Basic] linux command
Linux [shell command]
[Linux] Command / Knowledge
pyenv for linux
My linux command
Linux command <Basic 1>
Linux command collection
Linux mkdir command
Linux command basics
[Linux] Git command
Linux (command memory)
[Linux] A list of Linux commands that beginners should know
[For beginners] How to use say command in python!
[Linux] Basics of authority setting by chmod for beginners