# systemd और cron — Linux Command Line Fundamentals

Source: https://www.skillbyai.com/hi/linux/linux-systemd-cron

> systemctl से services नियंत्रित करें और cron व crontab से बार-बार चलने वाले jobs schedule करें।

## systemctl — सर्विसेज़ प्रबंधित करें

आज के अधिकतर डिस्ट्रो पर बैकग्राउंड सर्विसेज़ `systemd` चलाता है; `systemctl` से आप उन्हें नियंत्रित करते हैं।

```bash
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl status nginx
```

Output:

```
● nginx.service - A high performance web server
   Active: active (running) since Thu 2026-09-04 09:00:00 IST
```

## cron — नियमित काम शेड्यूल करें

**cron** आपके तय किए शेड्यूल पर कमांड चलाता है, पाँच समय फील्ड्स के साथ: मिनट, घंटा, महीने का दिन, महीना, हफ़्ते का दिन।

## crontab -e

`crontab -e` आपके निजी crontab को संपादन के लिए खोलता है।

```bash
# run backup.sh every day at 2:30 AM
30 2 * * * /home/alice/backup.sh
```

**Quiz:** किसी स्क्रिप्ट को हर रात तय समय पर स्वचालित रूप से चलाने के लिए कौन-सा टूल उपयोग होता है?

- [ ] systemctl
- [x] cron
- [ ] scp
- [ ] grep

*Answer:* cron. cron लिनक्स का बिल्ट-इन जॉब शेड्यूलर है, जो नियमित कामों के लिए बना है।

## अंतिम क्विज़ 1/8

अंतिम क्विज़

**Quiz:** कौन-सा command आपकी वर्तमान directory दिखाता है?

- [ ] ls
- [ ] cd
- [x] pwd
- [ ] whoami

*Answer:* pwd. pwd working directory प्रिंट करता है।

## अंतिम क्विज़ 2/8

अंतिम क्विज़

**Quiz:** chmod 755 file क्या सेट करता है?

- [ ] rw-r--r--
- [ ] rwxrwxrwx
- [ ] r--r--r--
- [x] rwxr-xr-x

*Answer:* rwxr-xr-x. 7 = rwx, 5 = r-x।

## अंतिम क्विज़ 3/8

अंतिम क्विज़

**Quiz:** कौन-सा command log file को live follow करता है?

- [x] tail -f
- [ ] cat
- [ ] head
- [ ] wc

*Answer:* tail -f. tail -f नई lines लिखे जाते ही दिखाता है।

## अंतिम क्विज़ 4/8

अंतिम क्विज़

**Quiz:** `command > /dev/null 2>&1` क्या करता है?

- [ ] Appends output to a file
- [x] Discards stdout and stderr
- [ ] Runs in background
- [ ] Shows only errors

*Answer:* Discards stdout and stderr. /dev/null उसमें भेजी हर चीज़ निगल लेता है।

## अंतिम क्विज़ 5/8

अंतिम क्विज़

**Quiz:** कौन-सा signal पकड़ा या अनदेखा नहीं किया जा सकता?

- [ ] SIGTERM
- [ ] SIGINT
- [x] SIGKILL
- [ ] SIGHUP

*Answer:* SIGKILL. SIGKILL हमेशा process समाप्त करता है।

## अंतिम क्विज़ 6/8

अंतिम क्विज़

**Quiz:** Ubuntu पर package कैसे install करें?

- [ ] dnf get name
- [ ] pacman -Q name
- [ ] brew add name
- [x] sudo apt install name

*Answer:* sudo apt install name. apt Debian और Ubuntu का package manager है।

## अंतिम क्विज़ 7/8

अंतिम क्विज़

**Quiz:** PATH क्या करता है?

- [x] Lists directories searched for commands
- [ ] Stores your home directory
- [ ] Lists open files
- [ ] Sets the prompt

*Answer:* Lists directories searched for commands. Shell PATH की entries को क्रम से खोजता है।

## अंतिम क्विज़ 8/8

अंतिम क्विज़

**Quiz:** कौन-सा tool recurring job schedule करता है?

- [ ] scp
- [x] cron
- [ ] grep
- [ ] tar

*Answer:* cron. crontab entries time fields और commands तय करती हैं।
