CS 279 - Week 2 Lecture 2 - 2022-08-31 TODAY WE WILL * announcements * more filesystem and file stuff! * prep for next class ===== a little more on ls, part 1 ===== * one of ls's MANY options: a, for all * to see all the files in a directory, including the invisible ones ls -a ===== cp intro ===== * cp - your basic copy command * most basic use: cp existing-file desired-new-file * makes a copy of existing-file with the name desired-new-file, and existing-file still exists and is unchanged afterwards ===== QUICK aside: diff command ===== * lovely for comparing two text files! * does a line-by-line comparison of its two argument file names * if it finds differences, it lists them -- if it does not, it has no output ===== back to cp! ===== * IF you call cp with a list of arguments and the last one is a directory file, (and only the last one is a directory file), it makes a copy of each of those files in that given directory (each with the same name they have in this directory) cp file1 file2 ... desired-dir ...and now there are copies of file1, file2, ... in desired-dir (and also in the current directory) ===== mv command ===== * mv for move! * NOW you are getting rid of the original... you are moving the file from one name to another name * one way of using: mv desired-file new-file-name ...now there will NOT be a file named desired-file anymore, but its contents will be in a file named new-file-name * and if you call mv with a list of non-directory files followed by a directory file, then it "moves" them to that directory file, and they are no longer in the current directory! mv file1 file2 ... dir-name ...now file1, file2, ... are no longer in the current directory, but they are now in dir-name ===== shell file globbing! PART 1 ===== * actually discussed in 2021 revision of course text, Chapter 16...! 16.1: "File globbing is the use of wildcards to specify a set of filenames" You can use this in a shell that supports this within shell commands * bash supports several wildcard characters, arguably the most commonly-used is * * in file globbing, * matches 0 or more characters (in visible file names...) *.txt # matches all files ending in .txt m* # matches all files starting with m m*.txt # matches all files that start # with m and end with .txt a*b*c*d* # matches all files that start with a # and have a b after that and # have a c after that and have a # d after that (and I don't care # how it ends) mkdir code-copies cp *.cpp *.h code-copies cp * .. cp ../* . ===== rm and rmdir ===== * rmdir followed by a directory name will, IF that dirctory is empty, REMOVE that directory rmdir a-dir-name # removes a-dir-name IF it is # empty * rm followed by a list of filenames removes the non-directory files from that list DEPENDING on how the system is set up, this may or may not be un-doable!!!!!!!!!! * be careful with wildcards and rm....!!!!! * a safer approach: use rm with its i, or interactive, option rm -i *.cpp * a useful-but-be-careful option: use rm with its r, or recursive, option to recursively remove contents of all subdirectories, and their subdirectories, ...!