CS 211b Reference Notes -- Final Exam, April 2006 Selected Command Descriptions and Selected Command Line Options cat: Concatenate and display files -n precede each line of output with its line number cd: Change the working directory chmod: Change file permissions -R recursively descend through directory arguments to set modes cp: Copy files -i prompt for confirmation -r recursively copy directory contents echo: Write its arguments to standard output, followed by a newline expr: evaluate arguments as an expression; can perform + - * / % grep: Search a file for a pattern -c print the number of lines that match the pattern -i ignore differences between upper and lower case -n precede each line of output by its line number in the input file -v print only the lines that don't match the pattern head: Display first few lines of a file -num the first num lines of each input file are copied to standard output ln: -s create a symbolic link ls: -l print a detailed listing of files in the current directory, including file protections, owner, group, size, date of last modification -a includes "hidden files" in the listing -b force display of nonprintable characters -F mark directories with a trailing /, executables with a trailing *, symbolic links with a trailing @ -r reverse normal listing order -R recursively list subdirectory contents -t sort by time stamp nl: -b argument specifies type of numbering to take place (a, t, n) passwd: Change password rm: Remove directory entries -f do not prompt for confirmation, and suppress diagnostic messages -i prompt for confirmation -r recursively descend through directory subtree to delete files rmdir: Remove an empty directory scriptfix: Remove extraneous non-printable characters from a file sort: -b ignore leading blanks -f ignore differences between upper and lower case -d use dictionary ordering -k specifies start (and end) fields for sorting, comma-separated; similar to +pos -pos notation for same purpose -M sort as month names -n compare values as numbers -r reverse the normal order of sorting -t specifies a field separator char for sorting by fields -u remove duplicate lines from the output tail: -num print the last num lines from the file +num begin a specified distance from the beginning of the file, and print to the end tee: Replicate standard output -a append file output, rather than overwriting test: -d true if the filename exists, and is a directory -f true if the filename exists, and is a regular file -h true if the filename exists, and is a symbolic link -x true if the filename exists, and is executable -z true if the string being tested is empty (0 length) -n true if the string being tested is non-empty =, != used to compare strings for equality -gt, -le, -eq, -ne, etc relational operators for testing two integers (greater than, less than or equal, equal, not equal, and so on) tr: -d delete the specified characters -c the complement of the specified set of characters is being replaced -s "squeeze": multiple adjacent occurrences of replacement characters are replaced by a single character wc: -c report the number of characters in the file -l report the number of lines in the file -w report the number of words in the file Selected Functions from the C Standard Libraries From stdio.h: int fclose(FILE *stream); /* close the file pointed to by stream */ FILE *fopen(const char *filename, const char *mode); /* open the file with name filename in the given i/o mode */ char *gets(char *s); /* read a line of standard input into s */ char *fgets(char *s, int n, FILE *stream); /* read up to n chars from a line of file stream into s */ int puts(const char *s); /* write string s to standard output, followed by a newline */ int fputs(const char *s, FILE *stream); /* write the null=terminated string s to destination given by stream */ int fgetc(FILE *stream); /* get the next char from the input stream */ int fputc(int c, FILE *stream); /* write c to the output stream as a char */ int scanf(const char *format, ...); int fscanf(FILE *strm, const char *format, ...); int sscanf(const char *s, const char *format, ...); int printf(const char *format, /* args */ ... ); int fprintf(FILE *strm, const char *format,/* args */ ... ); int sprintf(char *s, const char *format, /* args */ ...); From stdlib.h: int atoi(const char *str); /* convert a string representation of an int to int, and return it */ long atol(const char *str); /* convert string representation of a long to a long, and return it */ void free(void *ptr); /* deallocate the dynamically allocated chunk of memory referenced by ptr */ void *malloc(size_t size); /* allocate size bytes from the heap, and return a pointer to this space */ From string.h: char *strcat(char *dst, const char *src); /* concatenate a copy of src onto the end of dst */ char *strncat(char *dst, const char *src, size_t n); /* concatenate at most n chars from src onto the end of dst */ char *strchr(const char *s, int c); /* return a pointer to the first occurrence of c in s, or NULL if not found*/ int strcmp(const char *s1, const char *s2); /* return 0 if strings are equal, >0 if s1>s2, and <0 if s1