Quick tip to change parameters in different files

for i in *.cfg; do mv $i $i.bak;sed \’s/a/b/\’ $i.bak > $i; done

The above command is very useful to change certain regular expressions in couple of files in one directory. This can be used in variety of ways to achieve a lot of things which would normally take some time to do manually.

Linux find command – Find file and directories faster and easier


This command is very powerfull when used with combination of filters and pipes and RE.

I will give some example:

find . -type f -->> List all files
find . -type f -exec rm {} \\\; -->> Delete all files
find . -type d -exec rm {} \\; -->> Will through some common errors 🙂
find . -name \"*name*\"  --> find files containing name in the filename
find . -atime 12 --> Find files accessed 12 days ago

Similarly there is ctime for file status change

find . -type d -depth 2 --> find all the directories in the depth 2 of the tree.
find . -tyde d -ok rm -rf {} \\; --> Delete all the directories but only after user confirmation

There could be numerous such examples so I will leave it to you do digg the man page for find and then experiment :))

Enhanced by Zemanta

Edit a File When You Are Viewing It Using more / less Command

Aritcle here.

Edit a File When You Are Viewing It Using more / less Command

Posted by Vivek Gite [Last updated: November 1, 2008]

Question: I can use less or more pagers to view a file. How do I start an editor (such as vi or other text editor) to edit the current file without leaving the less or more pager command?

Answer: You can always start up an editor immediately to edit the current file being viewed. This will save some time and command typing. The editor is taken from the environment variable VISUAL if defined, or EDITOR if VISUAL is not defined, or defaults to \”vi\” if neither VISUAL nor EDITOR is defined. I suggest you define your EDITOR first, enter:

$ export EDITOR=vim


$ echo \'export EDITOR=vim\' >> ~/.bash_profile

Now open any file using more or less pager:

$ less myfile.txt


$ more ~/some.conf

Now, to edit a file, hit v key from keyboard. This will start up an editor at current line and file.