The ability to create files is a basic and essential function in any operating system. However, those who are new to Linux – especially its command-line – may struggle. Today's quick guide will remedy this, showing you how to quickly create a file in Linux using its terminal. We'll also be covering some common issues that may be preventing you from creating files.
The touch command: useful parameters
| Flag | What it does |
|---|---|
-a |
Updates only the access time, leaving modification time untouched |
-m |
Updates only the modification time, leaving access time untouched |
-c |
Prevents touch from creating a file if it doesn't already exist |
-d |
Sets a specific date/time instead of the current time, e.g. touch -d "2026-01-01" file.txt |
-r |
Copies the timestamp from another file, e.g. touch -r source.txt target.txt |
How to create an empty file in Linux
If you don't need to fill your file with content, the syntax for making a file in Linux is very simple. Both the touch command and cat work perfectly for this use case.
How to create a new file in terminal with touch
Creating a single, empty file with touch is simple:
touch yourfilename.txt
You can, of course, change the file name and extension to whatever you like.
You can also create multiple files in one command:
touch filename1.txt filename2.txt filename3.txt
How to make an empty file in Linux with cat
The cat command is primarily designed for reading and combining files, but you can use it to create them, too. For example:
cat > filename.txt
You can then press Ctrl + D to save the file.
How to create files in a specific directory
By default, touch, cat, and other file-creation tools make files in your current directory. To create files in a specific directory instead, you just have to specify the path before the file name.
For example:
touch ~/docs/yourfile.txt
Or, using cat:
cat > ~/docs/yourfile.txt
How to create a file with content using echo
You can quickly create files that contain text with the echo command:
echo i love bitlaunch > filename.txt
Or, if you want to create a file in a specific location:
echo i love bitlaunch > ~/home/documents/filename.txt
Creating a file with content using the cat command
Cat allows you to create a file with content in a slightly different way. Rather than typing the string in advance, you run the cat command, type your content, then save and exit with Ctrl +D. This gives you more intuitive control over formatting and so on.
cat > myfile.txt

Much like echo, you can specify a location with cat:
cat > ~home/documents/myfile.txt
Creating a file with formatted content using printf
echo is great at throwing a quick string of text into a file, and cat is good if you want a GUI approach. But if you want formatting and the ability to add specific spacing and tabs, or want to inject variables neatly, the printf command is the better choice.
To create a file and format the text inside it, use printf followed by your formatting string, your text, and the > redirection operator:
printf "User: %s\nID: %d\n" "Admin" 105 > user_info.txt
In this example, the formatting string acts as a template:
%sis a placeholder for a string ("Admin").%dis a placeholder for a number (105).\ncreates a new line.
You can see how this can become quite powerful for scripting. Just like the previous commands, you can easily direct this formatted output to a file in a specific directory:
printf "Status: %s\n" "Active" > ~/docs/status.txt
Renaming a file using the mv command
Once you've created a file, you can use the move command (mv) to quickly rename it:
mv oldfilename.txt newfilename.txt
This is useful if you made a spelling error, want to create a new file with the same name, change the file extension, and so on.
How to delete files
At some point, you'll need to clean up the files you created. The easiest and most universal way to do this in Linux is using the rm command.
Deleting a single file
To permanently delete a single file, run a command with the following syntax:
rm yourfilename.txt
You can specify the full path of the file before its name if it's not in your current folder.
Deleting multiple files
To permanently delete multiple files, separate them with a space:
rm filename1.txt filename2.txt filename3.txt
Common errors that prevent file creation
If you followed the guidance above but still can't create a file, the first thing to check is your permissions. You'll need write permissions on the file's parent directory to create a file there. If you do not have the relevant authority, you'll get a 'permission denied' error. Some directories require root privileges to create files in. You can follow our guide on Linux permissions to ensure they're correct.
Other possible issues include:
- Mistyping the name of the directory: This will return a 'No such file or directory error'
- A hardware issue: A physical fault in a drive may prevent new content from being written to it.
- Dual booting: You are dual booting but the Windows OS hasn't been completely shut down. Perform a full shutdown by holding the Shift key while pressing the shutdown button in your Start menu.
- The file system is incompatible: Linux prefers Ext4, XFS, Btrfs, and ZFS file systems.
Next steps
Now that you know how to create basic files, you can start using these commands in your scripts and workflows. Combining tools like printf with other commands in a bash script will allow you to do things like create log files based on your debugging output, or auto-generate config files during deployment.
Once file creation is second nature, the next step is to script these commands with cron jobs or shell scripts to automate repetitive tasks on your server.
Found this guide interesting? Learn to base64 encode a file in the Linux CLI.
FAQs
How do I create a file with nano?
To create a file with nano, run nano yourfilename.txt, type the content you want, and then press Ctrl + O followed by Ctrl + X to save and exit.
How do I create a file with vi/vim?
Open or create the file with vi filename.txt, press i to enter insert mode and type your content, then press Esc followed by :wq to save and quit. You can learn more in our dedicated how to use vim guide.
How do I create a folder in Linux?
The easiest and most universal way to create a folder in Linux is the mkdir command. For example: mkdir ~/docs/newfolder. You can pair this with file creation command such as touch if you wish: mkdir ~/docs/newfolder && touch file.txt.
What's the difference between Windows and Linux when creating files?
Linux organizes files under one root directory (/) and lets you create them anywhere you have write permissions using touch, cat, printf etc. Permissions on Linux are controlled via simple read/write/execute bits using chmod and it supports several filesystems, including ext4, xfs, and zfs.
Windows uses drive letters such as C:\, and has a greater emphasis on creating files through a GUI application. Much like Linux, Windows can use echo to create files, but using New-Item via PowerShell is also common. Permissions are more complex and managed through access control lists, while the filesystem is NTFS or, more rarely, FAT32.