Sie sind auf Seite 1von 22

Remember that almost everything in

Linux is a file? Well, that goes for


programs, too. Every command you run
(that isn't built into
the shell) resides as a file somewhere.
You run a program simply by specifying
the full path to it.

In a commandline environment, the user interface is provided by a "shell", which


interprets commands and generally makes things useable. Immediately after logging
in (which is covered in this chapter), users are put into a shell and allowed to go
about their business. This chapter serves as an introduction to the shell, and to the
most common shell among Linux users-- the Bourne Again Shell (bash).

A shell is a command interpretor that makes possible to issue commands in Linux

The Linux shells:

- bash = Bourne again Shell - default pt majoritatea distributiilor Linux


- sh = Bourne Shell
- csh = C shell
- Ksh = Korn Shell
To view the shell you have after login:
echo $SHELL

man command
Ex. man ls

man -k keyword -> to search for a keyword in man pages


Ex. man -k time

Command lsof - lists open files

Home directories
- the initial directory in which the users are placed when they first log on
- the user is the only one who will be able to access this directory besides the sys admin
- linux user typically have full rights on their own home directories

ex. /home/geoana
Displaying available disk space
- df = disk free - displays free space on one or more mounted disks or partitions
- du = disk usage - estimates file space usage and summarizes disk usage of each file + it
summarizes disk usage recursively for each directory

Files Listing
- ls
- ls -l
- ls /bin

Files Locating
- find
- locate
- which
- whereis

Ex.

find directory search_criteria


^
|
name,type,size,owner,date of creation/modification

find . -name "*.cc" - find all files beginning with the current directory which extension is cc

find / -name file -print |xargs grep -i -n "time"


^ ^
| |
displays the displays full path
full path of all files of your specified
on your Linux system file

grep searches the content of a file


options -i is for ignore(case insensitive) and -n to display the line where the keyword time was
found

xargs means eXecute the arguments after

display the full path and name of files on your system beginning with m:

find / -name "m*" -print

Find is a very useful and powerful utility. It is often used by system administration and in shell
scripts. Here
are 2 commands that might be useful:

find / -perm -4000 -print

This command will find every file on the system that is suid. This means that when you run it you
will be
running it as an other user. For example, traceroute is a utility that needs to be run as root. To
allow users to
run it, systems administrators will set it suid root so it will be run as root even if a user starts it.
This can be
useful, but can also be a big security risk if the utility has a security hole in it.

Here is another interesting command:


find / -atime +10 -print

This command will find all the files accessed more than 10 days ago. Commands like this one can
be useful
to find old files that need to be backuped or erased.

locate lsofb

which ls gives the directory which contains the binary ls

Swap and memory


One important setting in any protected mode operating system like Linux is the swap space. In
the
installation, you will need to create a swap partition. A common question is what size should the
partition be?
The proper size depends on 2 things: The size of your hard drive and the size of your RAM
memory. The less
RAM you have, the more swap you will need. Usually you will want to set your swap space size
to be twice
the RAM size, with a maximum of 128 megs. This of course requires you to have a hard drive
with enough
free space to create such a partition.
If you have 16 megs of RAM, making the swap space 32 megs or even 64 megs is very
important. You will
need it. If you have 128 megs of RAM on the other hand, you won't need much swap because the
system will
already have 128 megs to fill before using swap space. So a swap partition of 128 megs or even
32 megs
could be enough.
If you don't select enough swap, you may add more later.
Allowing users to mount drives
By default, Linux will not allow users to mount drives. Only root can do it, and making the mount
binary suid
root is not a good idea. With a special command in the /etc/fstab file, you can change that.
This is a typical line for the fd0 (A:) drive in /etc/fstab:
/dev/fd0 /mnt auto noauto,user 1 1
The keywords here are noauto and user. Noauto tells mount not the try to mount a diskette on
boot, and user
allows any user to mount the drive into /mnt. The auto keyword is also interesting. It tells mount
to try to find
out which file system is on the diskette. You could also use msdos or ext2.

Allowing users to run root programs


When a user starts a command, it runs with the permissions of that user. What if you want to
allow them to
run some commands with root permissions? You can, and that's called suid.
You can set a command to be suid root with the chmod command. This will make it run as root
even if a user
starts it. Here is how to set mybin suid root:
chmod +s mybin
Note that you must be very careful with this option. If the command has any security hole, or
allows the user
to access other files or programs, the user could take over the root account and the whole system.

Default file permissions


When you create a file, the system gives it default permissions. On most systems the permissions
are 755
(read, write and execute for the owner, and read and execute for others).
This default is setup with the umask command. To use the command, you need to find the right
octal number
to give it. The permissions in the umask are turned off from 666. This means that a umask of 022
will give
you the default of 755. To change your default permissions from 755 to 700, you would use this
command:
umask 077

read = 4
write = 2
execute = 1

FTP access restrictions


When you first install Linux, it comes with a lot of Internet services running, including mail,
telnet, finger
and FTP. You really should disable all those that you don't need from /etc/inetd.conf and your
startup scripts.
FTP may be very useful, but must be configured correctly. It can allow people to log into their
accounts, it
can allow anonymous users to login to a public software directory, and it can display nice
messages to them.
The files that you will probably want to modify are /etc/ftpusers and /etc/ftpaccess.
The file /etc/ftpusers is very simple. It lists the people that will not be allowed to use FTP to your
system. The
root account, and other system accounts should be in that file.
The file /etc/ftpaccess is a bit more complex and controls the behaviour of the FTP server. It tells
it what to
use as README file to display on a directory listing, what kind of logs to create and what
messages to
display.
Note that if you create an anonymous FTP area, you will need to read the FTP man page and do
exactly what
it tells you to avoid possible security risks.

Shutdown and power off


Linux, like most other operating systems, must be shutdown in a specified manner. You can't turn
the power
off on a computer running Linux, or you may lose some data.
Here are the steps that need to be done when you want to shutdown:
• The operating system needs to stop all the running processes and logout the users.
• Various servers need to be shutdown in a proper way.
• All the mounted file systems need to be unmounted safely and unwritten data need to be
stored
on the disk.
The system can then be turned off safely.
To accomplish all these tasks, the shutdown command exists. That command has a lot of options,
and you
should explore them before trying anything at random. Another way to shutdown a Linux system
is to set the
runlevel to 0, the default shutdown level, with the init program.

Hard to erase files


File names in Linux can have many letters and numbers in them. Usualy, names should not have
spaces in them, although Linux can deal with them. There are some characters that should not be
used in files, like "/" and "~". Some programs unfortunately will create strange looking file
names, often as temporary files. Using the rm command, you should be able to remove them, but
it may be hard when strange alphanumeric characters are used. Here are a few ways you should
try to get rid of a file with a strange name: • First you should try the following: rm -f "file
name" • If this doesn't work you should try the console program mc. • With graphical file
managers, you should be able to pick an icon and remove it, regardless of the file name.
Files permissions
When you try to run a file it may refuse to work with an error like "Permission denied" and when
you try to
view another file it may also say that you don't have permission to view it. These all come down
to file
permissions, a basic feature of Unix.
There are 3 types of permissions: read, write and execute. When you list files it will say which
permission the
files have:
ls -l file.dat
-rw-r--r-- 1 root users 1656 Mar 22 00:27 file.dat
The first part of that line is the permissions. They are, in order, the user permissions, the group
permissions
and others permissions, where r means read, w means write and x means execute. For this file, the
user, root,
has read and write permission (rw-), the group, users, can only read the file (r--) and everyone
else can also
only read the file (r--).
Other letters may appear. The first letter is - for a normal file, d for a directory and c or b for a
device. In
place of x you may see a letter s. This means that when you start a program, it will run as its
owner.

Changing file permissions


To change a file's permissions, you need to use a program called chmod. With that command you
can change
one or multiple file permissions. Here are a few examples:
$ chmod 755 file
$ ls -l file
-rwxr-xr-x 1 root users 1656 Mar 22 00:27 file
$ chmod 700 file
$ ls -l file
-rwx------ 1 root users 1656 Mar 22 00:27 file
$ chmod 664 file
$ ls -l file
-rw-rw-r-- 1 root users 1656 Mar 22 00:27 file
The numbers are based on the 3 types of permissions. Read = 4, write = 2 and execute = 1. A
permission of
755 means the user will have read, write and execute permissions (4 + 2 + 1 = 7), and everyone
else will have
read and execute permissions (4 + 1 = 5).

Documentation and manual


Software under Linux rarely comes with printed documentation. Some do, like the GIMP and
Blender, but
most only come with online documentation. This way, you can get the documentation at the same
time that
you download the program.
There are 2 traditional ways to provide documentation under Unix and Linux:
The first is man pages. These are small files containing information about every command you
have on your
system. For example, if you want to know what the command df does, simply type:
man df
The man system works with level of commands, from 1 to 8, plus other extensions. For full
details about the
man program, simply see its manual page:
man man
The second way to provide help is with the info system. These are usually much bigger files (the
libc info
files have more than 10,000 lines of text).
To access info files, simply type the info command. It is a bit harder to use, but you can get help
by typing h.

Display IP rather than hostname


When dealing with networking issues, it often helps to be able to use only IP addresses rather
than
hostnames. Why? For 2 reasons. First, the name server might not always be available if routing is
being
changed. And most important, you may not have the time to wait for all the IP resolving to be
done.
Fortunately, many networking utilities in Linux share a common option flag. The -n flag. It will
allow you to
make the utility display IP addresses rather than hostnames. Here are a few examples:
netstat -an
traceroute 1.2.3.4 -n
arp -n -a -i eth0 -a proxy
These commands were all given the -n flag and will display only IP addresses.

uname -a displays information about machine, processor,operating system

Access to various networks


Big corporations often sub-divide their networks into small networks, hidden behind gateways.
To access
them, you need to tell your Linux system that there is a gateway to use to access the networks.
The route program makes it easy to add networks, hosts and gateways to your routing table. To
add a default
gateway, for example to access the Internet, you can set it as default with the following line:
route add default gw 10.0.0.1
This will work if you need to access the Internet via the 10.0.0.1 gateway. Now, if you want to
access
networks 10.1.0.0 and 10.2.0.0 through other gateways, here is what you will want to do:
route add -net 10.1.0.0 gw 10.0.0.10
route add -net 10.2.0.0 gw 10.0.0.20

Accessing remote file systems


SMB is the most popular protocol to access Windows systems. But from the Unix world comes
NFS. NFS is
a way to share files that predates SMB and Samba, and comes compiled in most Linux
distributions. To
enable file sharing, you must have the nfsd and mountd daemons running. You also need to add
the IPs of the
systems you want to allow in /etc/exports.
To access remote file systems, you simply mount them like local hard drives. To mount /usr/files
from 1.2.3.4
into /mnt/files, simply type:
mount -tnfs 1.2.3.4:/usr/files /mnt/files
The -tnfs parameter may be omited.

Secure alternative to telnet


Telnet is a protocol allowing you to connect to a remote system and run programs and commands
on that
system. It is very old and still very much in use today.
Unfortunately, a telnet client sends the user password as clear text, and the connection is not
encrypted. On
the other hand, a program called ssh exists that can replace both telnet and ftp in a secure,
encrypted way.
Ssh stands for Secure Shell. It will encrypt each connection with a random key, so that it is
impossible or at
least very hard for a third party to decrypt the connection and find the password, or spy on you.

Who owns this port


Several utilities exist to check which ports are open, who is connected to your system and even
what process
owns a port number.
First a few ground rules. Ports below 1024 are reserved for common services, and only root can
use them.
Standard port numbers can be found in /etc/services. The maximum number of ports is 65k, so
you have more
than enough Internet ports for all your services.
Here are some useful utilities. Netstat is a command that will list both the open ports and who is
connected to
your system. You should run it like this:
netstat -an | more
This way you can find out who is connected to which service.
Another interesting command is the fuser program. This program can tell you which user and
process owns a
port. For example, the following command will tell you who owns port 6000:
fuser -v -n tcp 6000

How to compile and execute a program in linux:

gcc is for a C program


g++ is for C++

gcc -o file file.c

-o means the executable file

gcc -o ex ex.c
and you run ex by writing
./ex

Parsing the command line in BASH


Bash is a shell, but it's also a scripting language. You can make bash scripts, and you can pass
parameters to
it. You can access the parameters with $1, $2, ... But what if you need the whole command line?
Bash uses special variables for all kind of purposes. One of them is $* which contains the whole
command
line. You can use it rather than the $1, $2 if all you need is a string of text, passed on the
command line.

Don't grep grep


A useful tool in scripting is the "grep" function. This program will find a string in a file. It is often
used also
to find if a process is running:
ps ax | grep sendmail
That command will find if sendmail is running. The problem is that you might end up with an
other entry for
this command. Because you grep for "sendmail", you may well end up with this command
showing because
the "sendmail" string is in the command line. To avoid that, you can use the -v flag to grep:
ps ax | grep sendmail | grep -v grep
That command will find all the lines in the current process list that have the "sendmail" string in
it, and will
remove the lines containing the string "grep".

Move a text into upper case letters


When you want to do text manipulation, you can use Sed and Awk. These 2 tools which come on
most Linux
distributions, will allow you to modify text files in many ways.
To move a text file into upper case letters, you can use Awk in the following way:
awk '{ print toupper($0) }' old_file > new_file
Sed and Awk are useful for a lot of other uses, and are integrated in several products.

Segmentation fault
One of the most common problems when making software is errors like "Segmentation fault",
also called
SegFault. Here is what a SegFault is.
Virtual memory in a computer can be created in 2 ways: pages or segments. Paging means that
the memory is
divided in pages of equal size, containing words of memory in it. Segmentation means that every
process has
a segment of memory of needed size, with gaps of empty memory blocks between the segments.
The operating system knows the upper limit of every segment, and every segment begins at a
virtual address
0. When a program accesses a memory block, it calls a virtual address that the Memory
Management Unit
(MMU) maps to a real address. If the operating system sees that the requested address doesn't
match any
valid address in the segment, it will send a signal to the process terminating it.
SegFaults are the direct result of a memory error. The program has a bad pointer, a memory leak
or any kind
of error that makes it access the wrong memory address. To correct these errors you need to
check pointers and arrays for errors.

Who is online?
Many system administrators use scripts to help them in the process of managing a server. A
common problem
is finding out exactly what users are on the system and what they are doing.
Several tools are available on the system to see who is online, what processes are running, and
pipeing them
together can resolve many problems. Here are 2 small scripts that will show, first if a user is
online, and then
what he is running:
who | grep $1
ps -aux | grep $1
The variable $1 here means the first command line argument, from a shell script. The who
command first
checks if the user is online, then ps will show all the processes currently running under that user's
UID.

The variable $1 here means the first command line argument, from a shell script. The who
command first
checks if the user is online, then ps will show all the processes currently running under that user's
UID.
You can use also w comand which will tell you what users are on a system and what they are
doing.

Talking to the terminal


Under DOS, or other text based systems, there is only one way in and one way out. Under Linux
and every
Unix system, there is one way in but two ways out.
The terminal has 2 outputs, one for standard output and one for errors. By default, they both
display on the
same device: your monitor. But they can be redirected, for example, to different logs. This is why
it's
important for you to use them properly.
The standard output is called stdout, and printing to it will print to the screen, or where it is
redirected. In C, it
may look like this:
fprintf(stdout, "Test\n");
The standard error is called stderr:
fprintf(stderr, "Error\n");
To input, you need to read from the standard input, called stdin. They are all available to you
from the stdio.h

Talking to the terminal


Under DOS, or other text based systems, there is only one way in and one way out. Under Linux
and every
Unix system, there is one way in but two ways out.
The terminal has 2 outputs, one for standard output and one for errors. By default, they both
display on the
same device: your monitor. But they can be redirected, for example, to different logs. This is why
it's
important for you to use them properly.
The standard output is called stdout, and printing to it will print to the screen, or where it is
redirected. In C, it
may look like this:
fprintf(stdout, "Test\n");
The standard error is called stderr:
fprintf(stderr, "Error\n");
To input, you need to read from the standard input, called stdin. They are all available to you
from the stdio.h file.

Library types
Two types of libraries exist on most operating systems: shared and static. On Windows, they
are .DLL, for
dynamically linked library, and .LIB for static library.
On Linux and most Unix, they are .so and .a files. The shared libraries, the .so files, are loaded at
runtime.
The .a files, or static libraries, are loaded at compile time and are no longer required to run the
binary program.

Shared library not found


Binaries need to load shared libraries at runtime. They are files on your system that provide
functions to the
program. Sometimes the program will report that a shared library was not found, and it will abort.
To find which libraries a program needs, you can use the ldd program. It will list all those
libraries and those
missing. If you know that a library is installed, maybe you need to add it to the current library
path. The path
used to look for shared libraries is in /etc/ld.so.conf. You can modify that file and add any path
you want,
then as root run the ldconfig program.

cd si ENTER -> te duce in home directory


cd ~ -> te duce tot in home directory

rm -f file -> sterge fisierul fara confirmare


cp -r directory dir2 -> copiaza recursiv din directory in dir2
mv file1 file2 -> redenumeste file1 in file2

pwd = print working directory , adica calea unde te afli

debugging with gdb

gdb binar core

ex.

Reading a foreign file system


File systems are defined in the kernel. The kernel supports many file systems, but they need to be
compiled
in, or compiled as a module. When you compile a file system in the kernel, all you need to do is
use mount
with the -t option and the right file system type.
If you have compiled a driver for a file system as a module, then you need to load the module
first.
Here are a few of the available file systems:
• msdos: This is the FAT file system used by DOS.
• vfat: This is the FAT32 file system used by Windows 95 and Windows 98.
• ext2: This is the default Linux file system.
• iso9660: This is the default CD-ROM format.

Mai exista si ext3.


Read files from FAT32 drives
The Linux utility mount can read any file system that the kernel supports. Since version 2.0.34,
the kernel
supports FAT32, which is the main file system used by Windows 98.
To read the FAT32 file system you need to specify the -tvfat option to mount. Here is an
example:
mount -tvfat /dev/hdb1 /mnt

Make a symbolic link:


ln -s source destination

ln -s /usr/src/linux/include/asm /usr/include/asm
ln -s /usr/src/linux/include/linux /usr/include/linux

Sorry but this host is not in my list

You need to put a line in /etc/hosts.allow:

Access to various networks


Big corporations often sub-divide their networks into small networks, hidden behind gateways.
To access
them, you need to tell your Linux system that there is a gateway to use to access the networks.
The route program makes it easy to add networks, hosts and gateways to your routing table. To
add a default
gateway, for example to access the Internet, you can set it as default with the following line:
route add default gw 10.0.0.1
This will work if you need to access the Internet via the 10.0.0.1 gateway. Now, if you want to
access
networks 10.1.0.0 and 10.2.0.0 through other gateways, here is what you will want to do:
route add -net 10.1.0.0 gw 10.0.0.10
route add -net 10.2.0.0 gw 10.0.0.20

Accessing remote file systems

To access remote file systems, you simply mount them like local hard drives. To mount /usr/files
from 1.2.3.4
into /mnt/files, simply type:
mount -tnfs 1.2.3.4:/usr/files /mnt/files
The -tnfs parameter may be omited.

Below, you will find descriptions of the major top level directories under Linux:
/bin
Essential user programs are stored here. These represent the bare minimum set of
programs required for a user to use the
system. Things like the shell and the filesystem commands (ls, cp, and so on) are stored
here. The /bin directory usually
doesn't receive modification after installation. If it does, it's usually in the form of package
upgrades that we provide.

/boot
Files that are used by the Linux Loader (LILO). This directory also receives little
modification after an installation.

/cdrom
Remember that all drives have to be mounted to a directory on the main root directory?
Well, /cdrom is provided as a
mount point for your CD-ROM drive.

/dev
Everything in Linux is treated as a file, even hardware devices like serial ports, hard
disks, and scanners. In order to
access these devices, a special file called a device node has to be present. All device
nodes are stored in the /dev
directory. You will find this to be true across many UNIX-like operating systems.

/etc
This directory holds system configuration files. Everything from the X Window
configuration file, the user database, to the
system startup scripts. The system administrator will become quite familiar with this
directory over time.

/home
Linux is a multiuser operating system. Each user on the system is given an account and
a unique directory for personal
files. This directory is called the user's "home" directory. The /home directory is provided
as the default location for user
home directories.

/lib
System libraries that are required for basic operation are stored here. The C library, the
dynamic loader, the ncurses
library, and kernel modules are among the things stored here.

/lost+found
When the system boots, the filesystems are checked for any errors. If errors are
detected, the fsck program is run to see if
any can be corrected. The corrected parts of the filesystem are written to the /lost+found
directory.

/mnt
This directory is provided as a temporary mount point for working on hard disks or
removable drives.

/opt
Optional software packages. The idea behind /opt is that each software package installs
to /opt/<software package>, which
makes it easy to remove later. Slackware distributes some things in /opt (such as KDE in
/opt/kde), but you are free to add
anything you want to /opt.

/proc
This is a unique directory. It's not really part of the filesystem, but a virtual filesystem that
provides access to kernel
information. Various pieces of information that the kernel wants you to know are
conveyed to you through "files" in the
/proc directory. You can also send information to the kernel through some of these
"files". Try doing cat /proc/cpuinfo.

/root
The system administrator is known as "root" on the system. root's home directory is kept
in /root instead of /home/root. The
reason is simple. What if /home was a different partition from / and it could not be
mounted? root would naturally want to
log in and repair the problem. If his home directory was on the damaged filesystem, it
would make it difficult for him to log
in.

/sbin
Essential programs that are run by root and during the system bootup process are kept
here. Normal users will not run
programs in this directory.

/tmp
The temporary storage location. All users have read and write access to this directory.

/usr
This is the big directory on a Linux system. Everything else pretty much goes here,
programs, documentation, the kernel
source code, and the X Window system. This is the directory to which you will most likely
be installing programs.
/var
System log files, cache data, and program lock files are stored here. This is the directory
for frequently-changing data.

find
The find(1) command will search for anything. I want to search the entire system for
the default xinitrc file on the system.
$ find / -name xinitrc
./var/X11R6/lib/xinit/xinitrc
find will take a while to run, since it has to traverse the entire root directory tree.
And if you run this command as a normal user, you
will probably get permission denied error messages for directories that only root can
see. But find found our file, so that's good. If
only it could be a bit faster...
locate
The locate(1) command searches the entire filesystem, just like the find command
can do, but it searches a database instead of the
actual filesystem. The database is set to automatically update at 4:40AM, so you
have a somewhat fresh listing of files on your
system. You can manually run updatedb(1) to update the locate database (before
running updatedb by hand, you must first su to
the nobody user). Here's an example of locate in action:
$ locate xinitrc # we don't have to go to the root
/var/X11R6/lib/xinit/xinitrc
/var/X11R6/lib/xinit/xinitrc.fvwm2
/var/X11R6/lib/xinit/xinitrc.openwin
/var/X11R6/lib/xinit/xinitrc.twm
We got more than what we were looking for, and quickly too. With these commands,
you should be able to find whatever you're looking for on your Linux system.

ifconfig
Now that your kernel can talk to your network hardware, what's needed is a way for
software to tell the kernel to pass some
information along, and vice versa. We need to configure an interface. We need
ifconfig(8).
ifconfig is probably best learned by example; you may want to just take a look at
your rc.inet1 file (covered in the section called
rc.inet1) to see how it's done there. The simplest and most common case looks
something like this:
# ifconfig eth0 192.168.1.10 broadcast 192.168.1.255 \
netmask 255.255.255.0
This line brings up eth0 (the first ethernet interface; for token ring use tr0, ppp use
ppp0, etc.) with an IP of 192.168.1.10, a
broadcast address of 192.168.1.255 (the entire 192.168.1 subnet) and a netmask of
255.255.255.0 (indicating that all of the first
three parts of the "dotted quad" of the IP address refer to the network, while all of
the last part, .10, refers to the host). Unless you're
doing something funky, you can almost always use a broadcast address that's the
first three parts of your IP followed by 255. You
can also almost always use a netmask of 255.255.255.0. If you are doing something
funky, you probably know enough that this part
of the book isn't going to be of much use to you.
ifconfig can also be used just to see what's there. Run it without any options or
parameters to get a listing of all of your current
network interfaces and their settings

route
In order to know where to send which data, the kernel maintains a routing table. I'm
not going to go into much detail about it here, but
you can view the routing table by running /sbin/route(8). route -n will give you the
table with IP addresses instead of names; this is
useful if you're having trouble talking to your name server or if you're just not
interested in the illusory world of domain names.
Fortunately, if you have a simple network setup (and most people do), the 2.2 kernels
will automatically create the necessary routing
table entries for you.

netconfig
netconfig is part of the Slackware setup program, but like most of setup's
components it can be run on its own. netconfig is very
straightforward, and will walk you through setting up a basic network connection. It's
an especially good program to use if you're not
very familiar or comfortable with the network rc files. When you run netconfig, you'll
be greeted with this screen:

Next, you'll be prompted to enter the hostname and domain name of your computer.
You can probably just make something up for
both of these, unless you are setting up a server or other machine that lots of people
will use. Then, you will be asked if you will be
using a static IP, DHCP, or just loopback.

If you are not going to be connected to a network, choose loopback. If you are setting
up a computer that will be attached to a
university or large office network, you should most likely choose DHCP. Otherwise,
choose static IP. Unless you chose static IP, you
are now done. If you did choose static IP, you will now have to enter your computer's
IP address, network mask, broadcast address,
and name server address. netconfig will tell you how to figure out all of those
numbers.
Network Configur

The /etc files


/etc/inetd.conf
On a network-centric operating system, it's not uncommon for a lot of services to be
running. Typically for each service that is
available a program needs to be sitting around listening for connections, which can
get a bit burdensome on a system that runs a lot
of these servers. In order to reduce overhead, inetd was created. inetd is the
"internet super-server"-- it sits around and listens for
connections on many sockets, and when one comes in inetd fires up the appropriate
server to handle it. Thus the many waiting
servers are reduced to one.
/etc/inetd.conf is the configuration file for inetd. It specifies which servers get run for
which connections. The inetd(8) man page has
more detailed information, of course, but let's take a quick look at a basic service
line:
ftp stream tcp nowait root /usr/sbin/tcpd wu.ftpd -l -i -a
This is the line for the ftp server. Note the protocol name ("ftp") first, and last the
command to run to respond. In this case, the
program that is run in response to a connection attempt is /usr/sbin/tcpd; it is a
"wrapper" program that provides some basic security
options for the server it wraps. wu.ftpd is our actual ftp server, but tcpd runs that for
us. More information on tcpd is given in the
section called tcp_wrappers.
Like many system files, lines in inetd.conf are commented by the # character; you
can add and remove services from inetd simply by
commenting their lines in or out and restarting inetd.

/etc/hosts
The hosts file allows the simplest kind of domain lookup. It is a list of hostnames and
their corresponding IPs. This is useful in a small
network where DNS is not worthwhile, in instances where DNS is unreliable, etc. and
is used by the machine during boot time when
no name servers are accessible. Mine might look like this:
127.0.0.1 localhost
192.168.1.32 ninja.tdn ninja
The first line should be self-explanatory. The second, however, may not. You can list
as many names and aliases for an address as
you like, separated by a space. So I have "192.168.1.32" translated to "ninja.tdn"
(and vice versa), but the alias "ninja" can also be
used when I'm too lazy to type ".tdn" (which is most of the time).

Here's how the $DISPLAY variable would be set on our example server using Bash as
the shell. Other shells would use a different
syntax, but the value should be the same.
golf$ export DISPLAY=couch.foc:0.0
root is the user above all users; root is all-powerful and all-knowing, and
nobody disobeys root. It just isn't allowed. Root is what we call a "superuser", and
rightly so. And best of all, root is you.

Users
root is the user above all users; root is all-powerful and all-knowing, and nobody
disobeys root. It just isn't allowed. Root is what we call a "superuser", and rightly so.
And best of all, root is you.

By the way, if you decide you want to be root while you're logged in as someone else,
no problems. Just use the su(1) command.
You'll be asked for root's password and then it will make you root until you exit or
logout. You can also become any other user using
su, provided you know that user's password: su logan.

Running Programs

remember that su command from the last section? Well, it's actually in the /bin
directory: /bin/su would run it nicely.
So why, then, does just typing su work? After all, you didn't say it was in /bin. It could
just as easily have been in /usr/local/share,
right? How did it know? The answer to that lies in the PATH environment variable;
most shells have either PATH or something very
like PATH. It basically contains a list of directories to look in for programs you try to
run. So when you ran su, your shell ran through
its list of directories, checking each one for an executable file called su that it could
run

Input/Output Redirection and Piping


(Here comes something cool.)
$ ps > blargh
Y'know what that is? That's me running ps to see which processes are running; ps is
covered in Chapter 11 That's not the cool part.
The cool part is > blargh, which means, roughly, "take the output from ps and write
it to a file called blargh". But wait, it gets cooler.
$ ps | less

export VARIABLE=some_value

Ownership
The filesystem stores ownership information for each file and directory on the
system. This includes what owner and group own a
particular file. The easiest way to see this information is with the ls command:
$ ls -l /usr/bin/wc
-rwxr-xr-x 1 root bin 7368 Jul 30 1999 /usr/bin/wc
We are interested in the third and fourth columns. These contain the username and
group name that owns this file. We see that the
user "root" and the group "bin" own this file.
We can easily change the file owners with the chown(1) (which means "change
owner") and chgrp(1) (which means "change
group") commands. To change the file owner to "daemon", we would use chown:
# chown daemon /usr/bin/wc
To change the group owner to "root", we would use chgrp:
# chgrp root /usr/bin/wc
We can also use chown to specify the user and group owners for a file:
# chown daemon.root /usr/bin/wc
File ownership is a very important part of using a Linux system, even if you are the
only user. You sometimes need to fix ownerships
on files and device nodes.

Permissions
Permissions are the other important part of the multiuser aspects of the filesystem.
With these, you can change who can read, write,
and execute files.
The permission information is stored as four octal digits, each specifying a different
set of permissions. There are owner permissions,
group permissions, and world permissions. The fourth octal digit is used to store
special information such as set user ID, set group
ID, and the "sticky" bit. The octal values assigned to the permission modes are (they
also have letters associated with them that are
displayed by programs such as ls and can be used by chmod):
read 4 r
write 2 w
execute 1 x
You add the octal values for each permission group. For example, if you want the
group permissions to be "read" and "write", you
would use "6" in the group portion of the permission information.
bash's default permissions are:
$ ls -l /bin/bash
-rwxr-xr-x 1 root bin 477692 Mar 21 19:57 /bin/bash
The first dash would be replaced with a "d" if this was a directory. The three
permission groups (owner, group, and world) are
displayed next. We see that the owner has read, write, and execute permissions
(rwx). The group has only read and execute (r-x).
And everyone else has only read and execute (r-x).
How would we set permissions on another file to resemble bash's? First, let's make
an example file:
$ touch /tmp/example
$ ls -l /tmp/example
-rw-rw-r--- 1 david users 0 Apr 19 11:21 /tmp/example

If the octal values confuse you, you can use letters with chmod. The permission
groups are represented as:
Owner u
Group g
World o
All of the above a

Links
Links are pointers between files. With links, you can have files exist in many locations
and be accessible by many names. There are
two types of links: hard and soft.
Hard links are names for a particular file. They can only exist within a single directory
and are only removed when the real name is
removed from the system. These are useful in some cases, but many users find the
soft link to be more versatile.
The soft link, also called a symbolic link, can point to a file outside of its directory. It
is actually a small file containing the information
it needs. You can add and remove soft links without affecting the actual file.
Links do not have their own set of permissions or ownerships, but instead reflect
those of the file they point to.

$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Apr 6 12:34 /bin/sh -> bash

Mounting Devices

fstab
Let's look at an example of the /etc/fstab file:
/dev/sda1 / ext2 defaults 1 1
/dev/sda2 /usr/local ext2 defaults 1 1
/dev/sda4 /home ext2 defaults 1 1
/dev/sdb1 swap swap defaults 0 0
/dev/sdb3 /export ext2 defaults 1 1
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
/dev/fd0 /mnt ext2 defaults 0 0
/dev/cdrom /cdrom iso9660 ro 0 0
The first column is the device name. In this case, the devices are five partitions
spread out across two SCSI hard drives, two special
filesystems that don't need a device, a floppy, and a CD-ROM drive. The second
column is where the device will be mounted. This
needs to be a directory name, except in the case of a swap partition. The third
column is the filesystem type of the device. For
normal Linux filesystems, this will be ext2 (second extended filesystem). CD-ROM
drives are iso9660, and Windows-based devices

will either be msdos or vfat.

The fourth column is a listing of options that apply to the mounted filesystem.
"defaults" is fine for just about everything. However,
read-only devices should be given the ro flag. There are a lot of options that can be
used. Check the fstab(5) man page for more
information. The last two columns are used by fsck and other commands that need
to manipulate the devices. Check the man page
for that information, as well.

mount the CD-ROM:

mount -t iso9660 -o ro /dev/cdrom /cdrom

That command line includes the same information as the example fstab did, but we'll
go over all the parts anyways. The -t iso9660 is
the filesystem type of the device to mount. In this case, it would be the iso9660
filesystem which is what CD-ROM drives most
commonly use. The -o ro tells mount to mount the device read-only. The
/dev/cdrom is the name of the device to mount, and
/cdrom is the location on the filesystem to mount the drive.

Before you can remove a floppy, CD-ROM, or other removable device that is currently
mounted, you'll have to unmount it. That is
done using the umount command. Don't ask where the "n" went because we
couldn't tell you. You can use either the mounted
device or the mount point as the argument to umount. For example, if you wanted
to unmount the CD-ROM from the previous
example, either of these commands would work:
# umount /dev/cdrom

Comenzi:

ls -la -> lists also the hidden files

***Investigation paused at Sunday,


April 18, 2010 22:11:08

Das könnte Ihnen auch gefallen