Archive for April, 2008

Learning Linux for Beginners 2

Peace to you all.

In the second article, we will navigate to many commands here.

The cd command

The cd command is used to change the current directory (i.e., the directory in which the user is currently working) in Linux and other Unix-like operating systems. It is similar to the CD and CHDIR commands in MS-DOS.
cd’s syntax is

cd [option] [directory]

The items in square brackets are optional. When used without specifying any directory name, cd returns the user to the previous current directory. This provides a convenient means of toggling between two directories.

When a directory name is provided, cd changes the current directory to it. The name can be expressed as an absolute pathname (i.e., location relative to the root directory) or as a local pathname (i.e., location relative to the current directory). It is usually more convenient to use a local pathname when changing to a subdirectory of the current directory.

As an example, the following would change the current directory, regardless of where it is on the system (because it is an absolute path), to the root directory (which is represented by a forward slash):

cd /

Likewise, the following would change the current directory, regardless of its location, to the /usr/sbin directory (which contains non-vital system utilities that are used by the system administrator):

cd /usr/sbin

If a user currently in the directory /usr/local/share/man/ desired to change to the directory /usr/local/share/man/man2, which is a subdirectory of the current directory, it would be possible to change by using the absolute pathname, i.e.,

cd /usr/local/share/man/man2

However, it would clearly be much less tedious to use the relative pathname, i.e.,

cd man2

On Unix-like operating systems the current directory is represented by a single dot and its parent directory (i.e., the directory that contains it) is represented by two consecutive dots. Thus, it is possible (and often convenient) to change to the parent of the current directory by using the following:

cd ..

Another convenient feature of cd is the ability for any user to return directly to its home directory by merely using a tilde as the argument. A home directory, also called a login directory, is the directory on a Unix-like operating system that serves as the repository for a user’s personal files, directories and programs. It is also the directory that a user is first in after logging into the system. A tilde is a short, wavy, horizontal line character that represents the home directory of the current user. That is, any user can return immediately to its home directory by typing the following and then pressing the Enter key:

cd ~

This is easier than typing the full name of the user’s home directory, for instance, /home/josephine in the case of a user named josephine. (And it is just one of the numerous shortcuts that help make the command line on Unix-like operating systems so easy to use.)

When followed by a space and then a hyphen, cd both returns the user to the previous current directory and reports on a new line the absolute pathname of that directory. This can further enhance the already convenient toggling capability of cd. Toggling is particularly convenient when at least one of the two directories has a long absolute pathname, such as /usr/local/share/man/man2

The chmod command

We use the chmod command to change the access mode of a file. This command comes in many flavors, but we’ll be talking primarily about one of them.

chmod who=permissions filename

This gives “who” the specified permissions for a given filename.

Who

The “who” is a list of letters that specifies whom you’re going to be giving permissions to. These may be specified in any order.

Letter Meaning
u The user who owns the file (this means “you.”)
g The group the file belongs to.
o The other users
a all of the above (an abbreviation for ugo)

Permissions

Of course, the permissions are the same letters that you see in the directory listing:

r Permission to read the file.
w Permission to write (or delete) the file.
x Permission to execute the file, or, in the case of a directory, search it.

Note: Do not put blanks around the equal sign, or your command will not work!

Syntax

chmod [OPTION]… MODE[,MODE]… FILE…
chmod [OPTION]… OCTAL-MODE FILE…
chmod [OPTION]… –reference=RFILE FILE…
-c, –changes like verbose but report only when a change is made
–no-preserve-root do not treat `/’ specially (the default)
–preserve-root fail to operate recursively on `/’
-f, –silent, –quiet suppress most error messages
-v, verbose output a diagnostic for every file processed
–reference=RFILE use RFILE’s mode instead of MODE values
-R, –recursive change files and directories recursively
–help display this help and exit
–version output version information and exit

Permissions
u – User who owns the file.
g – Group that owns the file.
o – Other.
a – All.
r – Read the file.
w – Write or edit the file.
x – Execute or run the file as a program.

Numeric Permissions:
CHMOD can also to attributed by using Numeric Permissions:

400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody

Examples

The above numeric permissions can be added to set a certain permission, for example, a common HTML file on a Unix server to be only viewed over the Internet would be:

chmod 644 file.htm

This gives the file read/write by the owner and only read by everyone else (-rw-r–r–).

Files such as scripts that need to be executed need more permissions. Below is another example of a common permission given to scripts.

chmod 755 file.cgi

This would be the following 400+040+004+200+020+100+010+001 = 775 where you are giving all the rights but the capability for anyone to edit your file.cgi (-rwxr-xr-x).

Finally, another common CHMOD permission is 666, as shown below, which is read and write by everyone.

chmod 666 file.txt

Additional information

Below is an example of how a file may be listed when typing ( ls -l ) at the prompt as well as information on how to interpret it.

-rw-rw-r– 1 hope 123 Feb 03 15:36 file.txt
- rw rw- r– 1 hope 123 Feb 03 15:36 file.txt
File owner group everyone else links owner size mod date file name

Install Software & Programs

To install software or programs write the following command in the termianl

yum install [software_name]

The yum command searches for the software supplied to it and look forward to find it in the repositories then installs it.

All yum commands cause yum to take the following actions:

* The first time yum is called, as root, it downloads all the header files in all repositories in its yum.conf and puts them in a cache on your system. Subsequently it only downloads ones that have changed since the last time the cache was refreshed.
* It then reads your RPM database (which should be consistent, see note above) to determine what packages are installed.
* Determine which yum command has been invoked, and process the command.
* If the command is run interactively (the default) yum will prompt the user for permission to proceed before actually updating or installing files.
* If yum is run with the -y option, yum will assume a “yes” answer to all interactive questions. This is typically used in a script or to process “known safe” installs or updates.
* If yum is run with the -d 0 option, it will run as quietly as possible. -y -d 0 are typically invoked together in a scripted update where only serious errors are to be reported.
* There are many other yum action modifiers; read the man page for a synopsis.

Yum is very conservative. It will never perform the equivalent of a -force install. It was designed, as noted above, by systems administrators to facilitate the consistent and scalable maintenance of systems, and thus will balk at any action that might cause your system to enter “package hell” (a state of package inconsistency). If yum refuses to do something, then the thing it refuses to do is probably a bad idea for most people to think about. If you are skilled enough to know that it is really OK on YOUR system, you are skilled enough to use rpm itself to override yum.

But do you really want to? Perhaps what you really should be doing is rebuilding the RPMs in question, or fixing some apparent conflict instead of ignoring it. In a sense, yum is the ultimate sanity check. If yum is happy, your repository is consistent, your RPM database is consistent, and your system is happy. If yum is not happy, then chances are pretty good that at least some part of your system could break, which would cost you a lot more time to set right than just making everything consistent to start with.

The following is a brief synopsis of the commands:

yum install package1 [package2 package3...]: Yum checks to see if package1 is already installed and is the latest version. If not, it downloads package1 and all its dependency packages (saving them in its cache directory) and installs them.

yum update [package1 package2...: If there is a basic, essential yum command this is it. Without arguments, yum compares each installed package to packages available on the repository list. If a newer package is available in the repository, it downloads it (saving it in the cache directory) and updates the old one. If a list of packages is given, it only checks for updates of those packages (and their dependencies).

Note that RPM updates generally preserve configuration information and restart daemons and so forth, so your system will generally not require a reboot, although updating the kernel is an obvious exception. Kernel updates are a special case and systems administrators will generally set a policy on this in /etc/yum.conf. In any event, yum will not reboot your system even after a kernel update.

yum remove package1 [package2 package3...]: Yum will first check to see if removing the package breaks anything else (that is, if anything else already installed depends on this package). It will then offer to remove the package and all the packages that depend on it. Yum will generally refuse to leave “dangling” packages that won’t work anyway because a critical library or component has been removed. Note that running remove with the -y option is probably a really stupid idea for most people, unless they are certain that they know all of the possible side effects.

yum list [ ,available,installed,updates,extras] [package list]: This is one of yum’s most useful commands. Run without arguments or a list of packages, yum lists all packages available to be installed on all repositories. Run with a list of packages (which can contain file wildcard globs, e.g. yum list kernel
to list all kernel package) it shows both the installed packages and the available packages that match the expanded list! The installed, available, and updates options show only installed packages, available packages, or packages that will be updated by the next yum update command. Note Well that when run interactively from a shell, wildcard characters need to be escaped from the shell itself or the command will have unexpected consequences.

yum info [ ,available,installed,updates,extras] [package list]: This command extracts the description and summary from all matching packages and prints it out. It takes the same options as list, but provides different information. yum info > /tmp/packages thus provides you with a shopping list in /tmp/packages of every package either already installed on your system or available on its set of repositories! This can be very useful indeed!

The extras option lists all packages that are installed but not available in the repositories. These are packages you may have installed by hand, for example. A good practice is to create a repository for these local RPMs (which can be nothing but a local directory on the system) and add the repository to the yum.conf file for the system, following the recipe above.

yum search keyword: Searches for packages matching the keyword string in the description, summary, packager and package name fields. This is useful for finding a package you do not know by name but know by some word related to it. The keyword string can contain wildcard file globs. Be sure to escape these from the shell as noted above if run interactively.

yum provides [feature|file]: Find package(s) that provide some feature or file. Accepts file wildcard globs, which again should be escaped from the shell if run interactively.

yum clean: Cleans up yum’s cache file. On systems with small disks or limited /var resources, the RPMs that yum caches can fill up the disk. Running yum clean periodically can free up the resources, but it can also mean that yum runs more slowly when doing certain things. Clean takes various options: see the man page for details.

yum group[list,install,update]: Yum has recently acquired the ability to perform the list, install, and update functions on package groups defined for a system, with otherwise similar arguments. This makes it relatively easy to install an entire block of software all at once, on systems that have package groups defined.

Add comment 30 April 2008

Learning Linux For Beginners 1

Peace to you all.

In this series, I will try to discuss to you the Linux essentials commands and operations. I will begin from zero to learn Linux for beginners, also other people may know some new information.

The Terminal

A “terminal” is a way of typing commands to the computer. That may sound very strange, but it’s actually really, really nice and easy once you get used to it. You can either open a terminal inside of your graphical environment, or you can switch your whole screen to a terminal. You can use any graphical system you need like Fedora, OpenSuse, or Ubuntu.

To open the terminal from the graphical system :-

In Fedora –> Open main menu then System then Terminal
In Ubuntu –> Open main menu then Accessories then Terminal

To switch you entire screen to console, press Ctrl-Alt-F1. You can then switch between six different terminals, by using Alt-F1 through Alt-F6. Pressing Alt-F7 will bring you back to your graphical environment.

The Basic Operations

The su (short for substitute user) command makes it possible to change a login session’s owner (i.e., the user who originally created that session by logging on to the system) without the owner having to first log out of that session.

Although su can be used to change the ownership of a session to any user, it is most commonly employed to change the ownership from an ordinary user to the root (i.e., administrative) user, thereby providing access to all parts of and all commands on the computer or system. For this reason, it is often referred to (although somewhat inaccurately) as the superuser command. It is also sometimes called the switch user command.

In ubuntu we use the command : sudo -s to do the same functionality.

Advantages of Using su

su is usually the simplest and most convenient way to change the ownership of a login session to root or to any other user.

More importantly, it provides a safer way for administrators on multi-user systems (as well as for users on home computers or other single-user systems) to use the system than to routinely log on as the root user. That is, there is much less potential for accidental or malicious damage if an administrator first logs on as an ordinary user (who, by default, has very limited system privileges) and uses that account for routine tasks that do not require root’s sweeping powers. su can then be used to switch to the root account for only those operations that actually require root access (e.g., making system repairs and managing user accounts).

The use of su instead of routinely logging in as root is particularly important when connected to the Internet. This is because it makes it much more difficult for malicious software originating on remote computers to access critical system files or commands (which belong to the root account).

On multiuser systems, not only the root account but also su should be used to the minimum extent necessary, and it should be used with great caution. This includes making certain (1) that no unauthorized persons see any passwords used with su (such as watching a password being typed in or seeing it on paper), (2) that su sessions are not left unattended and (3) that su sessions are terminated as soon as the tasks for which they were invoked have been completed.

When su is used while in console mode (i.e., with a text-only screen display), the original user’s session cannot, of course, be used on the same machine (because the su session occupies the entire screen). However, when su is used in a terminal window (i.e., a text-only window in a GUI), only that terminal window and programs that are started from it are run with the new user’s account (e.g., root), and all other programs, including any other terminal windows, can continue to be run by the original user.

A convenient way of eliminating the need for typing su numerous times during a session is to open a terminal window, run su once in that window and then use the window for all root tasks (i.e., tasks for which administrative privileges are required) during the session. However, it is important to make certain that no one has physical access to the computer during such session. Thus, it is advisable to close the terminal window as soon as practical, unless it is used on a home system (where, presumably, nobody is around to cause damage to the system or steal data).

Another advantage of using su is that a record is kept of its usage in system logs, whereas no such record is kept if one logs in directly as root.

Syntax

A simplified expression of the syntax of the su command is:

su [options] [commands] [-] [username]

The square brackets indicate that the enclosed item is optional. Thus, the simplest way to use the su command is to just type:

su

The operating system assumes that, in the absence of a username, the user wants to change to a root session, and thus the user is prompted for the root password as soon as the ENTER key is pressed. This produces the same result as typing:

su root

If the correct password is provided, ownership of the session is changed to root.

Likewise, to transfer the ownership of a session to any other user, the name of that user is typed after su and a space. For example, to change the owner of the current login session to a user named alice, type the following:

su alice

The user will then be prompted for the password of the account with the username alice.

Tail a Log with su

A major benefit of using su is that a record is kept of its usage in a system log, typically /var/log/messages. This is particularly valuable if there are multiple administrators for the system (each of which should have an individual username and password), because it facilitates finding out who was doing what and when. /var/log/messages records the username and user ID (UID) of the user that opens a su session as well as the times that the session is opened and closed. However, su does not keep a record of what is actually done as root, and such information must therefore be obtained from other sources.

The contents of /var/log/messages can be viewed by first using su to switch to the root account and then issuing the following command:

tail /var/log/messages

It is convenient to use the tail command here because it shows the last part of a file, rather than starting at the beginning as commands such as cat (possibly the most commonly used command for reading text files) do. As /var/log/messages can be a rather long file, this can save a lot of scrolling.

Tail prints (i.e., writes to the monitor screen) the final ten lines by default, but this can be easily adjusted by using the -n option followed by a space and an integer representing the desired number of lines. For example, the following command would print the final 20 lines of /var/log/messages:

tail -n 20 /var/log/messages
As is the case with many command line programs, there is a graphical front end available for su, and it is named KDE su. A graphical front end is a GUI program that operates on top of a command line program and replaces its character-based user interface with a graphical one.

su is one of the GNU Core Utilities, which are developed by the Free Software Foundation (FSF) and are therefore open source and free to use, study, modify and redistribute. KDE su is also free software.

Add comment 30 April 2008

هذي بلاد لم تعد كبلادي

هذى بلاد لم تعد كبلادى

لم أكن أتصور يوماً ما أن من قام بتأليف نشيد الجيش المصري الذى طالما أنشدناة فى طليعة كل صباح فيحيى فينا من الحماس و الإلهام و صدق الكلمات و عذوبة العبارات التى نلمسها جميعاً عند ترديدة, لم أكن أتخيل أن من كتب هذة ,الكلمات و أحسسها بكل ذرة فى كيانة, لم أعد أتصور أن من كتب و قال

رسمنا على القلب وجه الوطن, نخيلاً و نيلاً و شعباً أصيلاً

و صنالك يا مصر طول الزمن ليبقى شبابك جيـــلاً فجــيلاً

لم أعد أصدق أن من كتب هذا النشيد قد أتى يوما ما عليه و قد طفح بة الكيل إلى أن كتب قصيدة بعنوان هذى بلادُ لم تعد كبلادى“, إنة الشاعر فاروق جويدة.

نشيد الجيش المصري لفاروق جويدة

رسمنا علي القلب وجه الوطن

نخيلا ونيلا وشعبا اصيلا

وصناك يامصر طول الزمن

ليبقي شبابك جيلا فجيلا

علي كل ارض تركنا علامة

قلاعا من النور تحمي الكرامة

عروبتنا تفتديك القلوب

ويحميك بالدم جيش الكنانة

وتنساب يا نيل حرا طليقا

لتحكي ضفافك معني النضال

وتبقي مدي الدهر حصنا عريقا

بصدق القلوب وعزم الرجال

يد الله يا مصر ترعي سماك

وفي ساحة الحق يعلو نداك

ومادام جيشك يحمي حماك

ستمضي الي النصر دوما خطاك

سلام عليك اذا ما دعانا

رسول الجهاد ليوم الفداء

وسالت مع النيل يوما دمانا

لنبني لمصر العلا والرخاء

قصيدة هذى بلاد لم تعد كبلادى

كم عشت أسأل .. أين وجه بلادي

أين النخيل .. و أين دفء الوادي

لا شيء يبدو في السماء أمامنا

غير الظلام .. وصورة الجلاد

هو لايغيب عن العيون كأنه قدر

كيوم البعث و الميلاد

قد عشت اصرخ بينكم و أنادي

أبني قصورا من تلال رمادي

أهفو لأرض لا تساوم فرحتي

لا تستبيح كرامتي .. و عنادي

أشتاق أطفالا كحبات الندى

يتراقصون مع الصباح النادي

أهفو لأيام توارى سحرها

صخب الجياد .. و فرحه الأعياد

اشتقت يوما أن تعود بلادي

غابت و غبنا .. و انتهت ببعادِ

في كل نجم ضل حلم ضائع

و سحابة لبست ثياب حدادِ

و على المدى اسراب طير راحل

نسي الغناء .. فصار سرب جرادِ

هذي بلاد تاجرت في ارضها

و تفرقت شيعـًا بكل مزاد

لم يبق من صخب الجياد سوى الاسى

تاريخ هذى الارض بعض جيادِ

في كل ركن من ربوع بلادي

تبدو أمامي .. صورة الجلاد

لمحوه من زمن يضاجع أرضها

حملت سفاحا .. فاستباح الوادي

لم يبق غير صراخ أمس راحل

و مقابر سئمت من الاجداد

و عصابه سرقت .. نزيف عيوننا

بالقهر و التدليس و الاحقاد

ما عاد فيها ضوء نجم شارد

ما عاد فيها صوت طير شادِ

تمضى بنا الاحزان ساخره بنا

و تزورنا دوما .. بلا ميعادِ

شيء تكسر في عيوني بعدما

ضاق الزمان بثورتي و عنادي

احببتها .. حتى الثماله بينما

باعت صباها الغض للاوغادِ

لم يبق فيها غير صبح كاذب

و صراخ أرض في لظى استعبادِ

لا تسألوني عن دموع بلادي

عن حزنها .. في لحظة استشهادي

في كل شبر من ثراها صرخة

كانت تهرول خلفنا و تنادي

الافق يصغر و السماء كئيبة

خلف العيون أرى جبال سوادِ

تتلاطم الامواج فوق رؤسنا

و الريح تلقى للصخور عتادِ

نامت على الافق البعيد ملامح

و تجمدت بين الصقيع أيادِ

و رفعت كفى .. قد يراني عابر

فرأيت أمي .. في ثياب حدادِ

أجسادنا كانت تعانق بعضها

كعناق أحبابٍ .. بلا ميعاد ِ

البحر لم يرحم براءه عمرنا

تتزاحم الاجساد في الاجسادِ

حتى الشهادة راوغتني لحظة

واستيقظت فجرا .. اضاء فؤادي

هذا قميصى فيه وجه بنيتي

و دعاء أمي .. كيس ملح زادي

ردوا إلى امي القميص فقد رأت

ما لا أرى .. من غربتي و مرادي

وطن بخيل باعني في غفلة

حين اشترته عصابة الافساد

شاهدت من خلف الحدود مواكبا

للجوع تصرخ في حمى الاسياد

كانت حشود الموت تمرح حولنا

و العمر يبكي .. و الحنين ينادي

ما بين عمر .. فر مني هاربا

و حكايه .. يزهو بها أولادي

عن عاشق هجر البلاد و أهلها

و مضى وراء المال .. و الامجادِ

كل الحكايه أنها ضاقت بنا

و استسلمت للص و القواد

في لحظة .. سكن الوجود

تناثرت حولي مرايا الموت و الميلادِ

قد كان آخر ما لمحت على المدى

و النبض يخبو .. صورة الجلاد

قد كان يضحك .. و العصابة حوله

وعلى امتداد النهر .. يبكى الوادي

و صرخت و الكلمات تهرب من فمي

هذي بلاد .. لم تعد كبلادي

2 comments 18 April 2008


Calendar

April 2008
S M T W T F S
    May »
 12345
6789101112
13141516171819
20212223242526
27282930  

Posts by Month

Posts by Category