How to create and edit files on a Linux VPS/Server

Once you are navigated to the newly created directory, create your first file using the touch command.

touch new_file

The command above will create an empty file named new_file and you can use that file for testing purposes. To edit the file and add some content to it you can use a text editor. There are many text editors which you can use, but nano is very suitable for beginners. Our recommendation is to use nano as an text editor to modify your files until you become more familiar with the others. In case you do not have nano installed on your system, you can use the command below to install the program:

On a CentOS VPS:

sudo yum install nano

On a an Ubuntu VPS:

sudo apt-get install nano

Now, to open and edit the file you have previously created you can use the following command:

nano new_file

Enter some random text:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Illud dico, ea, quae dicat, praeclare inter se cohaerere. Nam aliquando posse recte fieri dicunt nulla expectata nec quaesita voluptate.

To save and close the file you should press CTRL + X and then Y. In case you do not like to save the changes you should press N after CTRL + X.

Now that you have a test file with content on your server, lets see the content. There are many methods to see the content of a file, but by far the easiest method is to use the cat command.

cat new_file

Using the cat command you can do many other things. For example, using the cat command you can concatenate multiple files together or append text to an already existing file. For more information you can read the Linux man page for cat.

If you like to remove the file you created and used for testing purposes, you can use the rm command. The basic syntax is:

rm new_file

Once you execute the command you will be prompted to confirm that you like to remove the file. You can confirm by pressing Y. If you changed your mind, press N.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Directory and File Structure - Linux

Directory/Folder StructureFrom amongst the several directories found within your cPanel account,...

PHP Parse error: syntax error, unexpected $end

This error is typically caused by a missing } used in PHP to denote content belonging to a WHILE,...

How to drop tables from a database in phpMyAdmin?

This article will demonstrate how to drop (permanently delete) tables from a database in...

Optimizing Magento

Magento is a very popular eCommerce application. It offers a great deal of customization and...

Optimizing Joomla

Joomla is a popular CMS that is highly extensible and customizable. The following are suggestions...

Powered by WHMCompleteSolution