Skip to main content

Experiment 03

Aim

To study file reading operations and text editors in Linux

Theory

  • touch

    • Used to create an empty file or update the access/modification timestamps of an existing file
    • Syntax: touch [filename]
  • cp (Copy)

    • Copies files from one location to another. If the destination is an existing directory, the file is copied into the directory (the directory is not overwritten)
    • Syntax: cp [OPTIONS]... SOURCE DEST
  • mv (Move)

    • Used to move/rename file from one directory to another. It completely removes the file from the source and moves to the directory specified
    • Syntax: mv [OPTIONS]... SOURCE DEST
    • Syntax: mv [-f] [-i] oldname newname.
    • Options: -i prompts before overwriting another file.
  • rm (Remove)

    • Used to remove/delete the file from the directory
    • Syntax: rm [options..] [file | directory]
    • Options: -i makes it interactive, prompting for confirmation before removing any files. -f removes all files in a directory without prompting the user
  • chmod (Change Mode)

    • Used to change permission. The basic permission characters are "r" (read), "w" (write), and "x" (execute). A simple plus or minus is used to add or subtract the permission
    • Syntax: chmod [permissions] [filename]
    • Syntax: chmod [permissions] [filename]
  • chown (Change Owner) / chgrp (Change Group)

    • Changes the user or group ownership of a file/directory (typically requires elevated privileges)
    • Syntax: chown [owner]:[group] [filename]

Commands

$ touch os_notes.txt
$ cp os_notes.txt backup_notes.txt

$ mv backup_notes.txt archived_notes.txt
$ ls -l archived_notes.txt
-rw-r--r-- 1 student student 0 Mar 19 14:05 archived_notes.txt

$ chmod +x archived_notes.txt
$ ls -l archived_notes.txt
-rwxr-xr-x 1 student student 0 Mar 19 14:05 archived_notes.txt

$ chmod -w archived_notes.txt
$ ls -l archived_notes.txt
-r-xr-xr-x 1 student student 0 Mar 19 14:05 archived_notes.txt

$ rm -i archived_notes.txt
rm: remove regular empty file 'archived_notes.txt'? y

Conclusion

The primary utilities for creating, duplicating, moving, and securely deleting files (touch, cp, mv, rm) were successfully executed. Additionally, basic file security concepts were practically implemented by adding and subtracting read, write, and execute attributes using the chmod command