Common UNIX Commands


cat, cd, chdir, chmod, cp, file, find, head,

This listing describes common UNIX commands. We use the following symbols to define a command's syntax:

[item] item is an optional arguement.
item(s) Must specify one or more items.
* Command reads from standard input if the file arguement is ommited.


I. FILE AND DIRECTORY MANAGEMENT


cat concatenate and print

cat [options] [file(s)]*

Useful Options

- read from standard input first.
-n Number lines (BSD only).
-u Output is unbuffered.

Examples

cat /etc/motd
Displays file /etc/motd on the screen.

cat dict1 dict2 > dictionary
Concatenates files dict1 and dict2 to file dictionary.

cat > memo
Reads from keyboard (standard input) until user types control-D and places output in file memo.


cd, chdir changes working directory

cd [dir]

Change working directory to dir. If no arguements specified, change to home directory ($HOME).

Examples

cd japanese
Change to subdirectory japanese.

cd /u/eric/dbms/source
Change to directory /u/eric/dbms/source.

cd
Change to home directory.

See index entries cdpath, pushd, popd, dirs, pwd.


chmod change access permission (mode) for files or directories.

chmod absolute-mode file(s)
chmod symbolic-mode file(s)

Useful Options

Absolute
4 Read access.
2 Write access.
1 Execute (search) access.

Symbolic
r Read access.
w Write access.
x Execute (search) access.

u user (owner)
g group
o others
a all

Examples

chmod 775 .
Make current directory (,) read, write, and searchable by owner, read and searchable by group, and read and searchable by others.

chmod +x loc
Make loc executable by everyone.

chmod o-r logfile
Remove read permission on logfile for others.

chmod o-r,o-w *
Remove read and write permission for others on all files in the current directory.

chmod a=r *.c
Make all files ending in *.c read-only for everyone (all).


cp copy file(s)

cp file1 file2
cp file(s) directory

Copy file1 to file2. Copy one or more files to a directory.

Examples

cp .cshrc save.cshrc
Copy file .cshrc to file save.cshrc.

cp /u/scott/network/include/* .
Copy all the files in /u/scott/network/include to the current directory.


file determine file type

file file(s)

file attempts to classify its arguments' file types. Some typical classifications are directory, ascii text, commands text (i.e., shell scripts), c program text, executable not stripped, English text, and empty. file is not always accurate.

Example

file *
Classify each file in the current directory.


find find files

find pathname-list expression

find all files in the pathname-list that match expression.

Useful options

Options may be combined.

-name filename True if filename matches the current file name.
-perm octnum True if the permission matches the octal number octnum.
-print Display the file name.
-type t True if the type of file is t, where t is d (directory), f (file), c (character special file), or b (block special file).
-exec command True if the executed command returns a zero exit status. Replace {} with the current pathname. An escaped semicolon follows command.
-size n true if the file size n (greater than n is + n and less than n is - n).

Examples

find ~ -name "*.c" -print
Display all file names in the user's directory hierarchy ending in .c.

find / -size 0 -exec rm "{}" \;
Remove all zero-length files in the file system.

find ~ -type d -print
Display all directory names in the user's file system.


head display in front of file

head [-count] [file(s)]*

Display the first (10 or -count) lines of file(s).

Examples