1. Home
  2. Linux
  3. Linux Files
  4. Linux – cat

Linux – cat

Linux cat command

Linux cat command is used to display file content. You can also use this to create new files or copy file contents to other files.

Syntax:

$ cat file_name

Examples:

#1. Display File Content

For example use the following command to list content of /etc/passwd file.

$ cat /etc/passwd

Output:

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
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin

#2. Display Multiple File Content

You can also display the multiple file content in single command.

$ cat /etc/passwd /etc/group

#3. Display Line Numbers

Use -n switch to display the line numbers with results of cat command.

$ cat -n /etc/passwd

#4. Create New File

You can also create create files with cat command. Type command line below (change filename as per yours)

$ cat > myfile

Write your content here
and here
[CTRL+C] to exit

#5. Redirect file content to other file

You can use redirect operator with cat command to copy file content to other other.

$ cat sourcefile > otherfile

You can also copy multiple file content to other file.

$ cat sourcefile1 sourcefile2 sourcefile3 > otherfile
Tags , , ,
Was this article helpful to you? Yes 7 No
Advertisement