This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 2: Commands

Manipulating Files

face Harry Coppock

Creating and Deleting

WARNING!! Linux does not have a command to undo a delete. Once you delete a file using rm, it is gone… forever…

  • touch fileName creates a new file by the name “fileName”. Remember to specify the type of file (touch fileName.py, touch fileName.txt, etc…)
  • mkdir dirName creates a new directory named dirName
  • rm fileName deletes fileName
    • -i representing interactive mode where you are asked if you are sure you want to remove the file (press y if you want the file to be removed and any other key otherwise)
    • -r representing recursion in which case, if it is a directory which you have specified to delete, it and all its contents are recursively deleted.
    • -f Attempt to remove the files without prompting for confirmation.

e.g. rm -rf someDirectory deletes the directory someDirectory, and recursively deletes all its contents - yeah scary.

Copying and moving

  • cp copys a file
    • cp file1 file2 copies file1 and names the copy file2
    • cp file1 file2 file3 /someParentDirect/someChildDirect/ copies file1, file2 and file3 to the directory someChildDirectory
      • to copy a directory and all its contents you need to pass the recursive -r argument
  • mv moves files. Apply the same logic for cp for functionality