CS 211b Reference Notes -- Midterm, March 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 */ From stdio.h: int scanf(const char *format, ...); /* read formatted values from standard input */ int printf(const char *format, /* args */ ... ); /* print formatted values to standard output */