How to copy all the content of a directory in Unix without “cp: omitting directory” error [Quick Tip]

Problem Scenario:

You want to copy all the contents of a directory (lets say source_dir) which contains lots of other files and subdirectories inside it to another directory (lets say target_dir). If you simply try cp command it may result in the following error:

command: cp source_dir target_dir
output: cp: omitting directory source_dir

If you try recursive copy (using option -r) the directory is copied inside the target directory which you may not be suitable if you want to duplicate the contents of the source directory.

command: cp -r source_dir target_dir
command: ls target_dir
output: source_dir

Solution:

If you want to copy just the contents of the source directory as in duplicating all its contents use the following command:

command: cp -r source_dir/* target_dir

This command will copy all the content (not the directory itself) in the target directory.

How to remove a directory including all the subdirectories and files in Unix [Quick Tip]

Problem:

Imagine a scenario where you want to delete a directory (lets say dir_name) which contains lots of subdirectories (folders) and files. You may encounter the following errors if you try rm or rmdir:

rm: cannot remove `dir_name': Is a directory

rmdir: failed to remove `dir_name': Directory not empty

cannot remove directory `dir_name’. Directory not empty

Solution:

To avoid this problem use the following command:

rm -rf dir_name

It will delete all the content of dir_name including the subdirectories.

Basic Tutorial in Vim and rails.vim: The open source Rails editing platform

Coders knew Vim for the last twenty years for its unmatched efficiency in editing source code. Vim wasn’ t too popular in the Rails community until lately when Tim Pope published his plug-in: Rails.vim. This plug-in and Vims legendary extendibility made it the editor of choice of many programmers who used some proprietary applications in the past. The plug-in offers shortcuts for easy navigation between files, makes it possible to run scripts, generate controllers, views, do some refactoring, and do auto completion , all of these from Vims cosy interface. Some people say that it is the least user friendly text editor ever. While these accusations might be partly true, because of the rather steep learning curve, many programmers just liked the way Vim helped them do their work quickly and efficiently.
Enough said lets see how to create a very simple blog in Rails from Vim. [Read more…]

Hello World is No More: RIP Dennis Ritchie

Seems like October 2011 is a sad month for tech world. We have lost 3 visionaries who have changed the world by their innovation. First it was Steve Jobs, the founder of Apple Inc then Robert Galvin, Motorola’s cellphone pioneer and now Dennis Ritchie, author of C programming language and co-author of Unix Operating System has died.

If you have ever learned a programming language your first line printed would have been “Hello World” which was Dennis Ritchie’s trademark (if I can say that) when he wrote C language. I found no better to way to pay tribute to Dennis Ritchie than this:

#include
#include
main( )
{
printf(“Hello World No More \n RIP Dennis Ritchie”);
}

 

I just pray that this month doesn’t bring any other bad news. :(

How to know which sound card I have on my PC?

To know the manufacturer of the sound card in your computer in Linux, try the following command in terminal (Shortcut to open terminal: Ctrl+Alt+T) :

aplay -l | grep card

The output of the command for my laptop is following:

card 0: Intel [HDA Intel], device 0: ALC269VB Analog [ALC269VB Analog]
card 0: Intel [HDA Intel], device 3: HDMI 0 [HDMI 0]

As it clearly says my sound card manufacturer is HDA Intel. What is yours? You can find that easily from the output.

Feedback/suggestions/questions are always welcomed. If you like the post then do let me know by liking/voting the post. Enjoy :)

How to find all files containing specific text in Linux?

One of the common commands that I use most frequently in my day-to-day Linux life is for finding files that contains a particular text. Take for an example that I want to search all the files in the current directory that contains string “Hello! this is my file”. The command that is use mostly is this:

find . -type f -exec grep -il 'Hello! this is my file' {} ; 

This search ignores the cases. If you want to search with definite cases (upper or lower) remove the “-i” from grep. You can replace “.” (dot, which means current directory) by the path of the directory in which you want to conduct the search. If you want to search in the whole system then use “/” (it means root directory).

How to know which network adapter I’m using?

To know the manufacturer of the network adapter of your computer in Linux, type this command in terminal:

sudo lshw -C network

The output of the command may look something like this:

       *-network               
       description: Wireless interface
       product: BCM4313 802.11b/g/n Wireless LAN Controller
       vendor: Broadcom Corporation
       physical id: 0
       bus info: pci@0000:03:00.0
       logical name: wlan0
       version: 01
       serial: 70:f1:a1:c2:f2:e9
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=brcm80211 driverversion=2.6.38-8-generic firmware=N/A ip=172.17.4.253 latency=0 link=yes multicast=yes wireless=IEEE 802.11bgn
       resources: irq:17 memory:f0500000-f0503fff
  *-network
       description: Ethernet interface
       product: AR8152 v1.1 Fast Ethernet
       vendor: Atheros Communications
       physical id: 0
       bus info: pci@0000:04:00.0
       logical name: eth0
       version: c1
       serial: b8:ac:6f:67:11:46
       capacity: 100Mbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress vpd bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=atl1c driverversion=1.0.1.0-NAPI firmware=N/A latency=0 link=no multicast=yes port=twisted pair
       resources: irq:43 memory:f0400000-f043ffff ioport:2000(size=128)

Check the output closely. It gives information about both Wired and Wireless Network Adapter. No need to specify that one with Wireless Interface describes wireless adapter and one with Ethernet Interface describes Wired Network Adapter. As you can see in the output, I have Broadcom’s wireless adapter and Atheros Ethernet (wired) adapter.

Questions, suggestions and feedbacks are welcomed. If you liked the post then please acknowledge it by liking/voting/commenting on the post. Enjoy :)

Troubleshooting FreeRADIUS

Recently I was working with FreeRADIUS to do PEAP authentication. I went under a lot of trouble from installing to configuring the FreeRADIUS. Thankfully, I noted down the problems I encountered and the solution I followed. This is not a complete guide for FreeRADIUS installation but provides you with possible solution to a few errors.

1.

While executing radiusd -X, it may throw the following error:

radiusd: error while loading shared libraries:

libfreeradius-radius-2.1.10.so:

cannot open shared object file: No such file or directory

The reason for this error is that the libraries have been installed in a place where dynamic linker cannot find it. To solve this problem use this command:

sudo /sbin/ldconfig -v

2.

While running in debug mode the RADIUS server may give the following error:

Ignoring EAP-Type/tls because we do not have OpenSSL support.

[eap] Request found, released from the list

[eap] EAP NAK

[eap] NAK asked for unsupported type PEAP

[eap] No common EAP types found.

[eap] Failed in EAP select

++[eap] returns invalid

Failed to authenticate the user.

The reason for this error is that open ssl dev library “libssl-dev” is not installed. Install the library (sudo apt-get install libssl-dev) and re-configure (by running configure, make and make install) FreeRADIUS server.

3.

Running the RADIUS server may also result in the following error:

Error: Failed binding to authentication address * port 1812: Address already in use /usr/local/etc/raddb/radiusd.conf[240]: Error binding to port for 0.0.0.0 port 1812

The reason for this error is that another instance of radius is running and has occupied the port.

See which radius process is running:

ps aux | grep radius

And then kill that process:

sudo kill -9 process_id

4.

While running the RADIUS sever it may also throw an error: “no soh-server”. To solve it, copy “soh” file in /usr/local/etc/raddb/sites-available to /usr/local/etc/raddb/sites-enabled.

I hope it helped you. Questions and suggestions are welcomed. Enjoy :)


How to install Windows application (.exe) on Linux / Ubuntu with Wine

As a new Linux user I always miss Windows for some of the applications that are not available on Linux. Booting the computer to go back to Windows just to use some specific software is a real pain. And that made me think how to install Windows programs i.e. .exe files in Linux? This task can be accomplished by the use of Wine application on Linux OS. To use this application you don’t have to be a member of a real wine club 😛

Jokes apart, Wine offers a compatibility layer that allows Linux users to run Windows application on Linux based OS.This tutorial describes the necessary steps to install a Windows application on Linux. The tutorial is based on Ubuntu but similar steps can be followed for other Linux OS as well.

  1. Install Wine application on Ubuntu. You can use Synaptic Package Manager or use this command: sudo apt-get install wine
  2. In this tutorial I am trying to install Rynga, a VoIP application. Download the .exe file of the application. Right click on it and choose properties. In the properties dialogue box go to the Permissions tab. In here check the  Allow executing the file as program box.
  3. Now go to the open with tab and select Wine Windows program loader. Close it.
  4. Now double click the .exe file and follow the usual Next-Next step as in Windows.

I wish this tutorial helped you to install Windows programs in Linux. Questions and suggestions are welcome.

P.S. Compatibility issues may be there with some applications.