Princeton University Library Princeton University Library

Search DSS





Finding Data Analyzing Data Citing data

About Us


DSS lab consultation schedule
(Monday-Friday)
Sep 1-Oct 16By Zoom appt. here
Oct 19-Dec 4Virtual Zoom Walk-ins
Dec 7-Jan 31By Zoom appt. here
Feb 1-April 30Virtual Zoom Walk-ins
May 3-Aug 31By appt. here
For quick questions email data@princeton.edu.
*No appts. necessary during walk-in hrs.
Note: the DSS lab is open as long as Firestone is open, no appointments necessary to use the lab computers for your own analysis.

Follow DssData on Twitter
See DSS on Facebook
Home Online Help Unix Unix Commands

Common Unix Commands


Working with Files

ls [directory]


To list the contents of the current directory issue the ls command with no operands:
	ls
To list all the files and sub-directories in some other directory, type the command ls immediately followed by the name of the directory. For example:
	ls  soc453
will list all the files in the soc453 directory.
You can also use options to make ls give you more information. One useful option is ls -l, which will tell you, among other things, how large the files are and when they were last edited. So, if you want to list all the files in the current directory and see how large they are, you would type:
	ls  -l
Another option is ls -F which will place a "/" after any directories, making them easier to distinguish from regular files.

cp [fromfile] [tofile]


Copies a file from fromfile to the second, tofile. For example, to copy a file, soc.data, to another file, psy.data:
	cp  soc.data  psy.data 
You can also copy a file from one directory to another For example, issue the following command to copy a file from temporary storage to the current working directory:
	cp  /scratch/tempdir/big.dta  big.dta 


rm [filename]
Erases the specified file. The system will ask you if you want to remove the file. For example, if you type:
	rm  soc.data 
The system will respond with:
	Remove soc.data?
You can type y if you do want to remove the file or n if you do not.


mv [fromfile] [tofile]


Moves the first file, fromfile to the second, tofile. The move command will erase the original file, leaving only one copy of the file. When you use the copy command (cp), by comparison, you will have two versions of the file, the original and the copy.


find [dir] -name "[filename]" -print


If you know the name of a file but not where it is, cd to your home directory (cd ~) and use
	find . -name "filename.txt" -print
This will search all the directories below your home directory for filename.txt. If you only remember a part of the file name, try
	find . -name "*filenamepart*" -print
You must include the double quotes.
If you are looking for a file that contains a specific chunk of text, you can combine find with the grep command, which searches through a group of files looking for a specific sequence of characters. To search through all the files in your current directory, use
	grep -i "phrase to find"  
To search through all the files in your account, cd to your home directory and type
	grep -i "phrase to find" `find . -name "*" -print` 
The command 'find . -name "*" -print' finds all the files in or below your current directory, and the backquotes send those files to the grep command.


Working with Directories

Files on UNIX are stored in directories. These are much like the directories on a PC or folders on a Mac. When you log on to your UNIX account, you are placed in your "home directory." Within your home directory you can have other directories, called "sub-directories." These sub-directories can also have other directories within them.

Directories make organizing your files easy. You can put all of your data files in one directory and all your programs in another, or, you can have a directory for each class you are taking. The term "path" is often used to refer to directories and their subdirectories.

pwd
The command pwd will tell you where you are witihin a directory structure.


cd [directory]


Use the cd command to change into the specified directory. The command cd without specifying any directories will bring you back to your home directory, and cd .. will bring you back up to the next highest directory. For example, the following command:
	cd  soc453 
will make soc453 your current or working directory. If you give the ls command, you will see a list of files in that directory. Any new files you create will, by default, be created in that directory. If you issue the command:
     cd  ..
you will move up one level in the directory structure, to what is called the parent directory. In this example, the parent directory would be your home directory. You can return to your home directory at any time by issuing the cd command with no operands:
     cd


mkdir [directory]


The command mkdir will make (create) the specified directory. For example, issue the following command to make a directory named thesis within the current directory.
	mkdir  thesis
Or issue the following command to make a subdirectory named programs with the directory soc453:
	mkdir  soc453/programs 


rmdir [directory]


The command rmdir will remove (erase) the specified directory. The directory must be empty of files or other subdirectories before it can be removed.


Printing

Before printing, you must determine which printer you want to use; not all printers are capable of printing from UNIX. Also, check the size of the file before you print it to avoid uneccesary use of paper and toner. To see a list of available printers, issue the command:

        printers  -L  |  more 

This will give you a list of printers and their locations, as well as the alias by which you can refer to them. Once you have identified the printer you want to use, issue the lpr command

        lpr  -P  [printeralias] [filename]

where printeralias is the alias for a printer and filename is the name of the file you would like to print. For example:

        lpr  -P  nslaser test.do

will print a file named test.do, to nslaser, a printer in New South Building.


Quotas

Your UNIX account has a certain amount of space in which you can store files. The following command will show you how much space you are given ("quota") and how much you are currently using ("usage").

        quota -v

Running out of space is a common reason why you cannot create, copy or transfer new files into your account. Files created or modified when you are at or over your quota may be corrupted! There is a buffer space (the difference between your quota and your "limit"). However, this is small and only temporary. If you do not clear space that is over your quota, you will lose files. See below for solutions if you need more space.


Temporary Storage and Extra Space

Sometimes you may need extra space for just a short time, say to edit a very large file. You can access temporary storage in the /scratch directory. To do this, simply issue the command:

        mkdir  /scratch/[userid] 

where userid is your userid. Be sure to use the slash (/) in front of scratch.

Now you can cd to this new directory and work with files in it just as you would in your own account. The system automatically erases files in the scratch directory 24 hours after they were last modified, so be careful not to leave anything important there.

If you find that you need more space on a permanent basis, then you can apply for a larger quota. Although there is a charge involved, academic departments will pay it for students who require the space for their research. See your department's undergraduate or graduate secretary. You can pick up the application at OIT (87 Prospect Ave) then get your department to authorize it.


Text Editors

There are several text editors available on UNIX. Among these are vi, emacs, and pico. Which one you use is a matter of personal preference. Try each and see what suits your needs best. Pico is similar to the editor used in the mail program, Pine, so if you already use Pine, Pico may be a good choice.


Help

You can get help on any command in UNIX by using the following command:

     man [command]

where command is the command with which you need help. For example, to get information on the copy command, cp, your would type:

     man cp

If you do not know the command you want you can type

     man -k [keyword]

where keyword is a topic rather than a specific command. You can also use the Internet to look up UNIX man pages.


Resources


This page last updated on: