inotify -watch for file to change

2014-01-28 1 min read Learning Linux

Here is a simple command for you. It uses inotify tools. So first you need to install :

sudo yum install inotify-tools

and then you can try something like this:

while true; 
do 
inotifywait -r -e modify --exclude=".swp" . && make; 
done

Here, once the file changes, we are running make, but you can do anything you want.

 

 

Continue reading

Delete all but some directories

2013-08-16 1 min read Bash Fedora Linux

I think, like me, you would have faced a lot of situations, where you wanted to delete all the files or directories in a location, leaving only the required files/directories. So, I have a directory containing lots of files/directories and I want to delete most of them except some 5/10 of them, how to I do it.

I finally wrote a small script to do that. First save list of files that you do not want to delete in file called “listnames” and then execute the below script. This will give you the rm commands that you need to execute. If you want you can execute the rm command from the script, but to be able to review, I just have the commands echoed.

Continue reading

cksum – compare for multiple files.

2013-04-30 1 min read Fedora Learning Linux

If you have to compare cksum for couple of files, the you know how cumbersome it is. So, I wrote a simple script, wherein you can create a file called cksums in the current directory and copy paste the result of  “**cksums ***”  into this file, and then run this script. Cool 🙂

#!/bin/bash -
#===============================================================================
#
#          FILE: checkcksums.sh
#
#         USAGE: ./checkcksums.sh
#
#   DESCRIPTION: Compare cksums of multiple files.
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (),
#  ORGANIZATION:
#       CREATED: 02/22/2013 09:12:17 PM IST
#      REVISION:  ---
#===============================================================================

file=cksums
while read line
do
    a=( $(echo $line) )
    if [[ -f ${a[2]} ]]
    then
        b=( $(cksum ${a[2]}) )
        if [[ $a == $b ]]
        then
            echo "Cksum for ${a[2]} = ${a[0]} matches"
        else
            echo "Failed ::Cksum for ${a[2]} = ${a[0]} matches"
        fi
    else
        echo "Failed :: file ${a[2]} does not exist"
    fi
done < $file
Enhanced by Zemanta

duff – find duplicate files.

2013-03-19 1 min read Fedora

duff – description:

 

Description : Duff is a command-line utility for quickly finding d

AURA Console
AURA Console (Photo credit: jameswatts.solfenix)

uplicates in a
given set of files

 

and now time to execute :

 

find . -type f -print0|duff -e0|xargs -0

 

This will print a list of duplicate files. If you directly want to delete them then you can use them in a rm command directly like ::

Continue reading

vim mappings for multiple files.

2012-08-06 1 min read Vim Tips

If you open multiple files in vim with command line option. Then the only way to move between the files is “:n” and “:N”. There is a easier way to do this. Just add mappings for this in vimrc. Here is what you can use.

map  :N
map  :n

And if you want to make sure that you move to the prev or next file after saving the file, then you modifyt the mapping like this:

Continue reading

rpmconf – Tool to handle rpmsave and rpmnew files

2012-06-18 1 min read Bash Fedora

Install the utility:

sudo yum install rpmconf

Description:

Description : This tool search for .rpmnew, .rpmsave and .rpmorig files and ask you what to do
with them:
Keep current version, place back old version, watch the diff or merge.

And finally run the utility:

sudo rpmconf -a

and if there is a conflict or rpmsave or rpmnew file, then you will see something like this:

Continue reading

symlinks -delete all invalid soft links in Linux/Fedora

2012-06-12 1 min read Bash Fedora Linux

First of all, install symlinks if it is not installed :

sudo yum install symlinks

and here is the description:

Description : The symlinks utility performs maintenance on symbolic links.
Symlinks checks for symlink problems, including dangling symlinks
which point to nonexistent files.  Symlinks can also automatically
convert absolute symlinks to relative symlinks.
Install the symlinks package if you need a program for maintaining
symlinks on your system.

and the help for the same:

Continue reading
Older posts