PDF download Download Article
Learn the command to save in Vi or Vim and more
PDF download Download Article

This wikiHow teaches you how to save different types of files from the Linux command line. If you're using an app that has a graphical user interface (GUI), saving files is easy—you'll usually just need to click the File menu and select Save. Read on to learn how to save files in command line text editors, how to save the output of a command, and how to save an existing file to a new file.

How to Save Files from the Linux Command Line

To save file with the Linux Command Line, use the command :w. Press Enter to save the file. Type :q and press Enter to quit Vi or Vim and return to the command line.

Method 1
Method 1 of 3:

Saving a Text File in Vi or Vim

PDF download Download Article
  1. If you want to edit an existing text file, just type vi filename at the prompt and press Enter. To create a new file, just type vi and press Enter. Vi and Vim both automatically open up in Command mode.
    • If you're using Vim, replace vi with vim.
    • The text editors Vi and Vim have most of the same functions, although vim is a bit more verbose and includes color highlighting.
  2. This puts you into Insert mode, which is how you can type into the file.
    Advertisement
  3. Make any changes you need while in insert mode.
  4. Now you'll be able to use Vi or Vim commands, including the command to save.
    • You can use this key to switch back and forth between Command and Input modes.
  5. You can skip entering the file name if you're editing an existing file and want to save your changes to that same file.
    • For example, if you're editing a file that already has a file name and want to save the changes you've made, type :w and press Enter. But if you're editing a brand new file and want to call it wikiHow, you'd use :w wikiHow instead.
  6. This exists Vi (or Vim) and returns you to the command line.
  7. Advertisement
Method 2
Method 2 of 3:

Saving the Output of a Command

PDF download Download Article
  1. Don't press Enter to run it just yet—simply type the command first.
    • For example, if you want to list the contents of the current directory and save the output to a new file, you could type ls -a now.
  2. Using the prior example, your command would now look like this: ls -a >.
    • If you want to append the output to an existing file, use >> instead of >.
  3. If you wanted to save the results to a file called filelist, the command would look like ls -a > filelist.
    • If you're appending the output to an existing file, you'd use ls -a >> filename.
  4. This creates a file in the current directory called filelist that contains the output of the ls -a command.
  5. Advertisement
Method 3
Method 3 of 3:

Copying a File to a New File

PDF download Download Article
  1. For example, if you want to copy a file from /home/wikiHow/personal to a new file, you'd type cd /home/wikiHow/personal and press Enter.
  2. This saves Just make sure a file with the new name doesn't already exist, as it will be automatically overwritten, if so.
    • For example, if the file you want to copy is called Staff.txt and you want to save it as a new file called Staff-old.txt, you'd type cp Staff.txt Staff-old.txt and press Enter.
    • If you want to keep the file name but save the file to a new folder (for example, /home/wikHow/backups), you'd use cp Staff.txt /home/wikiHow/backups.
    • If you want to copy the file to another folder and give it a new name, you'd use cp Staff.txt /home/wikiHow/backups/Staff-old.txt.
  3. Advertisement



Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Tips

Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!

You Might Also Like

Install Google Chrome Using Terminal on Linux
Linux How to Mount Drive Mount Drives on Linux: Command Line & GUI
Can Linux Run ExeCan Linux Run .exe Files? How to Run Windows Software on Linux
Use Wine on Linux Install and Use Wine on Linux
Tar a Directory Tar a Directory and Subdirectories in Linux
Take a Screenshot in LinuxTake a Screenshot in Linux
Become Root in LinuxBecome Root in Linux
Execute INSTALL.sh Files in Linux Using Terminal Run an INSTALL.sh Script on Linux in 4 Easy Steps
Add or Change the Default Gateway in LinuxAdd or Change the Default Gateway in Linux
Install DebianEasy Debian Linux Installation Tutorial
Run Files in LinuxRun Files in Linux
Execute .RUN Files in LinuxExecute .RUN Files in Linux
Boot Linux from a USB on Windows 10 Run Linus from a USB: Making a Bootable Stick and Installing
Unrar Files in Linux Open RAR Files in Linux using Unrar
Advertisement

About This Article

Nicole Levine, MFA
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. This article has been viewed 61,463 times.
How helpful is this?
Co-authors: 3
Updated: November 15, 2024
Views: 61,463
Categories: Linux
Article SummaryX

1. Type "vi" and press Enter.
2. Type i to enter Insert mode.
3. Edit your file.
4. Press Esc.
5. Type ":w" and press Enter.

Did this summary help you?

Thanks to all authors for creating a page that has been read 61,463 times.

Is this article up to date?

Advertisement