Command to create new file in linux
In Linux, you can create a new file using the following commands:
-
touch
command:touch filename.txt
This will create a new empty file named
filename.txt
. -
echo
command:echo "Hello World" > filename.txt
This will create a new file named
filename.txt
and write the text "Hello World" to it. -
cat
command:cat > filename.txt
This will create a new file named
filename.txt
and allow you to type text into it. PressCtrl+D
to save and exit. -
nano
editor:nano filename.txt
This will open the
nano
editor and allow you to create a new file namedfilename.txt
. You can type text into it and save it by pressingCtrl+X
, thenY
, thenEnter
. -
vim
editor:vim filename.txt
This will open the
vim
editor and allow you to create a new file namedfilename.txt
. You can type text into it and save it by pressingEsc
, then:wq
, thenEnter
.
Note: Replace filename.txt
with the desired name of your new file.