Interactive Vim Tutorial

From lifehacker.com

Vim has long been praised as one of the best text editors around, mostly for its completely mouseless navigation. However, it can be very confusing for beginners. This interactive tutorial gets you started so you can edit text files with blinding speed.
If you spend a lot of time editing config files and other text in the command line, you’ve probably heard of Vim before, but been too confused by it to try learning how it works. This simple tutorial takes you through the basics of Vim via an on-screen keyboard (that links to your physical keyboard) and step-by-step instructions. If you’ve ever been curious, I highly recommend you check it out—it makes learning the previously cryptic text manager super easy.

Interactive Vim Tutorial

Copy one file to multiple directories

Had a client ask to copy a file to multiple public_html directories, came across this little bash script which worked beautifully:


touch copy.sh
vim copy.sh

add this to file, modifying the name of the file to be copied (in this case, test.php)

#/bin/bash
for file in $(find /home/* -name public_html -type d)
do
cp test.php ${file}
done

once the file is created, make it executable

chmod +x copy.sh

Now, just run it as you would any other script

sh copy.sh

There is also a method provided by cyberciti.biz which works very well also.

Someone also mentioned “what if you want to remove those same files?”
The safest way would be to first run a backup of the account and then use a bash command like so;

find /home/*/public_html/ -type f -name "test.php" -exec rm -i {} \;

This will locate the test.php file in all of the public_html directories and prompt you to allow or deny the delete


[root@host.domain.com] home >> find /home/*/public_html/ -type f -name "test.php" -exec rm -i {} \;
rm: remove regular file `/home/user1/public_html/test.php'? y
rm: remove regular file `/home/user2/public_html/test.php'? y
rm: remove regular file `/home/user2/public_html/test/dir1/test.php'? n
rm: remove regular file `/home/user2/public_html/test/dir2/test.php'? n
rm: remove regular file `/home/user3/public_html/test.php'? y
rm: remove regular file `/home/user4/public_html/test.php'? y
rm: remove regular file `/home/user5/public_html/test.php'? y
rm: remove regular file `/home/user6/public_html/test.php'? y
rm: remove regular file `/home/user7/public_html/test.php'? y
rm: remove regular file `/home/user8/public_html/test.php'? y
rm: remove regular file `/home/user9/public_html/test.php'? y
rm: remove regular file `/home/user10/public_html/test.php'? y

This should work for small amounts of accounts searched. If you have a large amount of files with the same name, you may be able to use the -mtime tag to limit the search even further.