|
|
Text-based interface.
Type commands with arguments at a "prompt":
$ command (arg1) (arg2) ...You can use this as an adjunct to (rather than replacement of) the GUI interface.
The "prompt" may be anything, not necessarily "$".
Note I have changed my prompt so it looks different to yours. It doesn't matter what the prompt is.
Can launch GUI programs:
$ gedit file &
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
| 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 often matters on Web).
Is case sensitivity a good thing? Or is it a flaw in UNIX (and C/C++)?Advantages of case sensitivity:
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 on valid URLs (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 Program:$HOME/public_html/.htaccess The program it redirects to is a CGI script.ErrorDocument 404 /cgi-bin/user/prog The CGI script looks at REDIRECT_URL and 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 . (note: at start of filename will make file hidden) - (note: bad at start of filename, looks like command-line switch) _ |
Explore all these by typing "man (command)", e.g. "man ps"
man and more - space for next page, q to quit
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 may return nothing if prog is an alias type (prog) returns path of prog or else shows what prog is alias for 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 (on some systems)
lp -Pl128 (file) Print on printer l128 (L128)
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
(see this when you ssh student.computing.dcu.ie)
wget -q -O - URL Download URL
(command) ; (command) Multiple commands on same line
On Internet since 1987.