1. chmod — Change File Permissions
Changes the permissions of files and directories.
Syntax
chmod [options] <mode> <file>
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
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>
Common Usage
chown user1 file.txt
chown user1:group1 file.txt
chown :group1 file.txt
Useful Options
chown -R user1:group1 /var/www/html
-
-R: Change ownership recursively.
Notes
- Changing ownership usually requires
sudo.
sudo chown webuser:webgroup config.php
3. ps — Display Running Processes
Displays information about currently running processes.
Common Usage
ps -ef
ps aux
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
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
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
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>
Common Usage
kill 1234
kill -15 1234
kill -9 1234
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
Notes
- Use
SIGTERM(killorkill -15) whenever possible. - Use
SIGKILL(kill -9) only if the process does not respond. - Find a process ID with:
ps aux | grep <process_name>
- Administrative privileges may be required:
sudo kill -9 1234
Note: AI was used to assist in the drafting and formatting of this post.
Top comments (0)