Cat command in Linux with examples

Configurare noua (How To)

Situatie

Cat (concatenate) command is very frequently used in Linux. It reads data from the file and gives its content as output. It helps us to create, view, and concatenate files. So let us see some frequently used cat commands.

Solutie

Pasi de urmat

So let us see some frequently used cat commands.

1) To view a single file

Syntax:

cat file_name

Example: If our file_name = jayesh.txt

Note: `ls` command is used to display all files and directories in the current location.

2) To view multiple files

Syntax:

cat file_name1 file_name2

Example: If we have two files , file1 and file2.

cat file1 file2

3) To view contents of a file preceding with line numbers.

Syntax:

cat -n file_name

Example: If our file_name is file2.

cat -n file2

4) Create a file and add content 

Syntax:

Example: If we want to create a newfile_name = jayesh1.

cat > jayesh1
ls

`ls` command is used to display all files and directories in the current location.

Tip solutie

Permanent

Voteaza

(2 din 5 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?