Unix Commands

List of commands covered in this document

cal display a calendar

To display a calendar: 

cal [month] [year] displays a calendar for integer month and integer year, if specified.

Example 1: cal 12 1998 displays a calendar for December, 1998

Example 2: cal 1998 displays a calendar for 1998

Example 3: cal displays a calendar for the current year.

cat display or join files

To display or join files:

cat file1 displays a copy of file1 on the screen.

Example 1: cat Bank.java displays Bank.java on the screen.

Example 2: cat Bank.java Account.java displays Bank.java and Account.java on the screen.

Example 3: cat Bank.java Account.java > assignment concatenates (joins) Bank.java and Account.java and redirects the output to the file assignment. i.e. a new file is created which contains both Bank.java and Account.java

cd change directory

cd dir changes the current directory to dir

Example 1: cd ECR/Bank changes the current directory to ECR/Bank

Example 2: cd .. changes the current directory to the parent directory.

Example 3: cd changes the current directory to the home directory no matter what the present working directory.

chmod change permissions of a file or directory

chmod who operation permissions file/directory adds or deletes permissions on a file or directory for various groups of users.

who :

u - owner of the file

g - group to which the owner belongs

o - all other users

a - all users

operations :

+ - add

- - delete

permissions :

r - read permission

w - write permission

x - execute permission

Example 1: chmod go-rwx ECR deletes read, write and execute permissions on the directory ECR for all persons except the owner.

Example 2: chmod u+x bin/noctrlM adds execute permission to the file bin/noctrlM for the owner.

cp copy a file

cp file1 file2 creates a copy of file1 called file2

Example 1: cp letter form creates a copy of letter, called form.

cp file1 dir creates a copy of file1 in the directory dir, keeping the same name.

Example 2: cp letter Archive creates a copy of letter in the directory Archive with the name letter.

Example 3: cp letter .. creates a copy of letter in the parent directory.

Example 4: cp ~marian/Bank.java . creates a copy of ~marian/Bank.java in your current directory

Example 5: cp -r ~marian/Wu/ch1 . copies the directory ~marian/Wu/ch1, all of its subdirectories and their contents to the current directory.
cp dir/file1 dir/file2 creates a copy of file1 in the directory dir, with the new name file2.

Example 5: cp letter Archive/form creates a copy of letter in the directory Archive with the name form.

Example 6: cp ~marian/Bank.java ./Cash.java creates a copy of ~marian/Bank.java in your current directory with the new name Cash.java

Example 7: cp ~marian/51/LLcode/chap02/* . creates a copy of all files in ~marian/51/LLcode/chap02 in your current directory with the new name Cash.java

date display the date

date displays the current date and time.

find find a file

find dir -name 'file' -print prints to the screen all files with name file below directory dir

Example 1: find ~tjones -name 'Bank.java' -print finds and prints the filenames of all files named Bank.java from the home directory tjones on down.

Example 1: find . -name 'Bank*' -print finds and prints the filenames of all files beginning with the letters "Bank" from the current directory on down.

lp print to a 向日葵视频CS printer

lp -dprinter file prints file on the printer .

Example 1: lp -dstudlp1 typescript prints the file typescript on the printer studlp1 located in CU310

Example 2: lp -dproglp1 typescript prints the file typescript on the printer proglp1 located in CU101

ls list the files in a directory

ls [options] dir displays a list of the files in dir

Example 1: ls ECR displays a list of all files (and directories) in the ECR directory.

Example 2: ls -F displays a list of all files in the current directory with directory names followed by a / and executable files followed by a *.

Example 3: ls -a -F displays a list of all files in the current directory with directory names followed by a / and executable files followed by a * including all invisible files which begin with a period (such as .profile).

Example 4: ls -l displays a long list of all files (and directories) in the current directory, giving information about access permissions, size of the file, when it was last modified.

man access the online manual

man unix-command displays on the screen the online manual for the unix-command

Example 1: man find displays the online information about usage of the unix command find.

mkdir create a directory

mkdir dir creates a new directory called dir

Example 1: mkdir LLcode creates a new directory called LLcode

Example 2: mkdir chap02 chap03 creates two new directories called chap02 and chap03

mv move or rename a file

mv file1 file2 renames file1 with the new name file2.

Example 1: mv Bank Bank.java renames Bank with the new name, Bank.java

mv file1 dir moves file1 to directory dir keeping the same name.

Example 2: mv Bank.java ECR moves Bank.java from the current directory to the directory ECR.

pwd list the present working directory

pwd displays the present working directory.

rm remove or delete a file

rm file1 removes or deletes file1

Example 1: rm letter deletes the file letter.

Example 2: rm mail/letter deletes the file letter in the directory mail.

rmdir remove or delete a directory

rm dir removes or deletes dir which must be empty.

Example 1: rmdir letters deletes the empty directory letters.

Example 2: rm mail/letter deletes the file letter in the directory mail.

telnet connect to a remote computer over a network

telnet remote-computer connects to remote-computer

Example 1: telnet studsys connects to studsys.cs.mu.edu

Example 2: telnet vms connects to vms.csd.mu.edu

Example 3: quit ends a telnet session