S.O.T.A. Revolution     |   home
Hacking Documents   |   Ancient Rune 1   |   Ancient Rune 2   |   Ancient Rune 3   |   Basic UNIX FAQ   |   Basic Usage UNIX Commands   |   Becoming a Uebercracker   |   Hacking: A State of Mind   |   Hack Kit   |   Neophyte's Guide to Hacking   |   The Hackers Manifesto   |   Newbie's Handbook   |   The Official Phreaker's Manual   |   The UNIX File system   |   Virus FAQ
Basic Usage UNIX Commands
Plus a chmod intro By InSaNiTy

This is for the most part just some basic commands for moving through the
file system, and some file modification commands. The command is show on
the left with a colon after it, then a description and example usage(for
some of the more "complicated" commands).
NOTE: Some DOS commands have an equivalent for deleting/modifying
directories, most UNIX commands on the other hand simply use a flag or
option. Most programs accept options by typing "programname -options"
Many commands use the "-r" or "-R" option to delete directories or copy
them. This -R/-r means recursive, try dictionary.com for that one.
Second NOTE: UNIX commands are CASE sensitive, meaning "ls" is not the
same thing as "lS". Meaning when you type a command, type it as you see
it, without the quotes.
ls: Show files in directory, the equivalent of the ms-dos "dir"
command.
cd: Change directory. Same as the ms-dos "cd" command, for example:
"cd /xspace" will move you into the /xspace directory.
mv: Move, move directories or files, also the equivalent of the
rename command in DOS. For example "mv blah .." will move blah
one directory up. Or "mv blah black" will rename blah as black.
rm: Remark, or also known as remove/delete, the equivalent of the
dos del/deltree command. To delete a directory, use the -R flag.
"rm blah" would delete the file blah, to delete a directory, "rm
-r somedir" will recursively delete the directory and all it
contents.
cp: Copy, to copy files/directories. "cp blah blah1" would make a
copy of the file blah with the name of blah1. "cp -r blah blah1"
would be if blah was a directory. Again notice the -r option for
directories. -r in these commands means "recursive" look it up.

cat: concatenate or print files. cat will basically print the
contents of a file, whether it is binary or text. Shows the data
in the file, "cat blah" would show me the contents of blah, if it
were a program, I would most likely see lots of extended ASCII
chars and hear lots of beeps.
man: Manual page, most decent programs/commands will have a man page
type "man command" to view the manual page for that command.
Linux tends to have Poor, spotty, inconsistent man pages. OpenBSD
tends to have the best.(I am a OpenBSD user so I am biased).
du: Shows file size, on OpenBSD at least, du -k will show the amount
of kilobytes the file uses.
df: Show the amount, and percentage, of free space/used on a
partition. Again, df -k will show everything in Kilobytes.

Those are the basic commands use to navigate and copy/move data. If your
using a shell account, and you try these commands, but are either denied
or not there, and your VERY sure you used it right, bitch to the sysadmin
because that is a fucked up shell account.

Here are some commands use to set file permissions, or modify the ability
to alter files, otherwise known as permissions.

chmod: Change file permissions, please see the end of this file as this
command requires a more detailed description than here.
chown: change the owner of a file, like "chown stevenm blah" would make
blah owned by stevenm, usually, you cannot change the owner of a
file(for example one of your own) to someone else.
chgrp: same as chown except changes the group of a file, rules about
being able to change the group of your files to someone else is
the same as chown.
Quick intro to ownership:
This is kinda necessary for the below.....
Anyways, UNIX/Linux are multi user operating systems. Meaning, one users
files/programs/everything is separate from other users. The user that
owns a file is called the owner. Files also have a group, meaning the
group they are owned by, usually they are group whoever owns the file.
But a file can easily be owned by 'root' and group 'wheel' meaning,
anybody in the group wheel will be able to do whatever the group
permissions allow them to.
Then there is the 'other' category, meaning everyone not the owner or in
the group that the file is.
Chmod intro:

Chmod is the command used to alter file permissions. UNIX being a
multi-user operating system(compared to the single user environment of
windows 9x) allows you to decide who can do what to your files.
Try typing "ls -l" sometime, the -l means long format, which shows file
permissions as well as some other file properties. Probably will looking
something like this, note, below output is taken directory from my home
directory. Also, it gives each column a field number for future
reference, this is not what will be displayed using ls:
Field 1 2 3 4 5 6 7 8 9
-rwxr-xr-x 2 stevenm stevenm 23 Apr 9 07:42 .plan -> /bin/sh
-r-x---r-x 1 stevenm stevenm 7383 Apr 9 07:45 PERL
-rw------- 6 stevenm stevenm 2983762 Apr 6 02:32 pornmovies
-rw------- 1 stevenm stevenm 5837 Apr 9 05:34 pornpics
drwx------ 1 stevenm stevenm 612 Apr 9 01:22 cdrom

<output snipped...>
Lets take a look at the most important field here, field number 1, this
shows the permissions on the file. Lets analyze this for a second:
-rwx------ The first dash will be a 'd' if it is a directory, then the
next 3 spaces are the permissions for the owner. So that rwx there means
what the owner of the file can do.
r = read
w = write
x = execute
So -rwx------ would mean that it is a file, and the owner can read, write,
and execute it.
The next set of 3 spaces are the group permissions. So -rwxr-x--- would
mean that the owner can read, write and execute it, and the group of the
file can read and execute it.
The last 3 spaces mean what others can do to that file, meaning if they
aren't in the group of the file, they don't own the file, then they are
'other'. So the following perms: drwxr-xr-x would mean that it is a
directory (the d at the beginning) and the owner can read write and
execute the file. The group can read and execute, and others can read and
execute.
Field 2 is unimportant. Field 3 where it says 'stevenm' for the first
time is the owner of the file/dir. The second stevenm, or field 4, is the
group of the file. Field 5 is the size of the file/dir in bytes.
Field 6-8 is the date and time the file was last modified. Finally, field
9 is the name of the file or directory.... that .plan -> /bin/sh means
.plan is linked to another file, in this case /bin/sh, so when you view
the contents of .plan or modify it, your modifying /bin/sh. For more on
symlinks see 'man ln'.
Applying permissions
Applying permissions with chmod can be done in two ways, using numeric
notation, or symbolic notation.
The numeric notation is what most UNIX users use, as it is shorter and
more powerful. I will start with symbolic notation for the sake of
newbies.
Symbolic notation uses 3 letters, or symbols to represent permissions.
u = owner
g = group
o = others
Lets use the pretend file "blah" without the quotes. If the file blah
already had the permissions -rwx------ and I wanted to make it so people
in the same group as me could write to it, I would do: "chmod g+w blah"
although that isn't useful without read so "chmod g=rw blah".
Lets analyze above two commands.
"chmod g+w blah" what this means is, add (w)rite permissions to the file
blah for (g)roup. Pretty simple. Now, "chmod g=rw blah" can be used to
apply all the perms for a category at once, so "g=rw" means, the perms for
group are read and write. Using = applies whatever you put after it as
the total perms, meaning, if g currently had just execute permissions,
that would change completely to read and write, = overwrites the current
permissions.
Here are some examples:
"chmod g+rw blah" add read and write for group
"chmod o+rx blah" add read and execute for others
"chmod o= blah" others cannot read write or execute
"chmod u+rwx blah" add read, write, and execute for the owner
"chmod o-rwx blah" remove read write and execute permissions for others
Using + will add the permissions to the file, not overwriting any current
permissions. - obviously will remove those permissions if it currently
exists. = will overwrite all permisions for that field.
Numeric notation tends to be more powerful, and faster. Using numerical
notation is personally my preferance.
Using numerical notation, consider each set of 3 a place value, for
example, the first 3 dashes(owner perms) are the hundreds place, and the 3
middle dashes(group perms) are the tens place, and the last 3 dashes are
the ones place(other perms). Using numerical notation, a number
represents each possible permission.
4 = read perms
2 = write perms
1 = execute perms
0 = no perms
So, to apply rwx for owner, you add all these together, and get 7, for
owner perms that 7 would go in the hundreds place, so lets say you want to
make 'blah' rwx by owner, and nothing for group or others. You would do:
"chmod 700 blah". See, by adding the number for read write and execute,
we get 7, and that goes in the hundreds place, 0 is no perms so we put a 0
in the tens(group) and ones(others) places.
The best way with numerical notation is probably to see examples so here
we go:
"chmod 755 blah" 4+2+1=7 for owner, 4+1=5 for group and others. This
would make blah look like -rwxr-xr-x .
"chmod 644 blah" 4+2=6 for owner, 4 = read for group and others. This
would make the perms look like -r-xr--r-- .
"chmod 700 blah" 4+2+1=7 for owner, 0 = no perms for group and others. This
would make the perms look like -rwx------ .
"chmod 722 blah" 4+2+1=7 for owner, 2 = write for group and others. This
would make the perms look like -rwx-w--w- BTW: This would
be a very stupid thing to do.
Well, that should cover chmod. This didn't cover
setting the SUID/SGID bit on files, but if your reading a doc on chmod,
you probably don't need to know that. For further referance see the
OpenBSD man page for chmod, viewable online at www.openbsd.org

HOME (Hackers.com)