File Manipulation – Linux Teaching Plan

This 3‑hour workshop covers the core utilities that allow you to create, copy, move, link, and delete files and directories in a Linux environment. The plan is suitable for students who already know how to navigate the filesystem but want to master the manipulation side of things.

Learning Objectives

Agenda (3 Hours)

  1. 0‑10 min – Welcome & objectives
  2. 10‑25 min – Creating files: touch, cat
  3. 25‑40 min – Copying & moving: cp, mv
  4. 40‑55 min – Removing & cleaning: rm, find
  5. 55‑70 min – Linking: ln
  6. 70‑85 min – Permissions & ownership: chmod, chown
  7. 85‑100 min – Text replace: sed
  8. 100‑115 min – Scripting & automation
  9. 115‑120 min – Q&A & wrap‑up

Command Topics & Hands‑On Exercises

1. touch – Create or Update Timestamp

Creates an empty file or updates its access & modification times.

touch file.txt
touch -t 202309301200 newfile.log

2. cat – Concatenate / Display

Displays file contents; also used to create files.

cat file.txt
cat > newfile.txt
echo "Hello" | cat - file.txt > combined.txt

3. cp – Copy Files & Directories

Copies files or directories, with optional flags.

cp source.txt dest.txt
cp -r dir1/ dir2/
cp -p file1 file2

4. mv – Move / Rename

Moves or renames files and directories.

mv oldname.txt newname.txt
mv file.txt ../destination/
mv -t dest_dir/ file1 file2

4b. rm – Remove Files & Directories

Deletes files; can be forced or recursive.

rm file.txt
rm -f file.txt
rm -r dir/
rm -i file.txt

5. find – Search & Execute

Finds files by name, type, size, etc. and can execute actions.

find . -name "*.log"
find /var/log -size +5M -exec rm {} \;

6. ln – Hard & Symbolic Links

Creates links to files or directories.

ln existing.txt hardlink.txt
ln -s /var/log/syslog syslink.log

7. chmod – Change Permissions

Alters file mode bits; numeric and symbolic forms.

chmod 644 file.txt
chmod u+x script.sh
chmod g-w file.txt

8. chown – Change Owner & Group

Modifies file ownership; can recurse into directories.

chown user:user file.txt
chown -R root:root dir/

9. find … -exec rm … – Automated Cleanup

Combines find with exec to remove files.

find . -name "*.bak" -exec rm {} \;
find . -mtime +30 -type f -exec rm {} \;

10. sed – Stream Editor (Text Replace)

Performs inline or streamed search & replace.

sed -i 's/old/new/g' file.txt
sed '/^#/d' file.sh

11. rm -rf – Recursive Force Delete

Forcefully removes directories and their contents.

rm -rf ~/tmp/old/

12. mv -n – Move Without Overwrite

Prevents accidental overwrites when the destination exists.

mv -n source.txt dest.txt
mv -n file1 file2

13. ln – Hard Link

Creates a hard link that shares the same inode.

ln existing.txt hardlink.txt

14. ln -s – Symbolic Link

Creates a pathname reference to another file/directory.

ln -s /usr/share/doc README_link.txt

15. cleanup.sh – Basic Automation

Students write a small shell script that uses the above commands.

# cleanup.sh
#!/bin/bash
DIR=$1
find "$DIR" -name "*.tmp" -delete
echo "Removed all .tmp files from $DIR"

Practice Workshop (Hands‑On)

Students work in small groups to complete the exercises. Instructors circulate to demonstrate “best‑practice” habits:

Assessment

  1. Quiz (5 min): 5 rapid questions on command options and expected results.
  2. Mini‑Project (15 min): Write a script that:
    1. Backs up all .conf files from /etc to /tmp/backup_conf.
    2. Creates a hard link for each backed‑up file in /tmp/links.
    3. Sets permissions to 640 and owner to the current user.
  3. Peer review: students run each other’s scripts and comment on effectiveness.

Resources

Feel free to tweak the schedule or the difficulty of the exercises to match your students’ experience level.