University of Southern California

ITS Information Technology Services

A division of the Office of the Chief Information Officer

File Commands

Creating and Editing Files

To create files, you should use a UNIX text editor such as pico, emacs or vi.

Listing Files

The see a listing of files and directories, you can use the following command:

common options:

-a List all entries; in the absence of this option, entries whose names begin with a "." are not listed.
-l List in long format, giving mode, number of links,owner, size in bytes, and time of last modification for each file.
-R Recursively list subdirectories encountered.
-F Mark directories with a trailing slash (/), executable files with a trailing asterisk (*) and symbolic links with a trailing at-sign (@).

For a full listing of the options available for use with the ls command, see the man pages. Type:

Removing Files

To remove a file, you can use the following command:

common options:

-i Interactive.With this option, rm prompts for confirmation before removing any write-protected files.
-r Recursively remove directories and subdirectories in the argument list. The directory will be emptied of files and removed.

Note: To delete a file starting with a "-", type rm - -<filename>

Viewing Files

To view files, you should use a pager such as more or less. Both commands will display the contents of the file, one screenful at a time. less, however, allows backswards movement within the file as well.

Copying Files

To make a copy of a file, you can use the following command:

common options:

-i Interactive. cp will prompt for confirmation whenever the copy would overwrite an existing target.
-r If filename is a directory, cp will copy the directory and all its files, including any subdirectories and their files; target must be a directory.

Moving and Renaming Files

To rename a file, you can use the following command:

common options:

-i Interactive. mv will prompt for confirmation whenever the move would overwrite an existing target.

Determining File Formats

To determine the format of a file, you can use the following command:

Comparing Files

To compare two files, you can use the following command:

Concatenating Files

To combine two or more files, you can use the following command:

This will concatenate homework1 and homework2, then write the results to homework3.

Last updated:
February 03, 2011

UNIX Documentation

The use of all USC computing resources is governed by the USC Computing Policies.