ls
ls -l -> list files details in current directory
ls -a -> list all files (include hidden files) in current directory
ls -la -> list all files with details in current directory
Unix Command Review
How to create/delete/copy files or directory?
mkdir test
Create a directory named "test" in current directory.
cp fileX dirY/dirZ
Copy fileX from current directory to ./dirY/dirZ.
cp fileX dirY/fileZ
Copy fileX from current directory to dirY and rename to fileZ.
cp -r dirX dirY
Copy dirX from current directory to dirY.
Unix Command Review
How to create/delete/copy files or directory?
mv fileA dirB
Move fileA to dirB.
mv dirA dirB
If dirB exists, then move dirA under dirB.
If dirB doesn't exist, dirA is renamed to dirB.
rm x
Remove file x or remove directory x if x is an empty directory.
rm -rf x
Remove directory x and all its contents regardless the file is write-protect or not.
Unix Command Review
The path used on cd, mkdir, cp, mv, and rm can be absolute path or relative path.
Type pwd to see what the current directory is.
Type whoami to see your account's name.
Type logout to logout the system, or you can press Ctrl+D.
Type Ctrl+L to clean your screen.
Type Ctrl+C to stop the program which is running.
Unix Command Review
Remember, whenever you have problems using Unix, try man command.
man ls
man cp
man stands for manual.
Unix Command Review
Start Ghost account elm
Type /usr/local/bin/elm
Enter y 3 times and q 1 time
Vim Tips
i, o, a, R -> change to insert mode
Esc -> back to normal mode
:, / -> enter command-line mode
:w -> save your work
:q -> quit vim
:wq, :x -> save and quit
:q! -> quit without saving
:xxx -> go to line xxx
/xxx -> search "xxx" in this file
Vim Tips
v -> character visual
V -> line visual
y -> copy
p -> paste
d -> delete (cut)
u -> undo
:nohl -> no highlight
gg=G -> auto indent
Simple C Program
main() is a entry point of program
#include<stdio.h>intmain(){
int x;
scanf("%d", &x);
x = x + 2;
printf("%d\n", x);
return0;
}
#include <stdio.h> is for preprocessor
int main(){...} -> main function
scanf -> input
printf -> output
return 0 -> no error
Compile Your Program
How to compile your program?
make if you have Makefile.
Like a script. It runs gcc automatically.
gcc, GNU compiler.
gcc xxxxx.c
It will compile xxxxx.c and generate the executable file a.out.
Or dump a lot of errors.
Compile Your Program
#include<stdio.h>intmain(){
int a;
printf("%d", a)
return0;
}
[ge10919@ghost]~ gcc test.c
test.c: In function'main':
test.c:5: error: excepted ';' before 'return'
There is a rectangle in plane coordinates. Give you the coordinates of the upper-left and bottom-right points of the given rectangle. Please calculate the area of the rectangle.
Input:
Two lines. Each line contains two numbers.
The two numbers in the first line are the coordinate of the upper-left point (x1,y1). The two numbers in the secend line are the coordinate of the bottom-right point (x2,y2).