Beruflich Dokumente
Kultur Dokumente
1 2
3 4
1
UNIX File System and Directories Useful UNIX Commands
ls list files and directories
Unix file system consists of files and directories.
ls -a list all files and directories (including hidden
When you first login, your current working directory is your home
files)
directory, and it is where your personal files and subdirectories are
saved. ls –l list all files and detailed information
drwxr-xr-x 2 lxiang users 4096 Nov 28 14:13 test
/ Top root directory for all the users
~ Your home directory (Unix file types, permissions, number of hard links, owner, group, size,
date, and filename)
. Current directory
.. Parent directory mkdir directory make/create a directory
A directory may contain several files and subdirectories. Examples: cd directory go to named directory
/home/faculty/lxiang cd ~ go to home directory (root for individual user)
/home/faculty/lxiang/test/display.c cd .. go to parent directory (go one level up)
~/test/display.c cd / go to top root directory for all users
5 6
6
7 8
2
Useful Information UNIX Text Editor: vi/vim
UNIX tutorial for beginners: vi/vim is a powerful UNIX-oriented text editor; vi is the
http://www.ee.surrey.ac.uk/Teaching/Unix/index.html original editor and vim stands for "vi improved". We will
You can use the up- and down- arrow keys to scroll use vi/vim to create all the text files including C codes.
through previous commands that you have executed vi operates in two different "modes":
Automatic filename completion is a useful utility. To use Command mode
vi starts up in this mode
it, just type a few letters of the desired file name, and
then press tab key, shell will fill in the rest of the name Whatever you type is interpreted as a command
11 12
3
Example: Hello.c Compiling and Executing Program
Let us create a simple C source code using vim (Step 1) You can compile your program with gcc (Step 2)
cd test (go to your test directory)
vim hello.c (open program vim and edit a file called hello.c) gcc hello.c –o hello.exe
(press 'i' to enter insert mode to type in the code; once done, This will compile hello.c program.
press Esc to go back to command mode and then type :wq to save
use –o option to specify the name of the executable file.
and quit vim to go back the UNIX prompt.)
If compilation is successful, it will generate an executable
/* Your first C program: hello.c */ called hello.exe
If there are any errors, go back to Step 1 (vim hello.c) to
#include <stdio.h>
edit your source code
int main() gcc comes with many options. For a listing of options, you can
{ type gcc – help
printf( "Hello!\n");
To execute the program, type ./hello.exe (Step 3)
return 0;
}
13 14