How to create a file in Linux using Terminal or SSH
How to create a file in Linux using Terminal, Command line interface or SSH.
There are a few ways to create a new empty file or redirect the output of a command to a new file. To create an empty file, any of these commands can accomplish that without having to install any extra packages or modules.
touch
Touch creates an empty file in the path you specify. Easy
touch file
touch /var/rex.red/file1
>file
Simply created an empty file with the name you write.
>file
or in a directory
>/var/rex.red/test4
echo
You can also add text with echo but this creates a new empty file.
echo -n >file
echo >/var/rex.red/file
printf
Same idea as with echo but using prinf if you prefer it like this.
printf ''>file
Create file from text output
Create non-empty file
If you need to save a file but with contents it’s still pretty easy.
echo
echo 'file contents' > file
printf
printf 'file contents\ntest\n' > file
ls > file
ls -lh /var/log/ > logfiles
cat >
cat file1 > file2
vim
Create the file and edit it. Insert key – When finished save it :wq to save and exit vim.
vim file1
Related Guides and Helpful Resources
If you found this guide helpful, check out these related step-by-step tutorials and category resources on ION HowTo:
- How to Replace AC Remote Batteries with a Ballpoint Pen: Lever out stubborn AAA batteries from deep remote slots without tools.
- Clean USB-C Port with Paper: Simple household trick to clean lint and debris from loose charging ports safely.
- IKEA KOPLA B22 to E27 Socket Converter Guide: Convert older UK bayonet lamp fittings to fit modern screw-in LED bulbs.
- DIY Hacks and Life Solutions: Explore our full collection of tutorials and step-by-step articles in this category.

Leave a Reply Cancel reply