• Skip to main content
  • Skip to primary sidebar
  • Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / Linux sysadmin tutorials linux system administrator / Top 10 most used Cat commands with examples (create, view, append files)

Top 10 most used Cat commands with examples (create, view, append files)

cat (short for “concatenate)
Create,view,concatenate,
cat [OPTION] [FILE]…
main advantage with just command
It will create file &writes data. unlike
nano &vim editors.

Table of Contents

Toggle
  • #1 viewing content of file with cat command
  • #2  creating a file with cat command
  • #3 cat command reading file with line numbers & sorting
    • Display along with numbers of line
    • Display $ at the End of every line with -e option
      • Multiple Files at Once (semi colons required)
  • #4 Overwriting existing file with cat command
  • #5 appending at end of existing file with command ft ssh authorizedkeys
      • Redirecting Standard Input with Redirection Operator
  •  #6creating single file from multiple files
  • #7 Sorting Contents of Multiple Files in a Single File
    • #8 creating file & writing data cat eof to file
    • touch command only to create a file
    • Nano file editor
    • Vim editor
    • writting to files with echo command

#1 viewing content of file with cat command

cat /etc/passwd
To view content of multiple files
cat file1.txt file2.txt

#2  creating a file with cat command

a. cat >test2
b. Type text.
c. Then press ctrl+d to exit
example
Create a new file with the stub_status configuration.
step 1
cat > conf.d/stub_status.conf
step 2 past the text
server {
listen 127.0.0.1:80;
server_name 127.0.0.1;
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
}
step 3 exit
«Ctrl-D»
Step 4 verify the text & file
ls -la conf.d/stub_status.conf && cat conf.d/stub_status.conf

#3 cat command reading file with line numbers & sorting

sorting
cat file1.txt | more
cat file2.txt | less

Display along with numbers of line

cat -n filename

Display $ at the End of every line with -e option

cat -e test

Multiple Files at Once (semi colons required)

cat file; cat file1; cat file2

#4 Overwriting existing file with cat command

cat file > file1
existing contents of file1 will be overwritten by contents of file file.

Appending(Standard Output with Redirection Operator)

cat file >> file1
contents of file file will be appended at the end of file1 file.

#5 appending at end of existing file with command ft ssh authorizedkeys

1st step we created public & private keys.
private key on local machine.
public key should be added to
./ssh/authorized_keys
we may copy & edit nano command save it.
nano ./ssh/authorized_keys
sometimes we generate in remote machine
cat  publickey.pub >> ./ssh/authorized_keys

Redirecting Standard Input with Redirection Operator

cat < file2
Displays the file2 information on the terminal

 #6creating single file from multiple files

cat file file1 file2 > file3
all data in 3 files will be create  new file 3

#7 Sorting Contents of Multiple Files in a Single File

cat file file1 file2 file3 | sort > file4,
all the contents piped and sort and results will be an new file

#8 creating file & writing data cat eof to file

cat >/etc/nginx/sites-enabled/newserver.conf<<EOF
server {
listen 80;
root /var/www/html/;
server_name _;
include /etc/nginx/conf.d/global.config;
}
EOF

it will creates a file newserver.conf in the prescribed path.

2nd

it adds content to file with eof command in linux shell script.

EOF (end-of-file)

 

 

 

touch command only to create a file

touch newfile.txt
later you have to use vim or nano to edit.

Nano file editor

sudo nano newfile.conf
#configuration
#press ctrl+x and then y save changes.

Vim editor

sudo apt-get install vim
vim file.txt
Press i insert or edit,
press Esc and then :wq to save and exit.
e opens file
:W save
:q exit
:Wq  to save changes and exit
:q! Exit without changes
0 to mive cursor to the first line

writting to files with echo command

to create a file

echo > phpinfo.php

or

echo > /var/www/html/phpinfo.php

write/print the words to document

echo “phpinfo();” > phpinfo.php

 

 

Primary Sidebar

Linux sysadmin tutorials linux system administrator

  • top 10 apt & apt-get commands (most used) apt vs apt-get
  • If-Else Statements in Shell Scripting
  • linux commands pdf (files & Directories, zip & unzip process, search etc)
  • Find Files with Specific Text on Linux grep find command
  • linux performance tuning inode limit file descriptors tco, kernel etc
  • Variables and Data Types in Shell Scripting
  • Top 10 most used Cat commands with examples (create, view, append files)
  • Ip tables / ufw / firewall d commands for block port ip rate limiting
  • Top 10 zip / tar commands to compress & extract files in linux
  • TOP 10 mv & cp commands in linux to move & copy files in Linux
  • Top 10 GREP Commands in linux to search files directory words strings
  • lsof netstat commands to know listening ports in linux 3 ways
  • Upgrade Ubuntu from 18.04 (19.10) to 20.04 LTS command line or gui server | desktop
  • 3 Ways (SCP, rsync, Sftp) linux server migration between two remote server apache nginx
  • linux system specs commands (CPU, Memory, Disk )speed, type. manufacture
  • linux sysctl command tweaks & hardening
  • linux security limits.conf deciding user limits process limits for nginx server
  • ulimit linux unlimited command unlimto set & know user limits open files file descriptor max user process etc.
  • red hat linux certification cost jobs salary syllabus courses fees
  • ufw firewall commads allow port enable disable ubuntu 20.04
  • ddos attack prevention
  • change ssh port in linux - avoid sshd ddos attacks
  • ping command
  • memcached install ubuntu wordpress
  • check linux version (lsb_release -a) ubuntu debian 32 or 64 bit
  • rsync command linux with examples comparison to scp
  • how to uninstall package in linux ubuntu rpm, yum apt-get
  • increase open file limit linux File descriptor ft nginx , mysql, lemp
  • remove repository ubuntu
  • htop commad memory details virtual vs shard vs resident
  • chown command in Linux with Examples
  • Kill PHP process
  • VIrtual Memory vs RSS Memory vs Shared memory in Linux
  • oom killer fixing it by configuration linux ubuntu
  • Install Lemp nginx mysql php fpm Stack on Debian 11 with repository
  • connect two remote servers linux command line
  • auto start after oom killer Mysql & php fpm nginx etc ubuntu wth systemd or cron job
  • load average Linux 1, 5, 15 min 2,4,8 cores explained
  • Control Structures in Shell Scripting
  • Shell Scripting Roadmap for Beginners to Advanced
  • awk commands with practical examples
  • Shell Scripting Tutorial for Beginners 🚀
  • find Command in Linux with Examples
  • sed Command in Linux with Examples (Beginner to Advanced)
  • Linux Text processing commands in with Examples
  • linux disk management commands
  • fdisk command in linux with examples
  • how to add a new disk in linux
  • Linux mount Command with Examples
  • fstab options with examples
  • Top 50 Shell Scripting Interview Questions and Answers
  • Linux Networking Interview Questions and Answers
  • Linux Networking Commands Cheat Sheet with Examples pdf
  • Netstat & SS Commands cheat sheet with examples Interview Questions
  • Nmap Cheat Sheet – Network Scanning & Security
  • Bash Brackets ([], (), {}, $( ), $(( ))) – Types, Uses & Examples

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy