Download presentation
Presentation is loading. Please wait.
Published byErica Melton Modified over 9 years ago
1
Basic Unix Commands CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang
2
For this class you need to work from your grove account to finish your homework Knowing basic UNIX commands is essential to finish your homework
3
Overview Files and Directories How to connect to GROVE Basic UNIX commands TAR Permissions UNIX editor pico Compiling C programs
4
Files and Directories In computers, what is the difference between a file and a directory? A file is a program or a document A directory contains files or other directories
5
Directory Structure Inside directories, you could find files and other directories Inside those “ other ” directories, you might find more files, and more directories
6
How do I connect to grove? telnet grove.ufl.edu
7
Telnet Window For login, enter the username on your grove account card For Password, enter the password on the grove account card Grove will ask you to change your password Just follow the on-screen instructions http://grove.ufl.edu/ for more information http://grove.ufl.edu/
8
UNIX Commands mkdir [directory] – create a new directory ls – list files or directories in current directory. ls – l list in long format (including details like permissions, owner, size, etc.)
9
More UNIX Commands pwd – let you know the absolute pathname of your current working directory (Where your are) cd [dir] – change directory cd.. – go back to parent directory. “.. ” is the relative pathname to the parent directory.
10
More UNIX Commands pico [filename] : create a new file Text editor ^X to quit and save the file cp cp [file1 file2] – copy file1 to file2. If there ’ s already a file2, the old one will be overwritten.
11
More UNIX Commands mv [sourcefile targetfile] – basically mv renames sourcefile to targetfile. If there ’ s a file with the same name as targetfile, it will be overwritten. rm file(s) – delete file(s). rmdir directories – delete one or more empty directories.
12
TAR Create tape archives and add or extract files. Creating a tar file: tar -cvf file.tar myfile.txt In the above example the system would create a tar named file.tar in the directory you currently are in. tar - cvf file.tar *.txt would compress all txt files in the current directory. tar -cvf home.tar home/ In the above example command the system would create a tar file named home.tar in the directory you currently are in of the home directory.
13
TAR Extracting the files from a tar file: tar -xvf myfile.tar In the above example command the system would uncompress (untar) the myfile.tar file in the current directory. tar -xvzf myfile.tar.gz In the above example command the system would uncompress (untar) the myfile.tar.gz file in the current directory. Note: There is no "untar" unix command.
14
Permissions There are three types of file access supported by UNIX. r – read, view the contents of a file w – write, edit file/directory contents x – execute, run executable file
15
- rwx r-x r-- 1 c3460abc cgs3460 858 Jan 23 8:28 f1 type owner group sizeModification date/timeFile name User permissions Group permissions Other Permissions links
16
Permissions read=4;write= 2;execute=1 rwxr-x r-- 4 +2 +14 +0 +14 +0 +0 754754
17
Permissions chmod mode file(or directory) –change the permission of the file or directory. Examples: Change the permission of file2 to: rwx r-x --x chmod 751 file2.
18
Unix Editor pico Simple and very easy to use text editor on UNIX Open a file using pico pico filename For example: pico hello.c The above example would open the editor with the file hello.c if present. Basic pico command (^ hold ctrl key) ^W where is ^Y previous page ^V next page
19
Compiling C Programs gcc is the "GNU" C Compiler. It is a free compiler that is available on grove.ufl.edu. Below are several examples that show how to use gcc to compile C programs.
20
Compiling a simple program Consider the following example: Let "hello.c" be a file that contains the following C code. #include main() { (void) printf("Hello…\n"); return (0); } A standard way to compile this program is with the command gcc hello.c -o hello This command compiles hello.c into an executable program named "hello" that you run by typing './hello' (or possibly just 'hello') at the command line. It does nothing more than print "Hello..." on the screen.
21
Compiling a simple program Alternatively, the above program could be compiled using the following two commands. gcc -c hello.c gcc hello.o -o hello The end result is the same, but this two-step method first compiles hello.c into a machine code file named "hello.o" and then links hello.o with some system libraries to produce the final program "hello". In fact the first method also does this two-stage process of compiling and linking, but the stages are done transparently, and the intermediate file "hello.o" is deleted in the process.
22
Compiling a program with multiple source files If the source code is in several files, say "file1.c" and "file2.c", then they can be compiled into an executable program named "myprog" using the following command: gcc file1.c file2.c -o myprog The same result can be achieved using the following three commands: gcc -c file1.c gcc -c file2.c gcc file1.o file2.o -o myprog
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.