Project 100. Unix Command Reference "Is there a quick reference for Unix commands?" This project lists a large number of Unix commands, each with a brief description of its purpose. The commands are organized in categories and grouped by functionality. Where a command is covered by a project in this book, the project number is shown in parentheses. In some cases where multiple projects are listed, numbers in bold are used to indicate the most significant coverage. Apple-specific commands are shown at the end, in "Use Mac OS XSpecific Commands." Use Basic Commands The following are stock commands that you'll use all the time. ls | list the contents of the current directory (2) | cp | copy files and directories (2) | mv | move or rename files and directories (2) | rm | delete files and directories (2) | mkdir | create a new directory (2) | rmdir | delete a directory (2) | touch | create a file/modify access times (2, 17) | ln | make a link to a file (19) | cd | change working directory (2, 13) | pwd | display working directory (2) | pushd | change working directory and stack it (14) | popd | move back to last pushed working directory (14) | dirs | print working directory stack (14) | chmod | change file and directory permissions (8) | chown | change owners of files and directories (3) | chgrp | change group owners of files and directories (7) | chflags | change file flags (69) | man | consult the Unix manual (3) | apropos | equivalent to man k (3) | whatis | equivalent to man -f (3) | makewhatis | (re-)build the whatis database (3) | info | consult the GNU info system (3) |
View Files The following are commands to view and edit files, including compressed and binary files. cat | display a file (21, 63) | head | display first 10 lines of a file (21) | tail | display last 10 lines of a file (21, 41) | less | display a file page by page (21) | lesskey | specify key binding for less | more | display a file page by page (21) | pr | display files with pagination (21) | lp | print a file (21) | file | report the type of a file (11, 29) | hexdump | display binary files (22) | xxd | display binary files (22) | strings | search a binary file for printable strings (22) | vis | display nonprintable characters (21) | unvis | reverse the output from vis (21) | zcat, zmore | cat, more for zipped files (22) | bzcat,bzless,bzmore | cat, less, more for bzipped files (22) | nano | simple text editor (30) | emacs | powerful text editor (31) | vi/vim | powerful text editor (32, 33, 34, 35) | visudo | safe edit /etc/sudoers |
Search for Files and Commands The following are commands to search the file system for files and directories, and Unix executable files. find | find files matching many criteria (15, 17, 18) | locate | search database for filenames (15) | locate.updatedb | update the locate database (15) | type | find an executable (bash) (16) | which | find an executable (csh and tcsh) (16) | whereis | find an executable (search system path) |
Search File Content The following are command s to search the contents of text files for specific text or patterns of text that match regular expressions. grep | search a file for text (23) | egrep | equivalent to grep -E (23) | fgrep | equivalent to grep -F (23) | wc | count lines, words, and characters (23) | bzgrep, zgrep | grep for bzipped, zipped files (23) | bzegrep, zegrep | egrep for bzipped, zipped files (23) | bzfgrep, zfgrep | fgrep for bzipped, zipped files (23) |
Change File Content The following are commands to change file content programmatically and to format file content. awk | search and change file content (60, 62, 23) | sed | search and change file content (59, 61, 23) | TR | translate one character into another (57) | col | strip chars | cut | filters columns from files | expand | expand tabs to spaces (57) | unexpand | compress spaces to tabs (57) | fmt | format a text file (29, 57) | fold | fold long lines (29, 57) | sort | sort the lines of a file in alphabetical order (26) | uniq | filter out repeated lines from a file (26) | comm | display lines common to two files (26) | join | perform a database join on files | split | split a file into multiple smaller files (63) | paste | merge corresponding lines from two files (63) |
Compress and Archive File Content The following are commands to compress files and to place multiple files in a single file archive. bzip2, bunzip2 | uses a better compression algorithm (27) | gzip, gunzip | GNU version of zip (27) | zip, unzip | compress/uncompress files and folders (27) | tar | archive files into a single file (28) | cpio | copy file archives in and out |
Compare Text Files The following are commands to compare the differences between two files and to create patches that can be applied to update older files. diff | compare two files and display differences (24) | diff3 | compare two files relative to a third (24) | sdiff | compare and merge two files into a third (24) | patch | update file from differences (24, 25) | bzdiff, zdiff | diff for bzipped, bzipped files (24) |
Query and Manage Processes The following are commands to view, manage, and delete running processes. kill | stop/restart processes by PID (40) | killall | stop/restart processes by name | ps | list running processes (39, 40) | top | display information on running processes (39) | nice | execute a process with a given priority (40) | renice | alter the priority of an existing process (40) | nohup | execute a command immune to HUP signals |
Query and Manage Users The following are commands for, and to get information about, user accounts. login | log into a machine | su | switch to another user's identity (15) | sudo | execute a command as root (2) | exit | close a non-login shell | logout | close a login shell | id | display identity of current user (64) | groups | display groups to which a user belongs (64) | last | list all logins with date, time, and status (64) | users | display who is currently logged in | who | as users but with more detail (64) | w | as who but with more detail (64) | whoami | useful for amnesiacs (64) | talk | chat to another user | write | send a message to another user | wall | send a message to all logged-in users | mesg | allow/disallow messages from other users |
Schedule Tasks The following are commands to schedule one-off and periodic commands. at | execute a command at a specific time (70) | atq | list the pending at jobs (70) | atrm | remove an at job from the queue (70) | leave | remind you when it's time to leave | calendar | scheduling and reminder service | crontab | create user cron tasks (71) | periodic | run system-maintenance tasks (72) |
Use Shell and Scripting Commands The following are commands used to change shell settings and manage shell jobs, as well as miscellaneous commands useful for writing shell scripts. Shell Environment and Settings alias | alias a command line to a keyword (4, 51) | unalias | remove an alias (4, 51) | declare | declare a shell variable or array (4) | unset | remove a shell variable | env, printenv | display environment of current shell | history | display command history (4, 48) | set | set a shell attribute (45) | shopt | set a shell option (45) | umask | display and set the file-creation mask (8) | bind | to change shell key functionality (53) | function | assign a function to a keyword |
Shell Jobs and Processes fg | bring a background job to the foreground (55) | bg | place a job in the background (55) | jobs | list active shell jobs (55) | batch | execute commands in nonbusy periods | exec | execute a command in place of the shell | source | execute a script with current shell (47) | script | make a transcript of a Terminal session | time | time the execution of a command |
Shell Scripting Commands echo | display arguments (2, 4, 63) | printf | formatted display arguments (56, 63) | expr | evaluate an expression | expect | script a dialogue with interactive programs | getopts | get and parse command-line options (83) | sleep | pause processing of a script | tee | split a pipe into streams | xargs | form a command line from arguments (18) | mktemp | generate a unique temporary filename | lockfile | block file access by more than one process |
TcshSpecific Commands bindkey | to change shell key functionality (53) | set | set a shell variable (4, 45) | setenv | set an environment variable (4, 50) | unsetenv | remove an environment variable |
Commands to Control the Terminal clear | clear the Terminal window | reset | reset the Terminal display | resize | resize X11 window (for example, resize -s 25 80) | sty | change the setting for the Terminal | tty | display the user's current Terminal |
Employ Useful Utilities The following are other useful commands. banner | create banner text (96) | bc | arbitrary-precision calculator (96) | dc | arbitrary-precision reverse-polish calculator (96) | cal | display a monthly or yearly calendar (96) | units | convert quantities between units systems (96) | openssl | manage TLS/SSL certificates | certtool | create new key pairs for certificates |
Query and Mount File Systems The following are commands to report on and manage file systems, including those on local disk drives and those on servers. df | display disk free information for all disks (66) | du | display disk use statistics (66) | lsvfs | list the known virtual file systems (66) | mount | mount and query drives (68) and shares (88) | umount | unmount drives (68) and shares (88) |
Access Network Services The following commands are attached to and query network services. ssh | start a secure shell on a remote machine | scp | secure copy files to/from a remote machine | sftp | secure version of FTP | curl | grab a URL from a remote server (95) | fetchmail | get mail from SMTP, POP, IMAP, and so on | ftp | File Transfer Protocol (94) | telnet | connect using the Telnet protocol | apachectl | control the Apache HTTP server (92, 93) | dig | look up DNS information (91) | host | look up DNS information (91) | ntpq | query NTP time server | ntptimeset | set network time |
Report and Configure Network Settings The following are commands to configure network interfaces, report on their current settings, and report traffic. hostname | set or display the hostname (73) | ifconfig | configure network interfaces (73) | ipconfig | set the IP mode of an interface | ipfw | query and set the firewall (73, 94) | arp | maintain address-resolution protocol tables (90) | route | maintain network routing tables ping contact a remote host (90) | ping | contact a remote host (90) | TRaceroute | report on the route network packets take (90) | netstat | display network status (43, 90) | tcpdump | dump TCP activity (43) |
Manage the System The following are commands to reports on various aspects of the system, including the processor and file-system activity. arch | display machine architecture (37) | hostinfo | display information on the host (37) | machine | display processor type (37) | uname | display OS name, version, and processor type (38) | dmesg | display system message buffer (43) | logger | write to the system-log daemon syslogd (42) | date | display and set the system date (74) | uptime | report how long system has been running (43) | fs_usage | display live file system usage (43) | lsof | list open files (43) | vm_stat | display virtual-memory statistics (43) | sc_usage | display live system call stats (43) | latency | display context switches and interrupts (43) |
Manage the Kernel The following are commands to examine the kernel settings. kTRace | perform kernel tracing (43) | kdump | display a human-readable kTRace.out file | sysctl | display and set kernel-state variables (43) | zprint | display information on kernel zones | kextload | kernel extension load | kextunload | kernel extension unload | kextstat | display kernel extension statistics |
Use Mac OS XSpecific Commands The following commands are specific to Mac OS X and supplied by Apple. They are not found in other Unix-based distributions. Manage Disks bless | bless a system folder, set boot disk (74) | diskutil | repair, journal discs (67, 68, 74) | drutil | interact with CD and DVD burners | hdiutil | manipulate disk images | pdisk | partition table editor | vsdbutil | read/write enable permissions on HFS+ volumes |
Manage HFS+ Files CpMac | copy with resource forks (99) | ditto | copy files/sync folders with resource forks (99) | GetFileInfo | get attributes of HFS+ files (99) | SetFile | sets attributes of HFS+ files (99) |
Manage the System system_profiler | generate detailed system information (37) | softwareupdate | command-line version of S/W update (38) | scselect | change network location (73) | launchctl | manage Apple's Launch Daemon (70) | scutil | manage configd | syslog | manage the system log facility (42) | nvram | view and change Open Firmware variables (38) | pmset | set power-management parameters (37) | ioreg | display IO registry hierarchy |
Manage User Accounts dscl | Directory Services command-line utility (65) | nifind | find a NetInfo directory (65) | nireport | print tables from NetInfo (65) | nicl | NetInfo command-line utility | nidump | dump NetInfo information in Unix FF format | nigrep | perform a regular-expression search on NetInfo | niload | load NetInfo information from Unix FF format | niutil | read and write domain in plain text |
Manage Useful Utilities pbcopy | copy text to the pasteboard (97) | pbpaste | paste text from the clipboard (97) | open | open a file as though double-clicked (98) | screencapture | screen and window capture (99) | opendiff | open two files and compare | say | text-to-speech converter | defaults | read and write .plist files (99) | plutil | .plist file utilities (99) | sips | scriptable image processing system | lsbom | interpret bom files; see man 5 bom | otool | examine object files (Unix ldd) |
|