Table of Contents

This is part 5 of the series Linux Command Line Interface. Please check earlier articles to get the grasp of current one.

Introduction

root directory - First directory in the file system. The location of the root directory is simply represented by /.

root account - Account with super user or administrative privileges.

Super user/Root privileges can be accessed in two ways.

  • By using su command or
  • By using sudo command.
Accessing root privileges
Accessing root privileges

su command

su command is generally used to access other user’s account. Assume you is another user’s login/user name, then su - you loads you’s shell environment.

Example 1

[email protected] ~ $ su - you
Password:
[email protected] ~ $

Notice that [email protected] is changed to [email protected]. When it asks for password, enter you account’s password. Password is invisible. Just enter.

Example 2

To access super user privileges, enter su - with no username.

[email protected] ~ $ su -
Password:
linux ~ # 

This time enter me’s account (first useraccount created on system) password when prompted.

Few more examples

Changing directory to root directory:

linux ~ # cd /
linux / # ls
bin    dev   initrd.img      lost+found  opt   run   sys  var
boot   etc   initrd.img.old  media       proc  sbin  tmp  vmlinuz
cdrom  home  lib             mnt         root  srv   usr

Making directories

linux / # mkdir dir1 dir2
linux / # ls
bin    dev   etc         initrd.img.old  media  proc  sbin  tmp  vmlinuz
boot   dir1  home        lib             mnt    root  srv   usr
cdrom  dir2  initrd.img  lost+found      opt    run   sys   var

Copying files

linux / # cp etc/hosts dir1
linux / # ls dir1
hosts

Moving files

linux / # mv dir1/hosts dir2
linux / # ls dir2
hosts

Removing/Deleting directories

linux / # rm -r dir1 dir2
linux / # ls

Exiting from super user account

linux / # exit
logout
[email protected] ~ $

sudo command

Use sudo along with the command that required super user privileges. When prompted for the password, enter it.

Creating directories

First change current working directory to root (/) directory using cd command. To create directories dir3 and dir4 in root directory use sudo mkdir dir3 dir4.

[email protected] ~ $ cd /
[email protected] / $ sudo mkdir dir3 dir4
[sudo] password for me:
[email protected] / $ ls
bin    dev   etc         initrd.img.old  media  proc  sbin  tmp  vmlinuz
boot   dir3  home        lib             mnt    root  srv   usr
cdrom  dir4  initrd.img  lost+found      opt    run   sys   var

Copying files

[email protected] / $ sudo cp etc/hosts dir3
[email protected] / $ ls dir3
hosts

Moving files

[email protected] / $ sudo mv dir3/hosts dir4
[email protected] / $ ls dir4
hosts

Deleting directories

[email protected] / $ sudo rm -r dir3 dir4
[email protected] / $ ls
bin    dev   initrd.img      lost+found  opt   run   sys  var
boot   etc   initrd.img.old  media       proc  sbin  tmp  vmlinuz
cdrom  home  lib             mnt         root  srv   usr