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

me@linux ~ $ su - you
Password:
you@linux ~ $

Notice that me@linux is changed to you@linux. 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.

me@linux ~ $ 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
me@linux ~ $

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.

me@linux ~ $ cd /
me@linux / $ sudo mkdir dir3 dir4
[sudo] password for me:
me@linux / $ 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

me@linux / $ sudo cp etc/hosts dir3
me@linux / $ ls dir3
hosts

Moving files

me@linux / $ sudo mv dir3/hosts dir4
me@linux / $ ls dir4
hosts

Deleting directories

me@linux / $ sudo rm -r dir3 dir4
me@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