Working With FilesIncluded on this page:
- File Names
- Create a File With a Text Editor
- List Your Files
- Copy a File
- Change the Name of a File
- View a File
- Delete a File
One of the most important skills in any computer system is knowing how to work with files. A file is a collection of characters that the operating system treats as a unit. Files can store any information you want to save. For example, files can contain text for letters and email messages, code for programs, or data for calculations. After you create a file, you can add material to it, delete material from it, or remove it from the system.
/ \ " ` ' * | ! ? ~ $ < > &
File names may be between 1 and 255 characters long, but you will find that short, descriptive names are easiest to use. File names should not contain spaces. Instead of spaces, use underscores or periods to separate names made of multiple words, as follows:
mail.Jan annual_report unix_tips
Also, Unix distinguishes between uppercase and lowercase letters. For example, Unix would treat these as three different files:
project1 Project1 PROJECT1
- Pico is easier to learn and use.
- Pico contains online help text and lists the most commonly used commands at the bottom of each screen.
- Pico is designed for worry-free exploration.
To create a new file using the Pico text editor, enter:
Note: the p in the pico command is lowercase.
This starts the Pico text editor and opens a blank file. Pico assigns to that file the name you specify. Use your keyboard to add text to the file.
To save a file and exit the Pico text editor:
- Press <Control>x
This means hold down the Control key, while you press the x key.
- In response to the question:
Save before leaving (y/n)?
- In response to the prompt:
Filename to write:
Press <Return> or enter a new name.
To re-open and edit a file with the Pico text editor, enter:
Where file is the name of the file you want to edit.
To create a file named
This starts the Pico text editor with the file sport.quote. Add to this file the following lines of text:
It ain't over till it's
When you finish typing, save and exit sport.quote using the three steps that precede this example.
To re-open and edit sport.quote, enter:
Your list might resemble the following:
mail murphy.law phone.dir sport.quote
For more on the ls command, see List the Contents of a Directory
cp file1 file2
This creates a copy of file1 and names it file2.
To copy a file to a different directory, enter:
cp file directory
This creates a copy of the file you specify in directory the you specify.
For more information on directories, see Working With Directories.
mv file1 file2
This changes the name of file1 to file2.
This starts the more program, which lets you view the file you specify one screen at a time. Use <Spacebar> to scroll forward one screen, <Return> to scroll forward one line, and q to quit the more program. To search for a word in the file, type / followed by the word and then press <Return>.
This permanently removes the file you specify. A safe way to give the rm command is with the -i option. With the -i option, you are prompted before a file is permanently removed.
To require a prompt before a file is deleted, enter:
rm -i file
In response to the prompt, enter y to remove the file or n to keep the file.