Search Socrates Help Pages:

Basic UNIX File Manipulation

Below is some information on the basic usage of simple UNIX file manipulation commands.


More detailed instructions can be found through the manpages on Socrates. Please see the Man Page help document for more details.


Listing your files

In order to get a listing of your files you need to use the ls command. Your files are organized in directories. Directories are like a hierarchy of folders, each containing files and/or subdirectories. Below are some examples:
        socrates% ls
        Mail            News            bin
        dead.letter     public_html     test
        socrates%

A nicer way to view this would be to add the -F flag to ls. This produces a listing like this:

        socrates% ls -F
        Mail/           News/           bin/
        dead.letter     public_html/    test*

Here, the trailing "/" denotes a directory, a plain name like "dead.letter" is a regular file, and files followed by * are executable (like "test").


Changing between directories

To change from directory to directory, you use the cd command. To use it, you need to tell it which directory to change to. So if you want to change to the directory "bin" (as shown above), you need to type cd bin at the prompt. Typing cd by itself brings you into your home directory. The command cd .. brings you into the parent directory of your current directory (one level back). To see what directory you are currently in, use the pwd command.
        socrates% pwd
        /user2/userid
        socrates% cd bin
        socrates% pwd
        /user2/userid/bin
        socrates% ls -F
        foo*            test2*          dir1/
        socrates% cd ..
        socrates% pwd
        /user2/userid
        socrates% cd bin	
        socrates% pwd
        /user2/userid/bin
        socrates% cd
        socrates% pwd
        /user2/userid


Copying Files

The UNIX copy command is cp.

Example:

        socrates% pwd
        /user2/userid
        socrates% ls -F
        Mail/           News/           bin/
        file1           memo
        socrates% cp memo letter
        socrates% ls -F
        Mail/           News/           bin/
        file1           letter          memo 

A copy of "memo" has been made in the file "letter".

Moving (renaming) Files

The move command is mv.

Example:

        socrates% pwd
        /user2/userid
        socrates% ls -F
        Mail/           News/           bin/
        file1           letter          memo 
        socrates% mv file1 updates
        socrates% ls -F
        Mail/           News/           bin/
        letter          memo            updates
"File1" has been renamed to "updates".

Removing Files

To remove files, you use the rm (remove) command. To remove directories, you use the rmdir (remove directory) command. You simply need to tell rm the filename or rmdir the directory name you want to remove. Conversly, to create directories, you use the mkdir command, giving it an argument of the name of the directory you want to create.

Examples:

        socrates% pwd
        /user2/userid
        socrates% ls -F
        Mail/           News/           bin/
        dead.letter     public_html/    test*
        socrates% rm test
        socrates% ls -F
        Mail/           News/           bin/
        dead.letter     public_html/
        socrates% mkdir junk
        socrates% ls -F
        Mail/           News/           bin/
        dead.letter     public_html/    junk/
        socrates% rmdir junk
        socrates% ls -F
        Mail/           News/           bin/
        dead.letter     public_html/

Please be careful with the files you remove. Once removed, they cannot be recoverred except from back-ups. Removing some special files may affect your environment and the operation of some programs. Also be careful with the use of wildcards. The most common wildcards are * and ?. The wildcard * matches any number of characters. So for example, using "w*g" will match: "wig", "wag", "wallawag", "wowthisisareallylongfilenameg", and so forth (basically any filename beginning with a "w" and ending with a "g". The ? wildcard matches any single character. So "w?g" matches: "wig", "wag", "wfg", etc... Some examples are below:

        socrates% ls
        wig     wag     wollog  wowthisisgreatg
        blah    junk    foo     bang
        socrates% ls w?g
        wig     wag

        ( This is tricky: any number of characters 
          followed by an "o" and one other character. )
        socrates% ls *o?                
        wollog  foo
        socrates% ls *g
        wig     wag     wollog  wowthisisgreatg
        bang    


Please send comments to: calweb_consult@berkeley.edu. For additional questions, see Questions.
Last updated 23 July 1998.