UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 22.9 Protect Important Files: Make Them Unwritable Chapter 22
File Security, Ownership, and Sharing
Next: 22.11 A Loophole: Modifying Files Without Write Access
 

22.10 cx, cw, c-w: Quick File Permission Changes

Here's a short script that I use a lot. To make a new shell script executable, for example, I type:

% cx scriptfile

Using cw adds write permission; c-w takes it away. This is the single script file for all three commands:

#! /bin/sh
case "$0" in
*cx)  chmod +x "$@" ;;
*cw)  chmod +w "$@" ;;
*c-w) chmod -w "$@" ;;
*)    echo "$0: Help!  Shouldn't get here!" 1>&2; exit 1 ;;
esac

The script has three links. Put it in a file named cx. Then type:

% chmod +x cx
% ln cx cw
% ln cx c-w

The script tests the name it was called with, in $0, to decide which chmod command to run. This trick saves disk space. You can add other commands, too, by adding a line to the case and another link. Or you can use aliases (22.9).

- JP


Previous: 22.9 Protect Important Files: Make Them Unwritable UNIX Power ToolsNext: 22.11 A Loophole: Modifying Files Without Write Access
22.9 Protect Important Files: Make Them Unwritable Book Index22.11 A Loophole: Modifying Files Without Write Access

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System