Previous Thread
Next Thread
Print Thread
Rate Thread
#16163 12/21/02 08:21 PM
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
I originaly posted this at Deaths Kitchen but I figured some of you guys might be able to learn from it also. It is not done so please don't post anything below and I will update it as I update the one at DK. Thanks

This is a little lesson for anyone totaly lost. Don't come back and say that is easy [censored]. I am saying now this is the basics.

In Linux you have a totaly different directory structure from windows. Every one has their own folder in the home directory accept root. Root is a default user who runs the syste. his default directory is /root.

see the directory structure here

http://deathskitchen.promodtecnologies.com/cgi-bin/DeathsKitchen2/YaBB.pl?board=OSforum;action=display;num=1013816145

Now in Linux you use forward slashse instead of back ward slashes in windows.

you use / in linux not \

Sooooo the path to your home folder is

/home/Your account name

In the root folder (/) you have certain folder you want to know about

bin - Bianaries are kept here

home - all home directories are stored here. Login under anything but root and you start here

mnt - mount point for all removeable drives. In linux everything is a file/program. Hard drives, printer, CDROM all can be found here

enough spoon feeding, see the link above.

Now once you are logged in and you are in a terminal windows or in text mode you might want to see all the fiels in the directory tou are in. you would use the "ls" command.

$ ls

that will give you something like this

$ls
gnome_setup BTP myxterm

above are 3 file names. In Linux everything is case sensative. BTP is not the same as btp. Rember that. What if you want more info on these files? YOu could use switches. The "-a" switch will allow you to see hidden files. That is any file starting with a "." usally. So in the same directory.

$ ls -a

gives us

$ls -a
. .mysql_history BTP gnome_setup
.. .profile myxterm

what if you wanted even more info on this directory? Well you can use the "-l" switch with the "-a" or without it.

ls -al

gives us

drwxr-xr-x 3 user_name username 512 Oct 28 20:28 .
drwxr-xr-x 41 nobody username 1536 Dec 9 14:10 ..
-rw------- 1 user_name staff 95 Oct 28 20:28 .mysql_history

You get the idea. What the [censored] is that right? Well this is a bit of usefull info. See in Linux you can actually own a file and set who can do what with it. you have 3 levels of access basicaly

World
Group
Owner

each of these levels can have privilages set for read, write and execute.

so...

rwx = read write execute

still with me? You can set levels with the "chmod" command, which we will get to in a moment.

Sponsored Links
▼ Sponsored Links ▼ ▲ Sponsored Links ▲
#16164 12/21/02 08:22 PM
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
okay so we know how to see what is in the folder we are in. Now how do we get to other folders right? Well this is sort of like windows. We would use the "cd" command

now lets say we are in the "/home" directory and there are 3 user accounts of bob, jan and steve on this computer. A simple "ls" command would show us all the directories we could go into below the one we are in.

$ ls
bob jan steve

It would look something like so. From here we could make our choice of where we want to go. Lets say we want to go into bob's directory because we are bob.

$ cd bob
$

This is what your command line would look like. you typed in cd bob then hit enter. The command prompt dose not change but you are in bob's directory now. but what if we decided this is in fact not where we wanted to be. But we forgot the name of the folders above this one. We would use the "ls" command again.
Simpley type in:

$ ls ..
bob jan steve
$

And the above is what you would get. This dose not take you out of the directory, but shows you what is in the directory above the one you are in. You could also use both the "cd" and "ls" commands.

$ cd ..
$ ls
bob jan steve
$

"cd .." would take you up one level, and "ls" of course shows us the files in the directory not hidden. Now if you wanted to just go straight to the root directory, (the equal to c:\) the "/" directory. You would use the cd command.

$ cd /
$

It is that simple. You can be 7 directories deep and zip right back to the root directory with a simple comand. A simple "ls" shows us

$ ls
Mail dev kernel tmp
devices lib opt usr
etc lost+found platform var
bin export mnt cdrom
home sbin xfn
$

Or something realy close get a good look at those directories. Those are the main directories in your root folder. You might have more or one or 2 less but most are universal in any unix/linux/bsd system.

Now lets say you want to create a directory... You simpley type in

mkdir directory name

So this would look something like the following

$ mkdir test

This would make us a directory named /test.

#16165 12/21/02 08:23 PM
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
A quick side note

You should know about the "man" command. The man command allows you to look up any command. Even the "man" command itself. to use it simpley type in "man command here". See example below

$ man ls

this will give you a complet document on the ls command and all of it's switches/attributes. Switches/attributes are what I covered earlier see below

$ ls -al

"-al" are switches or attributes. I say or because some call them switches some call them attributes. I am sure there is one that is right but I just don't care.

I said you could even do this on the man command. see below

$ man man

It is that simple.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

#16166 12/21/02 08:25 PM
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
Now what if we had multiple accounts or we had a non root account and a root account. We don't want to log out every time we want to switch users right? For this we would use the "su" command

$ su jan
password:
$

Did you get that? at the command prompt you would type in "su name_of_user_you_are_switching_to". The system then prompts you for a password by showing us "password:" Here you simpley type in that users password and hit enter. Now when typing in do not be surprised if you don't see squat. You will not see ******* or plain charaters. See this way no on knows how many charaters your password is even if they sre right behind you.

In short nothing is wrong.Now you are loged in as whoever you chose to login as.

#16167 12/21/02 08:32 PM
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
Digital Geek, When you post your tut, just edit your post below. I replyed to your private message. I will edit this one with a good tut before grep and maybe even lead into your tut.

#16168 12/25/02 05:15 AM
Joined: Sep 2002
Posts: 553
UGN Super Poster
UGN Super Poster
Joined: Sep 2002
Posts: 553
�in_tax I left you a private message. When you have some time read it. Later.

#16169 12/25/02 04:08 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
To remove a file:
rm [file]

To remove directory (with or without files):
rm -rf [directory]

To [censored] someones linux box over:
cd /
rm -rf *


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16170 12/26/02 04:03 AM
Joined: Sep 2002
Posts: 553
UGN Super Poster
UGN Super Poster
Joined: Sep 2002
Posts: 553
The 'grep' command.

The grep command is generally used when you need to search a particular word into files (ex: an IP adress in some huge log files).

Supose you have two files:
"file1.txt" that contains the sentence: bad dog
"file2.txt" that contains the sentence: good dog

To search in all the files that have the name begining with the leters "file"
and have the extension txt for the word "dog" you will write :

grep dog file*.txt

You should have the following output :

file1.txt bad dog
file2.txt good dog

The word "dog" apears in all the files that are begining with the letters "file"

If you search for the word "bad" and write :

grep bad file*.txt

You should have the following output :

file1.txt bad dog

The word "bad" apears only in file1.txt

Now, let's supose that the files do not have the same extension. Supose we have "file1.txt" and "file2.doc". To make a search in all the files, that have the name begining with "file" and have different extensions, for the word "dog" you write :

grep "dog" file*.*

You should have the following output :

file1.txt bad dog
file2.doc good dog

The word "dog" apears in all the files that are begining with the letters
"file", no matter the extensions of the files.

Supose you are loged in as root, and you are in the home folder (/home). Now, you want to see, if the user bob has files in his home folder (/home/bob) that contain the word "dog". From the home folder you write :

grep dog bob/*.*

This will do a search in all the files that are in the folder /bob for the word dog. If the user bob keeps his files in a subfolder (/bob/secret) the search will not return nothing, and to search that folder you have to write :

grep dog bob/secret/*.*

The important thing to remember is the charcter "*". This character (wild card) will stand for a string. You can use is to do a big search : grep dog *.* this will search in all the files, no matter the name or extension, or you can use it to do a specific search, as above.

Also keep in mind, that grep is a very complex search tool. It has many options that you can use to improve your search. This file was written to give a basic understanding. For more information read the manual : man grep

#16171 12/26/02 06:59 AM
Joined: Sep 2002
Posts: 553
UGN Super Poster
UGN Super Poster
Joined: Sep 2002
Posts: 553
The 'tar' command.

The 'tar' command is designed to store and extract files from an archive.

The tar command works like this. You write 'tar' then you use one or more than one of the options, then you put the name of the archive and in the end the name of the files/directorys you want to archive.

This tutorial will cover the basics operations : create, list, append, extract.

For the sake of this tutorial, I will presume that you are located in a folder named /dog under your home directory (/bob/dog) wich has the following files in it : file1.txt and file2.txt.
Keep in mind that to create an archive you must have the permission to write in that directory.

1. How to create a tar archive.

a. Archiving files.

To create a tar archive you write :

tar -cvf archive.tar file1.txt file2.txt

You should have this output:

file1.txt
file2.txt

This command will create (-c) a tar archive in verbose mode (-v) that will be named (-f) 'archive.tar' wich will contain in it 'file1.txt' and 'file2.txt'.
The verbose mode will show on your screen exactly what the tar command shows in response. To make the exactly same archive, without the verbose mode you could write :

tar -cf archive.tar file1.txt file2.txt

but you will not see any output. Seeing the output often helps and gives a better understanding.

b. Archiving directories

Now you are located in /dog so to archive this we first must exit this directory (using the command 'cd ..') so now we are located in the /bob directory. Now we can archive the '/dog' directory writing :

tar -cvf dog.tar dog

You should have this output:

dog/
dog/file1.txt
dog/file2.txt
dog/archive.tar

2. How to list a tar archive.

To list the contens of the archive named 'dog.tar' you write:

tar -tvf dog.tar

You should have a similar output like this one:

drwxrwxr-x digitalgeek/digitalgeek 0 2002-12-26 15:16:17 dog/
-rw-rw-r-- digitalgeek/digitalgeek 9 2002-12-24 04:27:28 dog/file1.txt
-rw-rw-r-- digitalgeek/digitalgeek 10 2002-12-24 04:27:41 dog/file2.txt
-rw-rw-r-- digitalgeek/digitalgeek 10240 2002-12-26 15:16:17 dog/archive.tar

This command will list (-t) in verbose mode (-v) the contence of the tar file named (-f) 'dog.tar'. Using the verbose mode will show you a detailed explanation of the files/directories contained in the archive like permisions, owner, the date and the time when this files were created or were last modified.

3. How to append files to a tar archive.

We are now located in /bob where we have the archive named 'dog.tar'. Well to apend a file named 'file3.txt' that is located also in the /bob directory we
would write:

tar -rvf dog.tar file3.txt

You should have this output:

file3.txt

You can also append an entire directory to a archive instead of file3.txt we would write the name of the directory.

Now as you can allready guess, -r is used for append.

List the archive and you should have this output:

drwxrwxr-x digitalgeek/digitalgeek 0 2002-12-26 16:43:24 dog/
-rw-rw-r-- digitalgeek/digitalgeek 10240 2002-12-26 15:16:17 dog/archive.tar
-rw-rw-r-- digitalgeek/digitalgeek 9 2002-12-24 04:27:28 dog/file1.txt
-rw-rw-r-- digitalgeek/digitalgeek 10 2002-12-24 04:27:41 dog/file2.txt
-rw-rw-r-- digitalgeek/digitalgeek 11 2002-12-26 15:45:21 file3.txt

The append command is a little bit tricky. You can append a file to a tar archive even if it has the same name with a file that is allready in the archive. For example you archive a file, than you work on it more and then you use append and put it in the archive one more time. If you will list this archive you will see both files in there, but when you will extract this archive only the version stored last will wind up in the file system, because the newer files are extracted last so the old version wich is extrated first is overwritten by the newer version of the file.

4. How to extract files from a tar archive.

To extract the archive named dog.tar you write:

tar -xvf dog.tar

This will extract (-x) everything that is inside the archive inside the curent directory. Now ... the good part is that, if we had two files named file1.txt inside the archive, we can still extract the older version by writing :

tar -xkvf dog.tar

The -k stands for --keep-old-files wich will not let tar overwride the older version of the file (wich is extracted first) with the newer version. So the newer version is kept in the archive, and only the old version extracted.

To extract a specific file from the archive, for example file1.txt you would have to write :

tar -xvf dog.tar dog/file1.txt

Notice that you have to write the entire path to the file (dog/file1.txt).

to extract only the directory 'dog' without the file3.txt (witch was not in that directory and was appended later) you would write:

tar -xvf dog.tar dog

Notice that the 'tar' command has many other options. This tutorial was written to give a basic understanding. For better understanding read the manual : man tar

#16172 12/27/02 03:55 PM
Joined: Mar 2002
Posts: 815
S
nobody
nobody
S Offline
Joined: Mar 2002
Posts: 815
chmod and file permissions

chmod has two different ways to use it, symbolic or octal(numeric). When you look at a "ls -l" command and its spews forth the directory information followed by:

drwxrwxr-x digitalgeek/digitalgeek 0 2002-12-26 16:43:24 dog/
-rw-rw-r-- digitalgeek/digitalgeek 10240 2002-12-26 15:16:17 dog/archive.tar
-rw-rw-r-- digitalgeek/digitalgeek 9 2002-12-24 04:27:28 dog/file1.txt
-rw-rw-r-- digitalgeek/digitalgeek 10 2002-12-24 04:27:41 dog/file2.txt
-rw-rw-r-- digitalgeek/digitalgeek 11 2002-12-26 15:45:21 file3.txt

such as in the case of DG here, notice the -rw-rw-r--
this notacion stands for being either readable, writable, and/or executable(non of his files were executable).
There are three different colums of "rwx" for the different owners the first is for g or group the second is o other and third is u user.

Using symbolic notation,
a = all (g, o, and u)
g = group
o = other
u = user

+ = add a setting
- = remove a setting

r = readable
w = writable
x = exectuable
s = set to this UID or GID

so you can:

chmod a+rx file1.txt

this will allow everyone to read and execute the file but they cannt write to it or modify it.

using octal notation

0 = ---
1 = --x
2 = -w-
3 = -wx
4 = r--
5 = r-x
6 = rw-
7 = rwx

using octal notation you can set the same permisions to that file by

chmod 555 file1.txt

the first number is for the group permissions, second is other permissions and third is user permissions.

#16173 01/28/03 08:28 PM
Joined: Nov 2002
Posts: 1,146
Likes: 1
Ice Offline
UGN News Staff
UGN News Staff
Joined: Nov 2002
Posts: 1,146
Likes: 1
thanks for all this info = ) I just got a free p2 Linux box that i can learn on and all these commands really helped me. Also explained a lot of the questions i had.
Thanks again


Good artists copy, great artists
steal.

-Picasso
#16174 01/28/03 09:01 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
::claps:: ebook creation time ::puts on hard hat::


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16175 01/28/03 10:37 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
Ok, for note to everyone, 3 tutorials came out of this topic:

GREP Tutorial
CHMOD Tutorial
TAR Tutorial

If you'd like to have an article put on the main page, of you've located an article that should be in our KBASE feel free to send me a PM.


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#16176 03/02/03 07:04 PM
Joined: Nov 2002
Posts: 1,146
Likes: 1
Ice Offline
UGN News Staff
UGN News Staff
Joined: Nov 2002
Posts: 1,146
Likes: 1
heres a site i also found today
Helped me alot also = )

http://www.ee.surrey.ac.uk/Teaching/Unix/

Mabye it could help other noobs out there intrested in learning = )


Good artists copy, great artists
steal.

-Picasso

Link Copied to Clipboard
Member Spotlight
None yet
Forum Statistics
Forums41
Topics33,840
Posts68,858
Members2,176
Most Online3,253
Jan 13th, 2020
Latest Postings
Top Posters
UGN Security 41,392
Gremelin 7,203
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Likes Received
Ghost 2
Dartur 1
Cyrez 1
Girlie 1
unreal 1
Powered by UBB.threads™ PHP Forum Software 8.0.0