Generation of coherent radiation in the IR and terahertz ranges during the propagation of a multi-terawatt laser pulse along a nanowire target is investigated. In the process of interaction, dense electron bunches are displaced from the target and accelerated in the laser field, generating intense electromagnetic radiation. Three regimes of interaction can be realised depending on the duration and shape of the laser pulse. In the first regime, when the laser pulse is long enough (tens and hundreds of femtoseconds), electrons are only partially forced out of the target. The characteristics of the low-frequency part of the spectrum of the generated radiation are determined in this case by the duration of the laser pulse, as well as by its amplitude and target parameters (geometric dimensions and concentration of electrons). In the second regime, the laser pulse has a large amplitude and a steep rising edge (the amplitude of the first half-wave is of the order of the maximum pulse amplitude); as a result, most of the electrons are displaced from the target already at the initial moment of interaction. In this regime, unipolar and bipolar pulses with a duration of tens of laser field periods can be formed. Changing the target length makes it possible to control the period of field oscillations and their number in the generated radiation. In the intermediate regime of short laser pulses with an insufficiently steep rising edge, oscillations of the formed electron bunches can occur in the macroscopic Coulomb attraction field of the charged target, which gives rise to radiation with a frequency several times lower than that of laser radiation. In this case, the pulses of the generated radiation contain a few cycles of the field with decreasing amplitude and increasing frequency. Using numerical simulation in three regimes of interaction, the characteristics of IR and terahertz radiation are found, in particular, the pulse shapes, ranges of generated frequencies, amplitudes and angular distributions of radiation are determined. It is shown that the amplitude of the generated pulse can reach subrelativistic and relativistic values (the field strength is more than 1 TV m−1 at a frequency ten times lower than the laser radiation frequency), and the energy conversion efficiency can be of the order of one percent.