Archive

Posts Tagged ‘Linux Commands’

Funny Unix commands: dd

October 1st, 2011 1 comment

Well, guys, we are at the summer issue, and I take a little ‘Holidays for me as well, as you can see by the brevity of this article. Okay, would make more sense that I had written more, because on the one hand you have more time for reading, and on the other hand, the lines should be less loaded and leave this issue of BETA download faster. Whatever. I’m lazy, the end is near, and I do not feel right to put on the stain to the keyboard between the heat and mosquitoes.

On the other hand, I think the topic of this issue is quite interesting: in fact, deal with dd, the date duplicator, a relatively unknown program, but which I find very useful for many things that no one would suspect at first sight. Before submitting the command in all aspects, I want to tell a legend that explains why its syntax is so funny – but find!. Unfortunately I can not remember the source of what I will say, but nothing takes away the breath of antiquity that pervades the story, and that makes us feel so small …

Legend has it that in the distant past, when UNIX was born first, its creators were in need at some point a low-level command to copy data from one device to another. However, since were in a hurry, you began to study the syntax of the command, and copied the weight used in IBM mainframe-360, so there would be time to define a command interface consistent with the other. Time passed, and everyone was so used to the idiosyncrasies of dd, it occurred to anyone to rewrite a similar command. Is it true? I do not know, but I repeat that it would still be well devised. But we see in detail how it works.

Options

Actually, dd is not quite like any other Unix commands: it is also a filter, which by default that reads from standard input and writes to standard output. In short, if you write simply “dd” and press return, the terminal remains quiet. You can write what you want, and end with ctl-D, at this point will be rewritten as typed, and then dd will add his signature, such as “ 0 +10 records in 0 +1 records out,” so to have some fun.

Call to chatter: The complete syntax is as follows.

    dd [if=file] [of=file] [ibs=bytes] [obs=bytes] 
       [bs=bytes] [cbs=bytes] [skip=blocks] [seek=blocks] 
       [count=blocks] [conv={ascii,ebcdic,ibm,block,
           unblock,lcase,ucase,swab,noerror,notrunc,sync}]

In short, all options are of the form variable=value. Warning: you can not put any spaces before or after the equal sign. This broke a little ‘boxes at one time, since the shell does not expand the file names in this situation and needed everything, fortunately bash Linux is smart enough to notice the context and the expansion to be made to work. In practice, nicc problem!

Another important thing to remember is that all the values ​​that accept bytes may be followed by a multiplier. The Linux version of dd recognizes b lock (512), k for kilobytes (1024), w for word (2), and thirteenth to multiply by a number m, this becomes the value of block.

Below is given a more complete explanation of the various options.

if=filein and of=fileout

tell dd respectively, read from and write to filein fileout. In the Linux version, in which case the output file is truncated to the value given to seek, or 0 if the keyword is not present. But be careful notrunc option!

ibs=nn and obs=nn

specify how many bytes must be read or written per record, that is, to write. I would say that the default is 512 bytes, ie a block, so it happens in ordinary files. Of course it is possible that the rest is thrown away: when the output of dd showed above that said “0 +10 records”, I had written ten lines, all less than 512 characters, and therefore were treated as “remnants”. These parameters are very important when using special devices as input or output: the network should have read IBS for example set to 20k, and has as a block floppino “natural” 18k. Do not set these values ​​can be not only more time to execute the command, but also in time-out errors, if not worse. User warned …

bs=nn

is an abbreviation to indicate how many bytes are simultaneously read and written at a time.

cbs=nn

please set the buffer conversion nnbyte. According to the manual, this is used when translating from ASCII to EBCDIC, or a device does not block in a block: Used together with the conversion block and unblock. I do not know. I never had the misfortune of having to use that option, and still live happy :-)

skip=nbl and seek=nbl

tell the program to skip nblblocchi respectively at the beginning of the input and the output. Obviously the latter makes sense only if you give the conversion notrunc: see below. The block size is given by the value of ibs (obs). A useful observation: in fact it can safely write 1b skip = 512 to indicate “something”. But if you set ibs 1, the “something” is a block in practice, this means 512 * 512 bytes, or 256K. It was what you wanted?

count=nbl

it copied only the input nbl blocks, each the size indicated by ibs. This option, together with the preceding, it is nice when you have a corrupted file and you want to recover as much as possible, it skips the offending party and you get the rest.

conv=conversion [, conversion ...]

converts the file as specified by its argument. Possible conversions, at least in the Linux version, are ascii, which converts from EBCDIC to ASCII ebcdic and ibm, which are both a reverse conversion; block, stretching all the records terminated by a newline at length CBS, replacing the newline spaces; unblock, which does the opposite (trailing spaces removed, and adds a newline); lcase and ucase, to convert text to lowercase or uppercase; swab, which exchanges between them two by two bytes of input (For example, if you have written a 2-byte integer file on a machine based on 680×0 and must read on a PC); noerror, to continue the conversion in the case of input errors, sync, stretching blocks Input the size of ibs adding NUL.

Examples

The canonical example of use of dd is one in which there will certainly be encountered when you created your first floppy disk Linux: how to write a floppino without putting up the MS-DOS filesystem. The solution is simple:

% dd if=disk.img of=/dev/fd0 obs=18k count=80

I decided not to use IBS because I do not know what the best value for a hard disk, I could still use BS instead of obs and everything would be fine. Please note that for safety I also indicated the number of sectors to write (80), and I have written directly on behalf of low-level floppy.

Another useful application of dd occurs in the case of network backup. Suppose you are on the machine alpha, beta, and that on the machine there is a tape /dev/rst0 with a tar file that interests us, is not large enough to be able to be saved and then copied on beta. In this case, we can write

% rsh beta 'dd if=/dev/rst0 ibs=8k obs=20k' | tar xvBf

to do the operation in a single step. In this case, we used rsh to read from the tape: size of input and output are made to the default for these operations, ie, 8KB and 20KB read from tape to write on the ethernet. From the point of view of our local tar, the bytes arriving are exactly those that would have seen the tape, apart from the somewhat ‘strange with which they come, which is why I added the B to the [6].

Finally, a quick command that can be useful when you get a Word file from a Mac, and it turns out that despite all this remains unreadable because controconversioni written in MacBinary: just remove the first 128 bytes.

% dd if=file.bad of=file.doc ibs=128 skip=1

In short, it’s always handy to have on hand our data doubler.

10 Linux Terminal Basic Commands

September 23rd, 2011 No comments

Ours is an era of extreme desktop environments, it is true, fluid graphics, bright colors and so on and so forth. However, the old command line from time to time (actually not so often …) back to peep between the user’s needs, even less experienced.

Linux Terminal On Debian command

Understanding the Linux terminal means having a direct approach on your PC as well as solve problems and situations, often, access to remote systems via ssh or embedded such as routers, access points etc..

But let’s go down to it, here’s a roundup of commands not too famous but very, very useful:

PS

The PS command stands for “process status”, and shows everything to do with the processes, as a kind of task manager. There are many variations of PS, such as PS AUX, which is a list of all running processes. This command, used together with the kill command allows you to terminate processes.

RM-RF

This command is very powerful, as capable of destroying entire systems in case of error. Nevertheless, it is very useful for quickly deleting entire directories.

Think of a folder containing thousands of files on a web hosting space: removing ftp require several minutes or hours, this command through ssh, however, the same takes a second.

For example rm-rf photos deletes the directory “pictures”.

Pstree

The command pstree is another variant of the PS command, and is very useful for those who often work on different machines and servers.
If you need to get a glimpse of the various programs running, and what processes are dependent on other processes, pstree is definitely more useful and organized a regular PS AUX.

HISTORY

We say that a directory suddenly disappears randomly from a user’s computer and we can not tell if someone has touched the terminal. It ‘can use the history command | grep-i command, replacing “command” with the command of which we want to analyze the previous use.
Otherwise you can type only history to have a general overview of all the last commands typed.

APROPOS

The command apropos is used to obtain information from the terminal.
It ‘can get information about images, documents and other such operations, or be suggested (and what type commands) can be used on a particular folder by simply typing apropos folder.

LS

LS is probably the simplest and most used command in a terminal. This is why you see the contents of a folder. LS-LH is also very useful as it displays the sizes of files in a folder in a human readable format rather than opens expressed in bytes.

GREP

The grep command is used mainly to apply a filter so as to restrict what interests us most of the output terminal. And ‘commonly used to find occurrences of a word or words in a series of files.

FIND

The find command is incredibly powerful, especially when used by an administrator.
This command can be used to find anything in the system, and it’s really easy to use.

CRON

CRON is a command that allows you to plan operations, such as running a program, script or anything.

The cron syntax is as follows: minute | hour | day | month | week + command.

You can specify each time component as an integer (eg 1 to 12 for months), or insert one or more components of the character “*” will be interpreted as a wildcard (ie, “*” in the month means that the command to activate a given day and at a time in every month).

For example, if the septum only minutes and hours, it means that every day at the same time you will run the operation that set.

WGET

WGET is a very powerful command. And ‘certainly one of the most useful and versatile for download.
It can be used for example to download even when things are not properly before the PC Program.

There is a huge amount of commands that can be used in combination with wget, and all are designed to make life easier.
A very interesting feature is that WGET to download an offline copy of a website, using the WGET command-M http://www.website.com/

Customize to fit your Ubuntu with Ailurus

July 26th, 2011 No comments

Ubuntu is too difficult to tackle and change? Get help from Ailurus to customize and improve it.

One of the things that baffle novice users find Linux is no longer certain functions that were easily available in the Windows world. The first operations were resolved with a few clicks now pass through “mysterious” commands like sudo, adding the repository or the use of the terminal that both frightens those who are not accustomed to using it.

To make life easier for those people, and maybe not just them, there are programs to help as Ubuntu-Tweak or Ailurus, we’re going to discuss in this article. This software allows us to implement several changes to the operating system configuration, install programs and more easily.

Installation

You can download the deb files with the latest version of the program from this address. Ailurus is also compatible with Fedora than Ubuntu and Mint.

If you want to install terminal enter these commands.

sudo apt-add-repository ppa Ailurus

ailurus ubuntu optimizer

sudo apt-get update

ailurus ubuntu

sudo apt-get install Ailurus

ailurus linux optimizer

Operation

Once installed, the program is located in Applications – System Tools – Ailurus.

When you first start the program you see a warning about the impossibility to install proprietary software and the installation of certain codecs to avoid violating the law, check the box, I agree. Do not ask me again so it will not ask again. Then click Yes

ailurus ubuntu

The operation of the program is extremely simple, and, moreover, the interface is translated into Italian.

It begins with the Information screen where you can read the features of your hardware and operating system installed.

ailurus ubuntu

It continues with a series of small improvements to the visual appearance of the desktop, boot screens, special configurations of Firefox, setting some restrictions on user functions and much more. The voices are many and very clear: to consult you first to explain that one by one.

ailurus linux

We will now install, automatically and without demands on the user, a series of programs and Firefox extensions.

ailurus

Also good cleaning function of the system that allows the elimination of unnecessary programs and packages.

ailurus customize ubuntu

You do not have to do is confirm the removal when required.

ailurus linux fedora

Report (and correct) errors of the operating system and recommend improvements.

ailurus linux fedora

Of Ailurus are released very often new releases to add new tricks and improvements, once installed will be updated automatically as it does for other programs.

Linux: Internet Connection Sharing

July 5th, 2011 No comments

Despite being a basic task for those who manage Linux networks, the Internet Connection Sharing can be an important issue for those who are beginners and want to use Linux as a gateway from your LAN.

 

The first thing we need to understand is the NAT or Network Address Translation. Also called masquerading (masking), is the process of transforming or translating IP addresses from one network to another, in the case of Internet sharing, NAT translates between IP network where the Internet IP address, allowing machines your local network to access the Internet. Thus, a single Internet IP address can be shared with all of its IP network.By using a gateway each data packet is translated by NAT and is recognized as coming from the Internet IP, ie, independent of the computer’s IP network, all packets go out to the Internet as the Internet IP. When the packet returns, the NAT is the translation back to direct you to the source computer.
Sharing the Internet connection

Sharing the Internet connection

Sharing the Internet connection

Before we start to configure our Internet sharing gateway, we check the environment to be used. For the settings to run smoothly you will need an environment like this:

  • A connection (which is working) with an Internet service provider;
  • A machine with Debian or Ubuntu installed;
  • Two network cards installed, one of which should already be with the settings of your Internet service provider;
  • A hub or switch to distribute Internet access across multiple computers.

Below is a simple suggestion of network topology:

LAN: a simple network topology

LAN: a simple network topology

Flushing the routing of packets

The first configuration to do is release the IP packet forwarding. For this we have two alternatives. The first is to change the file ip_forward entering 1 in its content and the second is by changing the sysctl.conf file.

Inserting a file ip_forward :

# echo 1> /proc/sys/net/ipv4/ip_forward

Change the sysctl.conf file:

# vi/etc/sysctl.conf

Remove the # sign from the line:

net.ipv4.ip_forward = 1

Save the file with “:wq”. For more information about the sysctl.conf file, simply enter the command:

# man sysctl.conf

Configuring IP Gateway

Let’s follow the example of topology up and admit that we have two network cards and will use the card named eth0 for Internet access (WAN) and eth1 card to access the local network (LAN).

Tip: To know more information about our network cards, we can use the command:

# cat/var/log/dmesg | grep eth

This command should return the network chipset and the appointment set by Linux.

After properly verify the network cards and we link the cables that were “made” using the standard CAT5e, we then manually configure the network information. Since we are using Debian Lenny (Debian 5.0) or Ubuntu Jaunty (Ubuntu 9.04), then the settings are in /etc/network/interfaces. Let’s edit it:

# vi/etc/network/interfaces

The file should look like the example below:

it self
it iface inet loopback

allow-hotplug eth0
iface eth0 inet dhcp

allow-hotplug eth1
iface eth1 inet static
address 192.168.0.1
netmask 255.255.255.0

Note that not inform the gateway address on the card that will be responsible for receiving all traffic on the local network (LAN). This is done because this machine is the gateway of the LAN.

In Ubuntu, the default setting does not mention allow-hotplug eth0 auto eth0 and yes.

If your Internet connection is using fixed IP, then the eth0 settings may be similar to this:

allow-hotplug eth0
iface eth0 inet static
address 200.174.144.20
netmask 255,255,255,240
broadcast 200.174.144.31
gateway 200.174.144.17

 

Using IPTables to share the Internet connection

The IPTables is the software responsible for configuring packet filtering rules. To use IPTables to share Internet access, before we need to tell the kernel modules to be loaded.

# modprobe ip_tables
# modprobe iptable_nat

The modprobe command is responsible for, among other tasks, add or remove modules in the Linux Kernel. The modules ip_tables iptables_nat and are meant to add to the kernel the ability to filter data packets and make the “translation” of IP addresses from one network to another.

Now let’s clear any pre-existing rule in iptables, so we can ensure the correct operation of NAT and packet forwarding:

# iptables-F INPUT
# iptables-F OUTPUT
# iptables-F FORWARD
# iptables-t nat-F
# iptables-t mangle-F

The clean lines above information input, output, forwarding, “translation” and change packages.

Finally, we will enable packet forwarding via iptables:

# iptables-t nat-A POSTROUTING-o eth0-j MASQUERADE

Understanding the parameters passed to the IPTables on the line above:

-T nat – uses the table of “translation” of IP addresses;
-A POSTROUTING – the rule adds to output packets;
-O eth0 – specifies that the outgoing interface used is eth0;
-J MASQUERADE – says that the focus (target) rule is the IP masquerading.

 

Testing the Internet connection

To test if the settings worked, just use the ping from a client machine on the network. For example:

# ping www.google.com.br

 

Monitoring the packet transfer

Monitoring interfaces iftop

Monitoring interfaces iftop

Iftop is a great utility for monitoring the transfer of packets between your LAN and the Internet. With it we can see in real time, which sites are accessed and measure the throughput. To install iftop in Debian Lenny (Debian 5.0) or Ubuntu Jaunty (Ubuntu 9.04) just run the command:

# apt-get install iftop

To use it you simply specify the interface (card) you want to monitor network. In our example topology of the board named eth0 is responsible for Internet traffic. To monitor it will use the command:

# iftop-i eth0

If you have created a script with the above settings, then you can add it automatically at system startup with the command:

# update-rc.d defaults

Now, you can try your internet connection.

Installing Apache and PHP on Ubuntu Linux

June 27th, 2011 No comments

Apache and PHP

Linux Apache Web Server is a PHP and MySQL, the 1st choice.
Not least because all components are free, the vast majority of web servers based on the Internet on these programs. A Linux Apache MySQL PHP server is often abbreviated as LAMP.
We show how simple the installation of the software components under Ubuntu.

Installation:
go into the terminal or log on to the console:

sudo apt-get install apache2 php5

MySQL
install with:

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql mysql-admin

at the end of the installation you must specify the root password
mysql-admin with databases and tables can then be created.
The directory in which the website and the PHP scripts are located then in

/var/www

using PHP to access MySQL see: Example Script PHP and Mysql