What's the easiest way to create a file in Linux terminal?
相关问题
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- how to get running process information in java?
- JQ: Select when attribute value exists in a bash a
- Spring Integration - Inbound file endpoint. How to
This will create an empty file with the current timestamp
Also, create an empty file:
There are several possible solutions:
Create an empty file
The
echo
version will work only if your version ofecho
supports the-n
switch to suppress newlines. This is a non-standard addition. The other examples will all work in a POSIX shell.Create a file containing a newline and nothing else
This is a valid "text file" because it ends in a newline.
Write text into a file
These are equivalent. The
$EDITOR
command assumes that you have an interactive text editor defined in the EDITOR environment variable and that you interactively enter equivalent text. Thecat
version presumes a literal newline after the\
and after each other line. Other than that these will all work in a POSIX shell.Of course there are many other methods of writing and creating files, too.
Create the file using
cat
$ cat > myfile.txt
Now, just type whatever you want in the file:
Hello World!
CTRL-D to save and exit
Depending on what you want the file to contain:
touch /path/to/file
for an empty filesomecommand > /path/to/file
for a file containing the output of some command.nano /path/to/file
orvi /path/to/file
(orany other editor emacs,gedit etc
)It either opens the existing one for editing or creates & opens the empty file to enter, if it doesn't exist
Simple as that :
> filename