CS 211a Reference Notes -- Midterm, November 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 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 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 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 stdio.h: char *gets(char *s); /* read a line of standard input into s, and return s; if end of input (end of file) is encountered, return NULL instead */ int puts(const char *s); /* write string s to standard output, followed by a newline */ int scanf(const char *format, ...); /* read formatted values from standard input; return the number of arguments that were read in successfully */ int sscanf(const char *s, const char *format, ...); /* like scanf, except "input" is taken from the string s */ int printf(const char *format, /* args */ ... ); /* print formatted values to standard output */ int sprintf(char *s, const char *format, /* args */ ...); /* like printf, except the output is "written" to the string s */ From ctype.h: int tolower(int c); /* If the character stored in the int c is upper case, return the corresponding lower-case character as an int; otherwise, just return c */ int toupper(int c); /* If the character stored in the int c is lower case, return the corresponding upper-case character as an int; otherwise, just return c */ 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