Create/Edit files and folders using SSH cmd line

There are various ways you can create a new file using the SSH command line.

The easiest and most common way is to use the command assigned for this task – touch. For example, if you would like to create a new file called .htaccess you would need to type the following line:

touch .htaccess

The command also accepts several arguments, which for example can instruct the OS to edit the modified date of already existing file. For more information you can check the manual page for the command by typing ‘man touch’.

In order to edit the newly created file, you should use a file editor. The most commonly used are vi and pico (aka nano).

We will try using pico, since it is easier than vi. To request the file to be opened in pico, type:

pico .htaccess

You can type text directly into the window. To save and exit the interface, you would need to send <ctrl + x> key combination.

To create a new directory, please use:

mkdir myDirectory

where you should replace the myDirectory string with the name of your folder.


  • 21 Users Found This Useful
Was this answer helpful?

Related Articles

List files and directories using SSH

In order to list all files and directories using an SSH client, you would need to execute the...

Move and copy files using SSH

Often you will need to move one or more files/folders or copy them to a different location. You...

Deleting files and folders via SSH

Sometimes you would need to remove a file or a folder from the system. To do so using SSH, you...

Extracting and creating archive files via SSH

Sometimes you would need to extract or create an archive file (i.e to install a script, you would...

Searching for files/text using SSH

In some cases you would need to find the location of a given file or to search for a certain text...