Bird
Raised Fist0
Linux CLIscripting~20 mins

zip and unzip in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Zip Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of listing files after zipping?
You have a directory with files: file1.txt, file2.txt, and file3.txt. You run the command zip archive.zip file1.txt file2.txt. Then you run ls archive.zip. What is the output?
Linux CLI
zip archive.zip file1.txt file2.txt
ls archive.zip
ANo such file or directory
Bfile1.txt file2.txt
Carchive.zip file1.txt file2.txt
Darchive.zip
Attempts:
2 left
💡 Hint
The ls command lists files and directories by name.
💻 Command Output
intermediate
2:00remaining
What happens when you unzip a file into a directory?
You have a zip file named docs.zip containing files readme.md and guide.pdf. You run unzip docs.zip -d extracted_docs. What will be the result?
Linux CLI
unzip docs.zip -d extracted_docs
ls extracted_docs
Adocs.zip
Breadme.md guide.pdf
Cextracted_docs
DNo such file or directory
Attempts:
2 left
💡 Hint
The -d option specifies the directory to extract files into.
📝 Syntax
advanced
2:00remaining
Which command correctly creates a zip archive including all files in a directory?
You want to create a zip file named backup.zip that contains all files inside the directory project. Which command is correct?
Azip -r backup.zip project
Bzip backup.zip project/*
Czip backup.zip -r project
Dzip backup.zip project
Attempts:
2 left
💡 Hint
The -r option means recursive, to include directories and their contents.
🔧 Debug
advanced
2:00remaining
Why does this unzip command fail with 'cannot find or open' error?
You run the command unzip myfiles.zip -d /home/user/docs but get the error: cannot find or open myfiles.zip, myfiles.zip.zip or myfiles.zip.ZIP. What is the likely cause?
Linux CLI
unzip myfiles.zip -d /home/user/docs
AThe file myfiles.zip does not exist in the current directory
BThe destination directory /home/user/docs does not exist
CThe unzip command requires sudo privileges
DThe -d option is used incorrectly
Attempts:
2 left
💡 Hint
Check if the zip file is in the current folder where you run the command.
🚀 Application
expert
3:00remaining
How to create a zip archive excluding certain file types?
You want to zip all files in the current directory but exclude all .log files. Which command achieves this?
Azip -r archive.zip . --ignore='*.log'
Bzip archive.zip * --exclude='*.log'
Czip -r archive.zip . -x '*.log'
Dzip archive.zip . -exclude '*.log'
Attempts:
2 left
💡 Hint
The -x option excludes files matching a pattern.

Practice

(1/5)
1. What does the zip command do in Linux?
easy
A. It extracts files from a compressed archive.
B. It compresses one or more files into a single archive file.
C. It lists the contents of a directory.
D. It deletes files permanently.

Solution

  1. Step 1: Understand the purpose of zip

    The zip command is used to compress files into one archive to save space or organize files.
  2. Step 2: Differentiate from other commands

    unzip extracts files, ls lists files, and rm deletes files, so these are not correct.
  3. Final Answer:

    It compresses one or more files into a single archive file. -> Option B
  4. Quick Check:

    zip = compress files [OK]
Hint: Zip means pack files together into one compressed file [OK]
Common Mistakes:
  • Confusing zip with unzip command
  • Thinking zip lists files
  • Assuming zip deletes files
2. Which of the following is the correct syntax to create a zip archive named archive.zip including all files in the folder docs recursively?
easy
A. zip -r archive.zip docs
B. zip -x archive.zip docs
C. unzip -r archive.zip docs
D. zip archive.zip docs

Solution

  1. Step 1: Identify the option for recursive zip

    The -r option tells zip to include folders and their contents recursively.
  2. Step 2: Check command correctness

    zip -r archive.zip docs correctly creates the archive including all files inside docs. Other options are incorrect or for unzip.
  3. Final Answer:

    zip -r archive.zip docs -> Option A
  4. Quick Check:

    Use -r to zip folders recursively [OK]
Hint: Use -r option with zip to include folders recursively [OK]
Common Mistakes:
  • Using unzip instead of zip to create archive
  • Forgetting -r to include folders
  • Using -x which excludes files
3. What will be the output of the command unzip -l archive.zip?
medium
A. It lists the contents of archive.zip without extracting.
B. It deletes archive.zip after listing contents.
C. It extracts all files from archive.zip to current directory.
D. It compresses files into archive.zip.

Solution

  1. Step 1: Understand the -l option in unzip

    The -l option lists the files inside the zip archive without extracting them.
  2. Step 2: Differentiate from other actions

    Extracting files uses unzip without -l, deleting is not done by unzip, and compressing is done by zip, not unzip.
  3. Final Answer:

    It lists the contents of archive.zip without extracting. -> Option A
  4. Quick Check:

    unzip -l lists archive contents [OK]
Hint: Use unzip -l to peek inside zip without extracting [OK]
Common Mistakes:
  • Thinking unzip -l extracts files
  • Confusing zip and unzip commands
  • Assuming unzip deletes files
4. You run unzip archive.zip but get an error saying "cannot find or open archive.zip". What is the most likely cause?
medium
A. The zip archive is corrupted and cannot be opened.
B. You used the wrong command; unzip cannot extract files.
C. The archive.zip file does not exist in the current directory.
D. You need to use the -r option with unzip to extract.

Solution

  1. Step 1: Analyze the error message

    "cannot find or open archive.zip" means the file is missing or path is wrong.
  2. Step 2: Check command and options

    unzip is correct to extract files; no -r option is needed. Corruption would give a different error.
  3. Final Answer:

    The archive.zip file does not exist in the current directory. -> Option C
  4. Quick Check:

    File missing causes cannot find error [OK]
Hint: Check file exists in current folder before unzip [OK]
Common Mistakes:
  • Assuming unzip command is wrong
  • Using -r option with unzip incorrectly
  • Ignoring file location or name typos
5. You want to create a zip archive named backup.zip that includes all files and folders inside project, but exclude all .log files. Which command will do this correctly?
hard
A. zip backup.zip project/*.log
B. unzip -r backup.zip project -x '*.log'
C. zip -r backup.zip project --exclude '*.log'
D. zip -r backup.zip project -x '*.log'

Solution

  1. Step 1: Use recursive zip with exclusion

    The -r option includes folders recursively, and -x '*.log' excludes all .log files.
  2. Step 2: Validate command correctness

    zip -r backup.zip project -x '*.log' uses correct syntax. zip backup.zip project/*.log only zips .log files, C uses invalid --exclude, and D uses unzip which cannot create archives.
  3. Final Answer:

    zip -r backup.zip project -x '*.log' -> Option D
  4. Quick Check:

    Use -r to recurse and -x to exclude files [OK]
Hint: Use -x '*.ext' to exclude files when zipping recursively [OK]
Common Mistakes:
  • Using unzip instead of zip to create archive
  • Wrong exclude syntax like --exclude
  • Not using -r to include folders
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard