Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, May 18, 2015

Linux : How to recursively touch files and folders in a directory

Guys today we will learn a small tip about touching multiple files / folders in a folder using Linux Terminal.

I assume you know about "touch" command in Linux if not please make sure you read its man page here.

You need to use below command to touch files/folders recursively.
 find . -exec touch {} \;  

Execute this command in the director in which you would like to perform this operation.

This command,

  • Finds each file
  • exec is used to invoke a subprocess "touch"
  • Curly bases and backward slash ending with semicolon as per syntax
Hope you find this tip useful.

Wednesday, April 15, 2015

Interrupts and Interrupt handlers

If you are an embedded engineer, you might be dealing with interrupts in your daily work. Though its simple concept, its thought complex.

To put them in layman words, interrupts allow hardware to communicate with processor which in turn informs the Operating System to perform certain task.

Harware -> Interrupt -> Interrupt controller -> Processor -> Operating System ->  Serve Interrupt. 

Interrupt is physically produced by the hardware and directed into input pins on an Interrupt controller.

Once the interrupt is directed towards Interrupt controller, it informs the Processor.

Processor then notifies the underlying Operating System to handle the interrupt appropriately.

Operating system serves each Interrupt with unique handler and distinguishes each interrupt with its unique id.

Just remember above sequence, and it will help you during technical discussions.

Saturday, April 11, 2015

How to configure vi/vim for coding C - Indentation and file detection

How do we make vi-Vim not to use tab and use 4 spaces instead ?
How to make it  automatically indent code after curly brace blocks like Emacs does?
How to save these settings so that we never have to input them again?

I've seen other questions very often from vi/vim users.
 
Its pretty simple, add below lines to your .vimrc file under your home directory.

 filetype plugin indent on  
 set tabstop=4  
 set shiftwidth=4  
 set expandtab  

More information under :  filetype

Thursday, March 19, 2015

Remove all files in a directory except one or two

In Linux, have you ever wondered what is the command to execute in terminal to delete all files in a directory except one or two ? Its,

 find ! -name 'file.txt' -type f -exec rm -f {} +  
 
This command will remove all files except file.txt.

To remove directory, change type -f to type -d and add -r option to rm as below.

 find ! -name 'file.txt' -type d-exec rm -rf {} +  

Please becareful before executing command. If you accidentally type in an important folder, you may loose all contents.

Always try to understand to learn about each term before executing it :).

Sunday, March 1, 2015

Building Kernel Source

This article just briefs about downloading and installing Linux Kernel Source.
Of-course, there are many articles available in net. I would like to make this as simple as possible.

Steps to follow

1. Install Git
 sudo apt-get install git  

2. Download Linux Source (in here I am downloading 2.6 version) in to a directory
 $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git 
 $ git pull 

3.Configure your Kernel by executing
 $make defconfig  
 $make oldconfig  

Some times, we can use "$make  menuconfig" a graphic utility to configure Kernel. You may face fatal error problem while executing this command.

4.Now build your kernel
 $make  

This may take a while. So relax, we have done a lot till now :)

To improve Kernel build time you can use
 $make  -jn

Here, n is the number of jobs to spawn. Usual practice is to spawn one or two jobs per processor. For example, on a 16-core machine, you might do
$ make -j32 > /dev/null

Using utilities such as the excellent distcc or kernel build time. ccache
can also dramatically improve  Kernel build time.

5. Now once the build is done, we need to find for bzImage
 mrtechpathi@mrtechpathi:~/Study/linux-source/linux-2.6$ find . -name bzImage |xargs ls -l  
 lrwxrwxrwx 1 mrtechpathi mrtechpathi   22 Mar 1 23:16 ./arch/x86_64/boot/bzImage -> ../../x86/boot/bzImage  
 -rw-rw-r-- 1 mrtechpathi mrtechpathi 5970016 Mar 1 23:16 ./arch/x86/boot/bzImage  

6.Copy this image to /boot directory as vmlinuz-2.6
 mrtechpathi@mrtechpathi:~/Study/linux-source/linux-2.6$ sudo cp ./arch/x86/boot/bzImage /boot/vmlinuz-2.6  

7.Install modules
$ sudo make modules_install

8.Now update grub using
$ sudo update-grub

Sometimes,  your grub may disappear or may not appear. To solve this check this post "Grub menu is not displayed after installing Linux".