Linux Tip: Create and Append to Temporary File Without Editor

terminal-logo-smallThis is a very typical case, the need to create a temp file on the command line quickly. Opening editor, writing content, save file and quit editor is not the fastest possible way. A faster way is to use the cat command with the name of the file and write contents of the file and give the end-of-file character (Ctrl-D).

Create Temporary File Without Editor on Command Line

# Create file
$ cat > /tmp/temp_file_name.txt
some content
more content
and even more content
<Ctrl-D>
 
# View file content
$ cat /tmp/temp_file_name.txt
some content
more content
and even more content

Append to Temporary File Without Editor on Command Line

# Append to file
$ cat >> /tmp/temp_file_name.txt
append content
append more content
append even more content
<Ctrl-D>
 
# View file content
$ cat /tmp/temp_file_name.txt
some content
more content
and even more content
append content
append more content
append even more content

Very easy, quick and usefull!

Related posts:

  1. Linux Tip: How to handle a files with a dash as first character from command line Sometimes you maybe have to handle files with a dash (-) as first character from Linux command line. It can...
  2. Delete files securely on Linux – Journaled file systems Few days ago I write about shred, which work fine for old systems, like EXT2, but not so nice with...
  3. Tuning Nano text editor with nanorc Nano is easy to use and lightweight command line text editor for Linux and UNIX systems. Nano text editor can...
  4. Linux locate command: Find Files and Directories Quickly and Efficiently This is quick guide howto find files and directories quick and efficiently on Linux with locate command. Linux find command...
  5. Add Hostname, Date, Time, Uptime, Load Average to Linux Terminal Title This tip is really useful if you need/want to monitor multiple servers at the same time. This Tip works, as...

About the Author

Hi, I'm JR and the Founder of if not true then false. I am a software developer, and I have over ten years experience in programming. I'm big fan of Linux and Open Source. And normally I use just Linux environments. - You can follow me on Twitter at @zuissi