27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13. System and Administrative Commands<br />

The startup and shutdown scripts in /etc/rc.d illustrate the uses (and usefulness) of many of these<br />

comands. These are usually invoked by root and used for system maintenance or emergency filesystem<br />

repairs. Use with caution, as some of these commands may damage your system if misused.<br />

Users and Groups<br />

users<br />

groups<br />

Show all logged on users. This is the approximate equivalent of who −q.<br />

Lists the current user and the groups she belongs to. This corresponds to the $GROUPS internal<br />

variable, but gives the group names, rather than the numbers.<br />

bash$ groups<br />

bozita cdrom cdwriter audio xgrp<br />

bash$ echo $GROUPS<br />

501<br />

chown, chgrp<br />

The chown command changes the ownership of a file or files. This command is a useful method that<br />

root can use to shift file ownership from one user to another. An ordinary user may not change the<br />

ownership of files, not even her own files. [38]<br />

root# chown bozo *.txt<br />

The chgrp command changes the group ownership of a file or files. You must be owner of the<br />

file(s) as well as a member of the destination group (or root) to use this operation.<br />

chgrp −−recursive dunderheads *.data<br />

# The "dunderheads" group will now own all the "*.data" files<br />

#+ all the way down the $PWD directory tree (that's what "recursive" means).<br />

useradd, userdel<br />

The useradd administrative command adds a user account to the system and creates a home directory<br />

for that particular user, if so specified. The corresponding userdel command removes a user account<br />

from the system [39] and deletes associated files.<br />

id<br />

The adduser command is a synonym for useradd and is usually a symbolic link to it.<br />

The id command lists the real and effective user IDs and the group IDs of the current user. This is the<br />

counterpart to the $UID, $EUID, and $GROUPS internal Bash variables.<br />

bash$ id<br />

uid=501(bozo) gid=501(bozo) groups=501(bozo),22(cdrom),80(cdwriter),81(audio)<br />

bash$ echo $UID<br />

501<br />

Also see Example 9−5.<br />

Chapter 13. System and Administrative Commands 214

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!