File commands

pwd, cd, ls, tree, mkdir, rmdir, touch, cp, mv, rm and find with their common options: what each one does, what it refuses and what it destroys.

  • 30 cards
  • 5 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link
  4. Scenarios
  5. Understand

A few cards from the deck

  • ls -la: what is it?

    Show the answer

    Lists a directory's content in detail (type, permissions, owner, size, date), hidden files included.

    -l gives the long format, -a adds the files whose name starts with a dot, such as .bashrc, which a plain ls does not show.

  • The directory archive does not exist. What does mv rapport.txt archive do?

    • It renames rapport.txt to archive
    • It creates the archive directory and moves the file into it
    • It fails, because the destination archive does not exist
    • It copies the file under the name archive and keeps the original
    Show the answer

    It renames rapport.txt to archive

    When the destination is not an existing directory, mv takes it as a new name. It is a classic way to lose files: the file is now a file called archive.

  • pwd prints the … directory; cd with no argument goes back to the … directory, and cd - to the … one.

    Show the answer

    pwd prints the current directory; cd with no argument goes back to the home directory, and cd - to the previous one.

    cd - switches back and forth between two directories: handy to hop without retyping paths.

  • mkdir -p a/b/c: what is it?

    Show the answer

    Creates a, a/b and a/b/c in one go, and reports no error if one of them already exists.

    Without -p, mkdir a/b/c fails (“No such file or directory”) if a/b does not exist, and mkdir a fails if a already exists.

  • cp src sauvegarde answers “cp: -r not specified; omitting directory 'src'” and copies nothing. Which fix?

    • Add root's rights: sudo cp src sauvegarde
    • Add recursion: cp -r src sauvegarde
    • Force the copy: cp -f src sauvegarde
    • Preserve permissions: cp -p src sauvegarde
    Show the answer

    Add recursion: cp -r src sauvegarde

    The message says it: src is a directory and cp only goes into a directory with -r. sudo, -f and -p do not change this refusal.