DirectNET

Data Center Management Solutions including UPS Systems, Data Center Cooling, KVM over IP & IP Power Strips, Server Racks and Server Rack accessories; KVM Switches and KVM Extenders; Rackmount Monitors and Rackmount Keyboards.


NAVIGATION
Home
Store
INSIDE MAC
Television Shows
Broadcast Shows
Daily News Shows
Special Shows
EVENTS
DAILY TIPS
Design
Mac OS X
Mac OS X UNIX
COMMUNITY
Forums
Surveys
NEWS
Current
Press
Archive
FEATURES
Editorial
Dr. Mac
Reviews
Reader Reports
RESOURCES
FAQ
Documentation
Learning Center
MAN pages
Glossary
Tutorials
Tips
Links

OUR PARTNERS

OSXFAQ Mac OS X UNIX Tip-of-the-Day   back to index

Week 104 - Unix Commands Reference IV (11 April 2005)

by Adrian Mayo - Editor, OSXFAQ

Monday - Miscellaneous Commands

The last three weeks and the this week will form a Unix command reference by listing lots of commands under specific areas of usage. There are so many commands available that it is impossible to know them all, or even remember all those one knew and used just last month.

See the rest of the tips for lots of example usage of these commands.

See the Learning Centre for tutorials on these commands.

And of course, don't forget the Unix manual 'man'.

To set and display environment and shell variables. The commands are marked as (tcsh) and (bash) if they are built-in for the respective shells, and (Unix) if they are standard Unix commands.

set ... set a shell variable (tcsh)
set ... set shell options (bash)
unset ... unset a shell variable (tcsh and bash)
setenv ... set an environment variable (tcsh)
unsetenv ... unset an environment variable (tcsh)
env ... set and display the environment (Unix)
printenv ... display environment variables (tsch and Unix)
(See tips week 54)

These commands are useful in shell scripts.

expr ... evaluate an expression
The expression can be arithmetic, relational, or logical
Used in scripting as `expr ...` or $(expr ...)
$ a=$(expr 1 + 1 )
$ echo $a
(See tips week 54 Friday
http://www.osxfaq.com/tips/unix-tricks/week54/friday.ws
)

getopt ... get and parse command line options
This is the standard command line parsing utility used by many commands to process options and command line arguments.

mktemp ... generate unique temporary file names
Option -d to make a directory
Option -t to include a prefix

printf ... formatted print to display
See 'man 3 printf' for more details of the formatting string.
(See tips weeks 27, 65, and 86)

sleep ... pause processing of a script
the script is paused for the given number of seconds to let other processes execute

[ and test ... tests an expression returning 0 (TRUE) or 1 (FALSE)
Use in conditional statements such as 'if' and 'while'
(See tips week 82)

xargs ...
Option -0 the expect null-separated filenames, Used with 'find -print0' to cope with filenames with spaces
Option -n to limit the number of arguments on each invocation. Used if the generated command line is too long (has too many arguments).
(See tips weeks 49, 98 Thursday)

lockfile ... prevent file from being accessed by more than one process

These commands compress files and make archives.

zip unzip ... compress/uncompress files and folders
gzip gunzip ... GNU version of zip
bzip2 bunzip2 ... uses a better compression algorithm
Option -1 to -9 to adjust the level of compression,
-1 is fastest but with the least compression
(See tips weeks 5 Friday, 37, 75 Tuesday)

tar ... archive files into a single file
Option -c to create a new archive
Option -x to extract from an existing archive
Option -r/-A to append files to an existing archive
Option -z to (un)compress with gzip

Miscellaneous commands.

visudo ... safe edit of /etc/sudoers
'sudoers' should not normally be edited by a standard test editor. visudo locks the file and does sanity checks.
(See tips week 36)

vipw ... safe edit of /etc/passwd
'passwd' should not normally be edited by a standard editor. vipw locks the file and does sanity checks.
This command is redundant as OS X uses shadow passwords and therefore does not use /etc/passwd except in single user mode.

time ... time the execution of a command

limit/unlimit ... change system resource limits


Discuss this trick in the Learning Center forum


If you want to learn more about Mac OS X Unix visit the Learning Center  click.

  • For beginners: Mac OS X Unix Tutorials
  • For detailed information on specific topics: Advanced Unix
  • For OS X in gereral: Mac OS X Tutorials

Copyright © 2000-2008 Inside Mac Media, Inc. All rights reserved.
Apple assumes no responsibility with regard to the selection, performance, or use of the products or services. All understandings, agreements, or warranties, if any, take place directly between the vendors and prospective users.
Apple, the Apple logo, Mac, PowerMac G4, PowerMac G5, Xserve, Xserve RAID, PowerBook, iBook, Airport, AirPort Extreme, iMac, eMac, iLife, iMovie, iCal, iPhoto, iTunes, QuickTime, FireWire, iPod, iSight, AppleWorks, Macintosh, Jaguar, Panther, Mac OS, Mac OS X and Mac OS X Server are trademarks of Apple Computer, Inc.