Monday, January 6, 2025
HomeProgrammingsudo Command in Linux with Examples

sudo Command in Linux with Examples

The sudo command allows users to run programs with superuser privileges. It’s used to execute commands requiring administrative access.

Syntax:

bash
sudo [options] command

Examples:

  1. Update System Packages
    bash
    sudo apt update
  2. Edit a System File
    bash
    sudo nano /etc/hosts
  3. Change Ownership of a File
    bash
    sudo chown user:group filename
  4. Restart a Service
    bash
    sudo systemctl restart apache2
  5. Run a Script as Superuser
    bash
    sudo ./script.sh

Key Notes:

  • Use sudo with caution to avoid system changes.
  • It asks for a password to verify privileges.
  • Use sudo -i for a persistent superuser session.
RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x