Faisal Akkawi Akkawi@cs - Iit.edu Department of Computer Science Illinois Institute of Technology Chicago, IL 60616
Faisal Akkawi Akkawi@cs - Iit.edu Department of Computer Science Illinois Institute of Technology Chicago, IL 60616
[email protected]
Department of Computer Science
Illinois Institute of Technology
Chicago, IL 60616
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 1
Topics
Handling Files and Directories
Text Editors
Compiling and Linking
Handling Processes
Archiving and Compressing Files
Other Useful Commands
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 2
Handling Files and Directories
ls : list files
cp : copy files
mv : move files
rm : remove files
mkdir : make directories
cd : change directories
rmdir : remove directories
pwd : print working directory
chmod : change permission mode
umask : set file-creation mode mask
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 3
ls command
Syntax
ls [-Options] [name ...]
Description
Lists contents of directory.
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 4
cp command
Syntax
cp [-Options] file1 [file2 ...] target
Description
File1 is copied to target.
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 5
mv command
Syntax
mv [-Options] file1 [file2 ...] target
Description
File1 is moved to target.
Examples
mv p*.c mydir
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 6
rm command
Syntax
rm [-f] [-i] file . . .
Description
Removes files or directories.
rm -r mydir
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 7
mkdir command
Syntax
mkdir [-m mode] [-p] dirname . . .
Description
Creates the specified directories.
Options
-m Specifies the mode to be used
-p Create missing intermediate directories
Examples
mkdir -m 700 letter
mkdir abc
mkdir -p ./abc/def/ghi
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 8
cd command
Syntax
cd [directory]
Description
Change working directory.
cd ./abc/def/ghi
cd ..
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 9
rmdir command
Syntax
rmdir [-p] [-s] dirname . . .
Description
Removes directories.
Options
-p Remove the directory dirname and its parent
directories which become empty.
-s Suppress the message when –p is in effect
Examples
rmdir letter
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 10
pwd command
Syntax
pwd
Description
Prints the path name of the working (current) directory.
Examples
pwd
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 11
chmod command
Syntax
chmod [-R] mode file ...
Description
Changes the permissions mode of a file or directory.
Examples
chmod 444 file1
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 12
umask command – I
Syntax
umask [ooo]
Description
Sets file-creation mode mask to ooo. The three octal
printed.
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 13
umask command – II
Examples
umask 022 removes group and others write permission
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 14
Text Editors
pico
- Simple, easy-to-use text editor
vi
- Text editor based on an underlying line editor ex
emacs
- Powerful and extensible
- Hard to learn
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 15
pico
Layout is very similar to the pine mailer
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 16
vi
vi Modes:
Command mode : Normal and initial mode. Other
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 17
Compiling and Linking
cc
- C compiler
- Default behavior is ANSI/ISO C
make
- Allows programmer to maintain, update, and
regenerate groups of computer programs.
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 18
cc command – I
Syntax
cc [-Options] ... file ...
Description
*.c are assumed to be C source programs.
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 19
cc command – II
-o out Name the final output file out.
-Dname Define the name to the C macro processor
-Idir Seek dir for include files
Examples
cc p1.c
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 20
make command
Syntax
make [-f makefile] [-eiknpqrsStuwdDPBNMOg] [names]
Frequently Used Options
-f makefile Description file is makefile
make –f Project1.mak
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 21
Handling Processes
ps : Prints information about active processes
kill : Sends a signal to a process
ipcs : Reports IPC facilities status
ipcrm : Removes IPC resource id
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 22
ps command
Syntax
ps [-Options]
Description
Prints information about active processes.
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 23
kill command
Syntax
kill [-signal] pid . . .
Description
Sends a signal to the specified processes.
Examples
kill 389
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 24
ipcs command
Syntax
ipcs [-Options]
Description
Prints information about active IPC facilities.
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 25
ipcrm command
Syntax
ipcrm [-Options]
Description
Removes messages, semaphore or shared memory
identifiers.
Frequently Used Options
-q msqid Removes the message queue id
Examples
ipcrm -q 231
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 26
Archiving and Compressing
tar : Tape archiver
compress, uncompress, zcat : Compresses and
expands data using adaptive Lempel-Ziv coding
gzip : Compresses data using Lempel-Ziv coding
gunzip, gzcat : Decompresses files created by gzip,
zip, compress, or pack
pack, unpack, pcat : Compresses and expands files
using Huffman codes
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 27
tar command - I
Syntax
tar key [arguments] [name...]
Description
Saves and restores multiple files on a single file.
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 28
tar command - II
Frequently Used Modifiers
v Verbose
f Next argument is the name of the archive
Examples
tar cvf my.tar ./mydir1 ./mydir2
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 29
compress command
Syntax
compress [ -f ] [ -v ] [ -c ] [ -V ] [ -d ] [ -b bits ] [ name ... ]
Description
Compresses and expands data
compress -d my.tar.Z
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 30
uncompress command
Syntax
uncompress [ -f ] [ -v ] [ -c ] [ -V ] [ name ... ]
Description
Uncompresses files
Same as compress –d
Frequently Used Options
-c Write output on standard output
-v Verbose
Examples
uncompress my.tar.Z
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 31
zcat command
Syntax
zcat [ name . . . ]
Description
Uncompresses files
Same as uncompress –c
Writes the uncompressed data on standard output
Examples
zcat my.tar.Z > my.tar
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 32
gzip command
Syntax
gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name . . . ]
Description
Compresses and expands data
Suffix .gz
Description
Uncompresses files (Same as gzip –d )
Automatically detects input format
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 34
gzcat command
Syntax
gzcat [ -fhLV ] [ name . . . ]
Description
Uncompresses files (Same as gunzip –c)
Writes the uncompressed data on standard output
Examples
gzcat myfile.gz > myfile
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 35
pack command
Syntax
pack [ - ] [ -f ] name . . .
Description
Compresses files
Suffix .z
Options
-f Force packing
Examples
pack myfile
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 36
unpack command
Syntax
unpack name . . .
Description
Expands files created by pack
The new file has the .z suffix stripped from its name
Examples
unpack myfile.z
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 37
pcat command
Syntax
pcat name . . .
Description
Uncompresses files created by pack
Examples
pcat myfile.z
pcat myfile
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 38
Other Useful Commands
grep : search files for a pattern
man : on-line reference manuals
wc : word, line and byte or character count
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 39
grep command - I
Syntax
grep [-E| -F] [-c| -l| -q] [-insvx] pattern_list [file . . .]
Description
Searches the input files, selecting lines matching one or
more patterns
Frequently Used Options
-i Case-insensitive search
-l Write file names only
-n Display line number
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 40
grep command - II
Examples
grep -i unix p1.c
grep -n UNIX *.c *.h
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 41
man command
Syntax
man [-Options] [-M path] [-T macropackage] [ -s section] name ...
man [-M path] -k keyword ...
Description
On-line reference manuals
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 42
wc command
Syntax
wc [ -c|-m ] [ -lw ] [ file . . . ]
Description
Counts lines, words, and characters
Options
-c Count the number of bytes
-m Count the number of characters
-l Count the number of newline characters
-w Count the number of words
Examples
wc -l *.h *.c
(c) Faisal Akkawi & Munki Lee 2001 Basic UNIX Commands 43