iT邦幫忙

0

16 cat Command Examples in Linux (The Complete Guide)

  • 分享至 

  • xImage
  •  

Today I have brought a handy command for you, and that is the cat command.

‘cat‘ stands for “Concatenate“.

Whether you are a beginner or an expert in Linux, this is the most frequently used command for all.

**Key features of cat command

  • Create a File
  • Concatenate Files
  • Combine Binary files
  • Display contents of a File
  • cat command can be used in conjunction with other commands such as head, tail, more, less.
  • Print Files
  • Can display useful system information such as CPU Information, Memory Information, etc.

The cat command was launched in the Unix operating system and was written by Torbjorn Granlund and Richard M. Stallman.

In this article, I will teach you about the complete features of cat command.

We can use the following Redirection operators with cat command:

> : Redirection of output
>> : Appends output to the specified file
< : Redirection of input
| : Pipe

Syntax:

You must follow the syntax given below to use the cat command.

cat [OPTION]... [FILE]...

1. Create a New file
To create a new file, you must combine the Redirection of output (>) operator with the cat.

Syntax:

~$ cat > [File Name]

Refer to the following example.

~$ cat > test.txt

After running the above command, it will allow you to type the text you want to store in the test.txt file.

After typing, press the CTRL + D (Hold the CTRL button and then press D) button on your keyword to save the file.

2. Display contents of a File

You can display the contents of a file using cat.

To do this type the following command.

~$ cat week.txt 
Monday
Tuesday
Wedneswday
Thursday
Friday
Saturday
Sunday

OR you can mention the path of the file.

~$ cat data/file1.txt 
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
whoopsie:x:112:117::/nonexistent:/bin/false

3. Display contents multiple Files

You can also display the contents of multiple files.

Here I have two files named months.txt and week.txt. Run the following command to display the contents of these files.

~$ cat months.txt week.txt 
January
February
March
April
May
June
July
August
September
October
November
December
Monday
Tuesday
Wedneswday
Thursday
Friday
Saturday
Sunday

Read Complete Article Here


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言