File Manipulation

ls

This program produces directory listings. If you provide no arguments, it assumes you want to see everything in the working directory. If you give it a filename argument, it produces information on just that file. If you give it a directory name argument, it produces information on all the files in that directory.

For example:

$ ls
$ ls afile.txt
$ ls subdir
$ ls *.c
cp

This program copies files. If the last argument is the name of a directory, cp will copy all the specified files into the specified directory. If the last argument is the name of a file, the first (and only other) argument is the name of the source file.

For example:

$ cp afile.txt bfile.txt
$ cp afile.txt bfile.txt subdir
mv

This program moves files. Rather than copying the file and then deleting the source, this program just updates the directories. The file itself is not touched. This is a much better way to move a file.

Its command syntax is similar to that of cp. If the last argument is not the name of a directory, mv assumes you are trying to rename the file.

For example:

$ mv afile.txt bfile.txt      # Renames afile.txt
$ mv afile.txt subdir         # Moves afile.txt
ln

This program links a file into a directory. Unix allows a file to appear in several subdirectories at once. You can use ln to create such additional directory entries for a file.

Its command syntax is similar to that of mv. If the last argument is not the name of a directory, ln assumes you are linking the file into a new name.

For example:

$ ln afile.txt bfile.txt      # bfile.txt is afile.txt
$ ln afile.txt subdir         # Link to subdir/afile.txt
rm

This program deletes files. Actually, rm removes a link. If the link removed was the last link to the file, the file is deleted from the disk. Thus if you've linked a file into several directories, it must be removed from all such directories before it is actually removed from the disk.

For example:

$ rm afile.txt bfile.txt
cat

This program displays the contents of a file to the terminal. It is similar to the Windows type command. You can also use it to create small files without bothering with an editor.

For example:

$ cat afile.txt               # Look at afile.txt
$ cat >afile.txt              # Create afile.txt
more

This program also allows you to look at the contents of a file. However, unlike cat, it will page the display instead of just scrolling it as quickly as possible. The more command is a much better program to use when you want to see something.

The more is often used at the far end of a pipe to make looking at the output of the previous commands easier.

For example:

$ more afile.txt              # Look at afile.txt
$ ls -l | more                # Look at ls -l's output.

The more has many interesting features. Type the 'h' key when it is paused to see its help screen.

Most modern systems (and all Linux systems) have a related program named less (think: "less is more"). The less is a more powerful version of more with many additional features. Some people use less exclusively and never use more.