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 filetouch /var/rex.red/file1>file
Simply created an empty file with the name you write.
>fileor in a directory
>/var/rex.red/test4echo
You can also add text with echo but this creates a new empty file.
echo -n >file
echo >/var/rex.red/fileprintf
Same idea as with echo but using prinf if you prefer it like this.
printf ''>fileCreate 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' > fileprintf
printf 'file contents\ntest\n' > filels > file
ls -lh /var/log/ > logfilescat >
cat file1 > file2vim
Create the file and edit it. Insert key – When finished save it :wq to save and exit vim.
vim file1 









Leave a Reply