SciencesPo Intro To Programming 2024
11 October, 2024
Questions
Objectives
thesis here:this outputs:
haiku.txt LittleWomen.txt
mkdir to create:used like this, thesis is created in the current directory. While with the -p flag we created nested subdirectories:
Bad File Names
north pacific gyre is not a good one. Use north-pacific-gyre instead.-.., -, and _thesis directory and create a text file called draft.txt.TEXT Editor
nano is a super simple editor, and you can use it only to edit text files (That’s normal for text editors 😉). You will probably switch to a more powerful editor later on (I recommend VSCode), but nano is a good starting point. Notice that ^ key is the Ctrl key, so ^X means Ctrl + X.
cdtouch command:$ # this is a comment, by the way
$ cd # so, going home.
$ touch new_doc.pdf # creating an empty file.new_doc.pdf. What is going to happen?rm command (more later)rm is forever gone.-i interactive to be safe(r).writing directorydraft.txt to quotes.txt with mv.mv x y means x is gone afterwards!cp x y is similar to mv x y, but you keep x.-r option means recursively and copies entire folders:rm -r mydir will delete everything inside the mydir folder!* character is a wildcard, i.e it matches all characters:Suppose we want to create the following structure on our computer:
Challenge
Which sequence will achieve this result?
1.
$ mkdir 2016-05-20
$ mkdir 2016-05-20/data
$ mkdir 2016-05-20/data/processed
$ mkdir 2016-05-20/data/raw
2.
$ mkdir 2016-05-20/data/raw
$ mkdir 2016-05-20/data/processed
3.
$ mkdir -p 2016-05-20/data/raw
$ mkdir -p 2016-05-20/data/processed
Tip
cp [old] [new] copies a file.mkdir [path] creates a new directory.mv [old] [new] moves (renames) a file or directory.rm [path] removes (deletes) a file.* matches zero or more characters in a filename, so *.txt matches all files ending in .txt.? matches any single character in a filename, so ?.txt matches a.txt but not any.txt.Ctrl-X, Control-X, and ^X.something.extension. The extension isn’t required, and doesn’t guarantee anything, but is normally used to indicate the type of data in the file.