Knowledge
of some common Unix commands will help you to get the most out of your
Netmar webhosting account.
All actual commands are noted in courier
or monospace font - these
all represent common commands you can run. "Arguments" means
additional directives or additional information, and are usually done
with syntax: command -argument,
as in
ls
-l (command dash argument).
cd -
change
directory.
This works very similar to cd in MS-DOS if you're familiar with DOS.
Note that directories in Unix use forward slash ( / ) not the
Microsoft backslash (\). Basic syntax is
cd
directory
Some common examples would
be:
cd ~ - changes
to your home directory
cd www - if
you're in your home directory, changes to your www directory
cd .. - changes
to the parent directory ("up one directory")
cd
../../cgi-bin
- go up two directories and then descend into the cgi-bin directory,
which is a subdirectory of the directory two directories above the current.
pwd -
print
working directory.
This command simply shows you what directory you are in at the time.
It takes no arguments.
pwd
/users/g/guest -
This would be an example output of pwd.
ls -
directory
listing.
This shows you the contents of the current directory. It is roughly
equivalent to "dir" in MS-DOS, but more powerful / descriptive.
It can take several arguments, the most common of which are l, a, and
F. The lowercase "l" argument gives you a long listing: in
addition to file names, it will give you the permissions on the file,
who owns it, last modification date, and the size. The "a"
stands for "all", it gives you a listing of all files in your
directory, including files hidden by a leading period. The "F"
switch shows you what type of file each file is by suffixing directories
with a slash ( / ) and executables with an asterisk ( * ).
You can also "pipe" the output of ls to the "page"
command. The page command gives you the listing of a directory one page
at a time. It is roughly the same as the "/p" switch for the
DOS command "dir" as in "dir /p". When the phrase
"pipe it out to", it means take the first command, put a pipe
( | ) and then type the second command. The output of the first command
is sent to the second command. The syntax for this is: commandone
| commandtwo as in ls
-la | page
ls
- simple directory listing, most common
ls
-l
- long listing
ls
-aF
- show hidden files and denote what type of file each is
ls
-la | page
-
show all files in a long listing, one page at a time, fairly common
ls
-laF
- show a long, complete listing, denoting what type of files the
directory contains (all three arguments)
mv -
move files.
The mv command moves a file from one place to another. Arguments are
mv sourcefile destinationfile
Note also that mv in Unix serves as a rename function. If you move a
file to a different file, essentially it renames the file.
mv
index.html ~/www/index.html
- moves index.html from your current directory
 
;
into your home directory, subdirectory www.
mv
to-do-june.txt to-do-july.txt
- renames the file to-do-in-june.txt
 
;
to to-do-in-july.txt
cp -
copy files
The copy command copies a file from one location to another, leaving
the original file intact.
cp
images/buttons/button1.jpg images/navbar/
- copies button1.jpg
 
;
into the navbar directory
cp
~/www/mypage.html
. - copies
mypage.html into the current directory (dot = current dir)
cp
mypage.html mypage2.html
- copies mypage.html into mypage2.html
rm -
remove
files
The rm command deletes files. It is very simple: rm <file> removes
the file. If you want to delete directories, you need to use the -r
switch, as in rm -r <directory>. Example:
rm
-r ~/www/oldfiles/ -
deletes oldfiles directory
rm
index.old.html -
deletes the file index.old.html
pico -
edit
files
Pico is a small utility that lets you open a file and edit it. The commands
that are used are on the bottom of the screen, the carrot ( ^ ) representing
the "control" key on your keyboard.
pico
index.html
- opens index.html to be edited.
When editing a file, just move the cursor around with the arrow keys,
type or delete what is needed. If you are ready to save the file and
exit, you just push control-X. When it asks you if you want to save
changes, type "y" or "yes". It will then ask you
what file name to write the changes to, you can hit enter if you want
them written to the same file, as it should list the default value as
the preexisting name of the file.
If you just wish to save and not to exit, you can use the control-O
command. It works much the same way as control-X, but it doesn't exit
the program on completion of the save.
grep -
get regular
expression
grep works basically to find things. Often, commands are piped to grep.
For example, if you want to know if the entry myfiles is in a directory,
but the directory has 1000 items in it, you could use grep to find the
file. Regular expressions are strings of characters. If you have more
than one word you're searching for, you need to put the expression in
quotes ( "this expression" ). One switch that grep takes is
the -v switch, which searches the input of grep for everything *but*
the expression. The syntax for grep is grep <search string> <where
to search>, or if being piped into grep, it's just grep <search
string>. Examples:
grep
html * -
greps the current directory for all files containing the string html
ls
-F | grep / -
will grep a directory for folders (-F on ls = filetype, folders have
/'s,
grep filters them)
grep
-v "new product" ~/www/ -
greps user's www directory for every
line of every file that doesn't contain the string "new product"
(minus quotes)
Some other switches for grep include -i, which searches case-insensative,
and -r which searches recursively (into directories). grep by default
is case sensitive.
chmod
- change
permissions
All files and directories in Unix have a permission associated with
them. You may have seen this before, in the form of:
-rwxr-xr-- filename
You can see this on the left of your screen if you use the "ls
-l" command. What it means is this: rwx would be read write execute,
in that order. There are enough places for three of these designations.
Something that has complete access would have -rwxrwxrwx. Something
that only the user has access to would be -rwx------. The first - is
a sticky bit (not covered here), the first trio beyond that are user,
then group, then world, so it would be
dash user read user write user execute group read group
write group execute world read world write world execute
If this isn't making sense, read on...
This is fairly common in FTP services and other places. First it must
be understood that there are three groups of people that the permission
deals with: the user (you), your group, and "the world" (everybody).
There are also three things people can do to any file: read it, write
to it, or execute it. Write it is synonymous with change it.
The user: This is you. You would want to have read/write/execute access
to all of your own files.
The group: This is everyone else in your group, everyone else that has
a webhosting account.
The world: This is absolutely everyone. You probably don't want everyone
to have access to your files.
Read: This is the ability to view a file. You can't save changes or
execute it if it's a program (binary)
Write: This means "change" the file, in any way. Delete it,
write over it, etc.
Execute: This means "run" if it's a program file.
Now, the way to set permissions on a file is a little complicated: You
have to do some math.
Execute = 1
Write = 2
Read = 4
In order to get what you want, you have to add them together, such that
values 0-7 each have a unique meaning. For example, 1+2 = 3, 3 = execute
and write, but not read. 4+1 = 5, 5 = read and execute, but not write.
A complete list is:
0 = no permissions
1 = execute only
2 = write only
3 = execute and write access
4 = read only
5 = read and execute (this is common)
6 = write and read, but not execute
7 = read, write, execute (total control)
Now, there are also, as mentioned earlier, three classes of people.
So in order to chmod something, you need to have three numbers: one
for user, one for group, and one for world. We'll just cut to some examples
now, it's easier to show by example:
chmod 755 index.html
In this example, we mod index.html such that the user (you) has total
access to it. We leave the group able to read and execute it, but not
write it, because we don't want other people to be able to delete or
change it, and same for the "world". You definitely want to
leave read access on your files for the "group" function so
that the webserver (apache runs as a user) can read it.
chmod can also take a -R (capital letter R), which means recursive,
or descend into directories below current directory to make changes
there as well. As long as you remember that write is equivalent to change
or delete, you will be ok.
Some more
examples:
chmod -R 755 ~/www/*
- this is safe, no one can delete / change your files
chmod
600 mysecretnumbers.txt
- no one can read your file but you
chmod 777 ~/*
- DO NOT DO THIS - bad idea, everyone has access to all your files
man - the Unix help system
If you're interested in learning more about the Unix shell commands,
you can always use the man command. The syntax is:
man ls
This will display the man page for the ls command.
The man page contains a description of the command, its syntax,
and any other helpful information. On some terminals, the arrow
keys can be used to navigate the page, on others, only the space
bar is used.