Text-based interface.
Type commands with arguments:
$ command (arg1) (arg2) ...You can use this as an adjunct to (rather than replacement of) the GUI interface.
Can launch GUI programs:
$ gedit file &The "prompt" may be anything, not necessarily "$".
echo $PATHThis makes the command-line "shell" a reasonably simple program:
Note: The complete list of executable files in the path is normally read once and cached in memory for fast access every time a command is typed.
pwd Print working directory
e.g. /users/staff/jsmith
cd Change directory
ls List files
cd .. Go to parent directory
e.g /users/staff
. Current directory
/ root directory
$HOME home directory
$HOME/public_html public web space
/tmp system temporary files
Hierarchical file system - /directory/sub-directory/file
The "path" environment variable v. The "path" of a file:
| Directory before | Command | Directory after | Notes |
| /users/group2/user | cd /users/group1 | /users/group1 | Absolute path command |
| /users/group1 | cd user/shell | /users/group1/user/shell | Relative path command |
| /users/group1 | cd ../group2 | /users/group2 | Relative path command |
Case matters in filenames in UNIX (this is why case matters on Web).
Advantages:
Diversion - 404 redirectionThe apache web server allows 404 to remap to a script instead of just a standard error page. The script could then do a case-insensitive search (perhaps pre-build a list of all files, and then grep -i on the input string).
My 404 handlerSo this is what I do to implement an error-tolerant web server. I put a .htaccess file in:This .htaccess file has an ErrorDocument line to redirect 404's to a CGI script.$HOME/public_html/.htaccess The CGI script does a case insensitive and partial-line match on a pre-built list of all URLs. e.g. Try something hopelessly wrong like: http://computing.dcu.ie/~humphrys/NOTES//Unix///INTRO/nonexist.htmlor: http://computing.dcu.ie/~humphrys///Somewhere-In-Notes///intro.htmlThis works for my sub-site only. i.e. only for:
http://computing.dcu.ie/~humphrys/* not for mis-spellings higher up:
http://computing.dcu.ie/~humphreys http://computing.dcu.ie/~nonexist
Override browser error messageProblem: If IE 5 receives a return code of 404, it may override the server error handling with its own useless error message. You can turn this off at Tools-Options-Advanced- Show friendly HTTP error messages. But obviously you can't get every client to do that. So to get my script to work, you have to tell IE 5 that it is not an error. i.e. The first 2 lines output by the script are:Returning 200 does have problems, though, because then spiders do not realise this link is broken. Everything seemed to work just fine. So, for example, all error URLs will be archived in the Internet Archive as well as all real URLs, since the archive cannot tell they are just error screens.Status: 200 Content-type: text/html Q. Would HTTP return code 3xx help? |
Long file names and multiple periods OK.
e.g.
product.4652.suppliers.us.html
On many UNIX/Linux distributions (e.g. openSUSE) you can actually put these chars in filenames. But the file may then be hard to work with at the command-line, and scripts may crash.
Avoid these chars in filenames, because they may get confused with the instructions for command-line programs:
space (separate arguments) # comment < redirection > redirection ` result of a program | pipe & detach process ; separate multiple commands on the same line * wildcard ? wildcard ^ start of line $ end of line / variable value [ pattern matching ] pattern matching \ "quoted" character / should be in pathname, not filename ' string delimiter " string delimiter ! shell history |
If you do actually just point-and-click your UNIX files
(which is possible too) then you can allow many
of these characters.
But if you're going to use the command-line,
best to just use:
0-9 a-z A-Z . - _ |
Explore all these by typing "man (command)", e.g. "man ps"
ls List files
ls -a Show "hidden" files (begin with ".")
ls -l Detailed
ls -alR Recursive
cat (file) Type file out in command-line window
more (file) Type file, pause for each screenful
cp Copy files
mv Move / Rename files
rm Remove files
mkdir Make directory
rmdir Remove directory
clear Clear screen
(prog) & Launch a process detached
from command-line (e.g. windowed)
(prog) Command-line frozen until prog exits.
firefox & Launch Web browser from command-line
firefox "URL" &
grep Search for a string in a file or files grep (string) (file) grep -i (string) (file) find Find files by name or date find . -mtime -1 Files modified today
which (prog) What runs if "prog" is typed on DCU Solaris: $ which grep /usr/bin/grep $ which ls /usr/bin/ls on DCU Linux: $ which grep /usr/bin/grep $ which ls (returns nothing - alias) on DCU Solaris: $ type grep grep is a tracked alias for /usr/bin/grep $ type ls ls is a tracked alias for /usr/bin/ls on DCU Linux: $ type grep grep is /usr/bin/grep $ type ls ls is aliased to `/bin/ls $LS_OPTIONS' whereis (prog) Where the binary, source, manual pages are for this prog whereis perl
tar Bundle a lot of files or directories into an archive file gzip (file) Compress a file (e.g. an archive file) gzip -d (file.gz) Uncompress file ghostview (file.ps) & View a PostScript file cal Calendar cal 11 1818 Calendar for Nov 1818
lp (file) Print lpr (file) Print lpq See print queue lprm Remove job from queue df -h Show space on all disks df -k exact kilobytes du Space used by me w Who is logged in wget -q -O - URL Download URL (command) ; (command) Multiple commands on same line
ps See what processes are running kill (process id) Terminate some of your processes kill -1 All my processes kill -KILL (pid) Definite kill xkill & Kill the next thing I click on nice Run something at low priority deliberately time Time a run of some programIn the setup at DCU, you each have your own CPU and memory, sharing a central filesystem.
-T associated with this terminal -u $USER associated with this user -f full details
Ctrl-S Pause Ctrl-C Interrupt Ctrl-D Kill, Logout Ctrl-Z EOF q exit man, more