0% found this document useful (0 votes)
17 views3 pages

9 CP Command

Uploaded by

Brian K. Acevedo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

9 CP Command

Uploaded by

Brian K. Acevedo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Marvel-Themed Linux cp Practices: 10 Exercises

Practice 1: Copying a Single File


Objective: Learn to use the cp command to copy files.
Instructions:
1. Open your Linux terminal.
2. Navigate to the Marvel directory using cd Marvel.
3. Create a file: touch [Link].
4. Copy the file to a new file named [Link] using:
cp [Link] [Link].
5. Use ls to verify the new file exists.

Practice 2: Copying Multiple Files


Objective: Use cp to copy multiple files simultaneously.
Instructions:
1. Inside the Marvel directory, create files:
touch [Link] [Link] [Link].
2. Copy all files to a new directory named Backup using:
mkdir Backup
cp [Link] [Link] [Link] Backup/.
3. Verify the copied files by listing the contents of Backup.

Practice 3: Copying Directories Recursively


Objective: Use cp to copy entire directories and their contents.
Instructions:
1. Inside the Marvel directory, create a directory with subdirectories:
mkdir -p Phase1/IronMan Phase1/Thor Phase1/Hulk.
2. Copy the entire Phase1 directory to a new location named Phase1Backup
using:
cp -r Phase1 Phase1Backup.
3. Verify the copied directory structure with ls -R Phase1Backup.

Practice 4: Preserving File Attributes


Objective: Use cp to copy files while preserving attributes like timestamps and
permissions.
Instructions:
1. Inside the Marvel directory, create a file:
touch [Link].
2. Change its permissions using: chmod 600 [Link].
3. Copy the file to Backup while preserving attributes:
cp -p [Link] Backup/.
4. Verify the permissions and timestamps in the copied file using ls -l
Backup/[Link].

Practice 5: Copying Hidden Files


Objective: Learn to copy hidden files using cp.
Instructions:
1. Inside the Marvel directory, create a hidden file:
touch .[Link].
2. Copy the hidden file to the Backup directory:
cp .[Link] Backup/.
3. Use ls -a Backup to verify the hidden file is copied.

Practice 6: Copying Files Based on Wildcards


Objective: Use wildcards with cp to copy specific sets of files.
Instructions:
1. Inside the Marvel directory, create files:
touch [Link] [Link] [Link].
2. Use a wildcard to copy all files starting with "Avengers":
cp Avengers*.txt Backup/.
3. Verify the copied files in the Backup directory.

Practice 7: Interactive Copying


Objective: Use cp with the -i option to prompt before overwriting files.
Instructions:
1. Inside the Marvel directory, create two identical files:
touch [Link]
cp [Link] Backup/[Link].
2. Try copying [Link] again to Backup with -i:
cp -i [Link] Backup/.
3. Observe the prompt before overwriting.

Practice 8: Copying Files with Verbose Output


Objective: Use the -v option with cp to display detailed output.
Instructions:
1. Inside the Marvel directory, create files:
touch [Link] [Link].
2. Copy the files to the Backup directory with verbose output:
cp -v [Link] [Link] Backup/.
3. Observe the detailed output showing each file being copied.

Practice 9: Copying Files Between Directories


Objective: Use cp to copy files between unrelated directories.
Instructions:
1. Create a new directory named Villains in the Marvel directory:
mkdir Villains.
2. Copy files from the Backup directory to the Villains directory:
cp Backup/* Villains/.
3. Verify the copied files in the Villains directory with ls.

Practice 10: Testing cp Without Executing


Objective: Use the --no-clobber option to test copying without overwriting existing
files.
Instructions:
1. Inside the Marvel directory, create a file:
touch [Link].
2. Copy the file to Backup, then try copying it again with --no-clobber:
cp --no-clobber [Link] Backup/.
3. Observe that the file is not overwritten.

You might also like