Day 11 Learnings: File Operations and Process Management in Linux

Today’s focus was on understanding how to manage file group ownership and how to list running processes in Linux. These topics are foundational for managing system resources and controlling access permissions.


What I Learned This Week

  • Managing File Group Ownership with the chgrp Command:
    The chgrp command is used to change the group ownership of files or directories in Linux.

  • Listing Running Processes with the ps Command:
    The ps command helps monitor processes, providing details such as process IDs, statuses, and resource usage.


Steps I Followed

Managing Group Ownership | chgrp Command

  1. Check Current Group Ownership:
    Used the ls -l command to view file group ownership:

     ls -l file.txt
    

    Example output:

     -rw-r--r-- 1 user oldgroup 1024 Jan 11 12:00 file.txt
    
  2. Change Group Ownership:
    Changed the group of a file:

     sudo chgrp newgroup file.txt
    
  3. Change Group Ownership Recursively:
    Applied the command to a directory and its contents:

     sudo chgrp -R newgroup directory_name
    
  4. Verify Changes:
    Confirmed the new group ownership:

     ls -l file.txt
    

Monitoring Processes | ps Command

  1. List All Processes:
    Displayed all running processes:

     ps -e
    
  2. Detailed Process Information:
    Used the -f option for a full-format listing:

     ps -ef
    
  3. Filter by Username:
    Listed processes for a specific user:

     ps -u username
    
  4. Filter by Process Name:
    Displayed processes matching a specific name:

     ps -C process_name
    
  5. Monitor CPU and Memory Usage:
    Used ps to check resource usage of processes:

     ps -eo pid,comm,%cpu,%mem --sort=-%cpu
    

Problems I Encountered

  1. "Operation Not Permitted" Error with chgrp:
    Encountered this error when attempting to change group ownership without sufficient permissions.

  2. Finding Specific Processes:
    Initially, I struggled to filter specific processes effectively using ps options.


How I Solved These Problems

  1. Using sudo for Elevated Permissions:
    Resolved the chgrp an error by running the command with sudo.

  2. Referencing the ps Manual:
    Used man ps to explore options for filtering processes, which helped me craft efficient commands.


Resources I Used

  • Linuxize Guide to chgrp Command

  • Linuxize Guide to ps Command

  • Community forums for practical examples and troubleshooting tips.


Conclusion

Today’s learnings enhanced my understanding of managing group ownership and monitoring system processes. The chgrp command is essential for fine-tuning file permissions, while the ps command is a powerful tool for process management and troubleshooting.

I’m excited to continue exploring Linux tomorrow. Stay tuned for Day 12 updates!