DEV Community

yuna song
yuna song

Posted on • Edited on

Linux Basics: Permissions and Process Management

1. chmod — Change File Permissions

Changes the permissions of files and directories.

Syntax

chmod [options] <mode> <file>
Enter fullscreen mode Exit fullscreen mode

Numeric (Octal) Mode

Permissions are represented by the sum of:

  • 4 = Read (r)
  • 2 = Write (w)
  • 1 = Execute (x)
Mode Permission Description
755 rwxr-xr-x Owner: full access; Group/Others: read & execute
644 rw-r--r-- Owner: read & write; Group/Others: read only
777 rwxrwxrwx Full access for everyone (not recommended)

Symbolic Mode

chmod u+x file.sh      # Add execute permission for owner
chmod g-w file.txt     # Remove write permission from group
chmod o+r file.txt     # Add read permission for others
chmod a+x script.sh    # Add execute permission for everyone
Enter fullscreen mode Exit fullscreen mode

Notes

  • u = owner
  • g = group
  • o = others
  • a = all users

2. chown — Change File Ownership

Changes the owner and/or group of files and directories.

Syntax

chown [options] <owner>[:group] <file>
Enter fullscreen mode Exit fullscreen mode

Common Usage

chown user1 file.txt
chown user1:group1 file.txt
chown :group1 file.txt
Enter fullscreen mode Exit fullscreen mode

Useful Options

chown -R user1:group1 /var/www/html
Enter fullscreen mode Exit fullscreen mode
  • -R : Change ownership recursively.

Notes

  • Changing ownership usually requires sudo.
sudo chown webuser:webgroup config.php
Enter fullscreen mode Exit fullscreen mode

3. ps — Display Running Processes

Displays information about currently running processes.

Common Usage

ps -ef
ps aux
Enter fullscreen mode Exit fullscreen mode

Practical Examples

ps aux | grep nginx          # Find nginx processes
ps aux --sort=-%mem          # Sort by memory usage
ps aux --sort=-%cpu          # Sort by CPU usage
Enter fullscreen mode Exit fullscreen mode

Common Output Fields

Field Description
PID Process ID
TTY Associated terminal
STAT Process state
TIME Total CPU time used
COMMAND Executed command

4. top — Monitor System Processes

Displays CPU, memory, and process information in real time.

Syntax

top
Enter fullscreen mode Exit fullscreen mode

The display refreshes every 3 seconds by default.

Useful Shortcuts

Key Action
P Sort by CPU usage
M Sort by memory usage
T Sort by CPU time
k Kill a process (enter PID)
q Quit top

Useful Options

top -d 1              # Refresh every second
top -u username       # Show processes for a specific user
Enter fullscreen mode Exit fullscreen mode

Notes

The top section shows system-wide CPU, memory, swap, and task information, while the bottom section lists running processes.


5. kill — Send Signals to Processes

Sends signals to running processes, most commonly to terminate them.

Syntax

kill [signal] <PID>
Enter fullscreen mode Exit fullscreen mode

Common Usage

kill 1234
kill -15 1234
kill -9 1234
Enter fullscreen mode Exit fullscreen mode

Common Signals

Signal Description
15 (SIGTERM) Gracefully terminate a process (default)
9 (SIGKILL) Forcefully terminate a process

Kill by Process Name

pkill nginx
killall chrome
Enter fullscreen mode Exit fullscreen mode

Notes

  • Use SIGTERM (kill or kill -15) whenever possible.
  • Use SIGKILL (kill -9) only if the process does not respond.
  • Find a process ID with:
ps aux | grep <process_name>
Enter fullscreen mode Exit fullscreen mode
  • Administrative privileges may be required:
sudo kill -9 1234
Enter fullscreen mode Exit fullscreen mode

Note: AI was used to assist in the drafting and formatting of this post.

Top comments (0)