V-TEK Weblog about webdevelopment and linux

9Sep/090

Learning Linux Part 2/15: Basic operations

Today part 2 of the 15 linux lessons. Have fun!

Contents of this lesson are:

  • Booting and bootloader
  • Logging in
  • Piping
  • Redirection
  • Need help? Man, info and help

BOOTING AND BOOTLOADERS

When you boot your system, you'll notice a screen with the text lilo or a graphical menu (grub). These are bootloaders which point to the location where the linux kernel resides. Not only Linux can be used in the bootloaders, you can also boot Windows using these bootloaders. Bootloaders can even give extra commands to the kernel, which enable single user mode for example (this is done by adding "1" or single to the kernel line).

grub example

Example of a grub menu

Loadlin is another bootloader, which is located on a DOS partition.

And if you want to know what is happening during startup, simply enter the command "dmesg". This will show you all the messages which the kernel prints.

LOGGING INTO THE SYSTEM

A new linux system has several different users. Most of these users are existing to serve a certain purpose. For example, the user "ftp" is used when other systems connect to your machine using the FTP protocol.
Next to the 'normal' accounts linux does also know a superuser. In most cases this user is called "root".

Logging in can be done by using the command "login". You probably wont have to use this command often, because the linux system displays a login itselves.

If you want to change the current logged in user, you can use the command "su". For example, if you'd like to change to the user "admin", you can use the command "su admin"

PIPING

Piping is used to filter or to re-use the output of a certain command. Let's say you have a big passwd file and you want to read all the users that are created in the system. We can use the command "cat /etc/passwd", but then everything will scroll over the screen and you wont be able to read everything. Then when we use the "|" sign and add the "less" command, we ARE able to read everything slowly. So then the command wil be cat "/etc/passwd | less", which gives us an overview in which we can scroll nicely.

REDIRECTION

Redirection can also use the output of a certain linux command, but it can also use a file as input for a command. The most easy and quickest way to explain this is a MySQL database dump and the import of database dump file.

The following command will save the output of the mysqldump command into a file called dbdump.sql.
If the file dbdump.sql does not exist, it will be created. If it does exist, it's content will be truncated to zero.

mysqldump database-name > dbdump.sql

This command will use the contents of the dbdump.sql file as an input for the database

mysql database-name < dbdump.sql

Besides the "<" and ">" characters, you can also use the ">>" for redirection. When you use these 2 greater then signs ">" the output will be appended to the content of a textfile ( instead of replacing the content of a file ).

Redirection can also be used to redirect the output of the command. Using "2" in combination with ">" means that you can redirect all errors to a certain file or device. Normal output can be redirected using "1" in combination with ">".

Example syntax:

grep -l root /etc/* 2>/dev/null

( searches for the string "root" in every file in the /etc folder. Error messages will be redirected to /dev/null )

grep -l root /etc/* 1> ~/results

( search for the string "root" in every file in the /etc/folder. Except all the results will be placed in the file "results" in the home directory of the home directory ).

NEED HELP? MAN, INFO AND HELP

Need help with a certain command? Use man (command) to see the man(ual) page of the command. Each man page shows a very detailed description of a certain command. Besides man, you can also use the option "info". Info gives in most cases a little bit more extensive information then man does.

man page

man page

In most cases you will use the "man" command followed by any term. But man accepts also a certain number of flags:

man -a command - this will display all the man pages of the given command. This means that it will not stop searching after it's first.

man -f command - Describes in which section of the man pages a certain command is explained. The result is identical to the result of whatis.

man -k keyword - This flag makes man search for a certain keyword. This might be handy if you dont know the exact name of the command. It's advisable to run "makewhatis" before using the -k flag.

Man is not the only command that brings information about a certain command. Info is also a somewhat (deprecated) command what kan bring you information about a certain command. Info is built in a hierarchical way. So when you enter info what any arguments, it will start at the top of the information tree.

Man pages are built in different sections:

  1. Executable programs and shell commands
  2. System calls, functions which are given by the kernel
  3. Library calls, functions given by system libraries
  4. Special files, most files which appear in /dev
  5. file formats and conventions, for example /etc/passwd
  6. Games
  7. Macro packages like man and groff
  8. Commands needed for system management
  9. Kernel Routines

Help is the thirth command available. This command only works for a limited amount of (shell)commands. Entering "help" without any arguments shows an overview of all the available arguments/commands.

About admin

No description. Please complete your profile.
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Recent Comments

Tags

Apache cakephp cpanel dav dd-wrt DNS Ext3 Framework GIT GNU grub javascript Kernel lilo Linux LPI LVM MVC MySQL Netbeans Netfilter PHP piping ps3 redirection regex Ruby on Rails Samba Sendmail Shell Skype SNMP Squid Symfony ubuntu upnp vim windows X Xorg X Window System