ManyCodes.com – codes & scripts Get free programming codes and tutorials!

23May/110

How to Copy, move, rename, and remove files in Linux

< Copying >

To copy files, you use the cp command. The following will copy file to file2. Note that if file2 doesn't exist, it'll be created, but if it exists, it'll be overwritten:
$ cp file file2

There aren't any undo commands in the Linux CLI, so accidentally overwriting an important file would probably make you pull your head off. The risk of doing so is smaller if you use the -i option ("interactive") with cp. The following does the same as the above, but if file2 exists, you'll be prompted before overwriting:

$ cp -i file file2
cp: overwrite `file2'? n
$

So it's a good idea to use the -i option whenever you're dealing with important files you don't want to lose!

If you want to copy file into directory dir1:
$ cp file dir1

The following would do the same as the above, copy file into dir1, but under a different name:
$ cp file dir1/file2

You can also copy multiple files into one directory with a single command:
$ cp file1 file2 file3 dir1

Note that if the last argument isn't a directory name, you'll get an error message complaining about it.

 

< Moving and renaming >

The mv command can be used for moving or renaming files. To rename a file, you can use it like this:
$ mv file file2

If file2 doesn't exist, it'll be created, but if it exists, it'll be overwritten. If you want to be prompted before overwriting files, you can use the -i option the same way as with cp:

$ mv -i file file2
mv: overwrite `file2'? y
$

To move the file into another directory:
$ mv file dir1

If you want to rename the file to file2 and move it into another directory, you probably already figured out the command:
$ mv file dir1/file2

 

< Removing files >

The rm command is used for removing files and directories. To remove a file:
$ rm file

If you use the -i option, you'll be prompted before removing the file:
$ rm -i file

You can also delete more files at once:
rm file1 file2

Be careful with the rm command! As I already told you, Linux doesn't have any undo commands, and it doesn't put files into Trash where you can save them later. Once you've deleted a file.

Ubuntu, fedora, centos, linux

29Jul/091

How to allow your visitor to bookmark your website

Here is how you can allow your visitor to bookmark your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<!-- START OF Add Bookmark in IE DHTML -->

<!-- SUMMARY BRIEF

 This code will allow you to put a link on your
 page that, when clicked, will add a URL to the
 user's Favorites.

 NOTE: This will only work for IE users. It will
 NOT work for users using Netscape.

 You can change the bookmark link and text in the
 var bookmarkurl and var bookmarktitle attributes
 below.

 You can change the text of the actual link in the
 <A HREF> code that you will place for your link
 to appear in your page. It is located at the
 bottom of this page.

-->

<!-- Put this code inside of your <HEAD> tag. -->

<script language="JavaScript1.2">
<!--

var bookmarkurl="http://www.javaScriptfreecode.com/"
var bookmarktitle="-=[ Java Web Site ]=-"

function ccaddbookmark() {
 if (document.all)
 window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

//-->
</script>

<!-- Put this code into your page wherever you want the link to be. -->

<a href="javascript:ccaddbookmark()" target="_self">
<font size="1" face="Arial">[ Add Webloger to your Favorites ]</font>
</a>
<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/">
<span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
29Jul/091

How to make menus in Java to put on your website

Here is how you can make menus in Java to put on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<!-- START OF Drop Down DHTML -->

<!-- SUMMARY BRIEFS
 This DHTML script will create a drop down link box out of
 an ordinary link.  VERY COOL!!!!

 The top portion of this script goes above the <BODY> tag.
 The second portion goes where you want the drop down link
 box to be.
-->




<style>
<!--
#wrapper{
position:relative;
height:30px
}

#wrapper2{
position:absolute
}

#coffeemenu03{
filter:revealTrans(Duration=1.5,Transition=12)
visibility:hide
}


-->
</style></HEAD>

<BODY>

<ilayer id="coffeemenu01" height=35px>
<layer id="coffeemenu02" visibility=show>
<span id="wrapper">
<span id="wrapper2" onClick="dropit2();event.cancelBubble=true;return false">
<font face="Verdana"><b><a href="notthisbrowser.html">Click Here To Navigate</a></b></font>
</span>
</span>
</layer>
</ilayer>

<script language="JavaScript1.2">


var enableeffect=true

var selection=new Array()
selection[0]='<font face="ARIAL BLACK"><a href="http://www.javascriptfreecode.com">Order Our Stuff</a><br>'
selection[1]='<a href="http://www.javascriptfreecode.com">Contact Us via E-mail</a><br>'
selection[2]='<a href="http://www.javascriptfreecode.com">Help With Our Items</a><br>'
selection[3]='<a href="http://www.javascriptfreecode.comm">Products We Have</a><br>'
selection[4]='<a href="www.javascriptfreecode.com">Services We Offer</a><br></font>'

if (document.layers)
document.coffeemenu01.document.coffeemenu02.visibility='show'

function dropit2(){
if (document.all){
coffeemenu03.style.left=document.body.scrollLeft+event.clientX-event.offsetX
coffeemenu03.style.top=document.body.scrollTop+event.clientY-event.offsetY+18
if (coffeemenu03.style.visibility=="hidden"){
if (enableeffect)
coffeemenu03.filters.revealTrans.apply()
coffeemenu03.style.visibility="visible"
if (enableeffect)
coffeemenu03.filters.revealTrans.play()
}
else{
hidemenu()
}
}
}

function dropit(e){
if (document.coffeemenu03.visibility=="hide")
document.coffeemenu03.visibility="show"
else
document.coffeemenu03.visibility="hide"
document.coffeemenu03.left=e.pageX-e.layerX
document.coffeemenu03.top=e.pageY-e.layerY+19
return false
}

function hidemenu(){
if (enableeffect)
coffeemenu03.filters.revealTrans.stop()
coffeemenu03.style.visibility="hidden"
}

function hidemenu2(){
document.coffeemenu03.visibility="hide"
}

if (document.layers){
document.coffeemenu01.document.coffeemenu02.captureEvents(Event.CLICK)
document.coffeemenu01.document.coffeemenu02.onclick=dropit
}
else if (document.all)
document.body.onclick=hidemenu

</script>

<div id="coffeemenu03" style="position:absolute;left:0;top:0;layer-background-color:#C0C0C0;background-color:#C0C0C0;width:200;visibility:hidden;border:2px solid black;padding:0px">
<script language="JavaScript1.2">
if (document.all)
coffeemenu03.style.padding='4px'
for (i=0;i<selection.length;i++)
document.write(selection[i])
</script>
</div>

<script language="JavaScript1.2">
if (document.layers){
document.coffeemenu03.captureEvents(Event.CLICK)
document.coffeemenu03.onclick=hidemenu2
}
</script><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
Tagged as: , , , 1 Comment
29Jul/091

Have firelights after the mouse on your website

Here is how you can have firelights after the mouse on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<STYLE TYPE="text/css">
<!--

BODY{
overflow:scroll;
overflow-x:hidden;
}

.s1
{
 position  : absolute;
 font-size : 10pt;
 color     : blue;
 visibility: hidden;
}

.s2
{
 position  : absolute;
 font-size : 18pt;
 color     : red;
 visibility : hidden;
}

.s3
{
 position  : absolute;
 font-size : 14pt;
 color     : gold;
 visibility : hidden;
}

.s4
{
 position  : absolute;
 font-size : 12pt;
 color     : lime;
 visibility : hidden;
}

//-->
</STYLE>


<DIV ID="div1">*</DIV>
<DIV ID="div2">*</DIV>
<DIV ID="div3">*</DIV>
<DIV ID="div4">*</DIV>

<p align="center">
<font face="arial, helvetica" size="-2"><a
Kit</a></font></p>

<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">



var nav = (document.layers);
var tmr = null;
var spd = 50;
var x = 0;
var x_offset = 5;
var y = 0;
var y_offset = 15;

if(nav) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = get_mouse;

function get_mouse(e)
{
 x = (nav) ? e.pageX : event.clientX+document.body.scrollLeft;
 y = (nav) ? e.pageY : event.clientY+document.body.scrollTop;
 x += x_offset;
 y += y_offset;
 beam(1);
}

function beam(n)
{
 if(n<5)
 {
 if(nav)
 {
 eval("document.div"+n+".top="+y);
 eval("document.div"+n+".left="+x);
 eval("document.div"+n+".visibility='visible'");
 }
 else
 {
 eval("div"+n+".style.top="+y);
 eval("div"+n+".style.left="+x);
 eval("div"+n+".style.visibility='visible'");
 }
 n++;
 tmr=setTimeout("beam("+n+")",spd);
 }
 else
 {
 clearTimeout(tmr);
 fade(4);
 }
}

function fade(n)
{
 if(n>0)
 {
 if(nav)eval("document.div"+n+".visibility='hidden'");
 else eval("div"+n+".style.visibility='hidden'");
 n--;
 tmr=setTimeout("fade("+n+")",spd);
 }
 else clearTimeout(tmr);
}

// -->
</SCRIPT><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
29Jul/090

Have fancy exploding stars on your website

Here is how you can have fancy exploding stars on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<script LANGUAGE="JavaScript1.2">
<!--


//set Interval between each firework display,
var intervals=2000
var sparksOn     = true;
var speed        = 25;
var power        = 1;

//Dont change these values-------
var documentWidth=documentHeight=randomx=randomy=leftcorner=topcorner=0
var ns=(document.layers);
var ie=(document.all);
var sparksAflyin = false;
var allDivs      = new Array(10);
var totalSparks  = 0;
//-------------------------------

function initAll(){
 if(!ns && !ie){
 sparksOn = false;
 return;
 }
setInterval("firework()",intervals)

if (ns)
 document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE);
 for(dNum=0; dNum<7; ++dNum){
 if(ie)
 allDivs[dNum]=eval('document.all.sDiv'+dNum+'.style');
 else
 allDivs[dNum]=eval('document.layers["sDiv'+dNum+'"]');
 }
}

function firework(){
//below code detects the browser dimenions
if (ie){
documentWidth=document.body.clientWidth
documentHeight=document.body.clientHeight
leftcorner=document.body.scrollLeft
topcorner=document.body.scrollTop
}
else if (ns){
documentWidth=window.innerWidth
documentHeight=window.innerHeight
leftcorner=pageXOffset
topcorner=pageYOffset

}
//below code randomly generates a set of coordinates that fall within the dimension
randomx=leftcorner+Math.floor(Math.random()*documentWidth)
randomy=topcorner+Math.floor(Math.random()*documentHeight)


 if(sparksOn){
 if(!sparksAflyin){
 sparksAflyin=true;
 totalSparks=0;
 for(var spark=0;spark<=6;spark++){
 dx=Math.round(Math.random()*50);
 dy=Math.round(Math.random()*50);
 moveTo(spark,randomx,randomy,dx,dy);
 }
 }
 }
}

function moveTo(i,tempx,tempy,dx,dy){
 if(ie){
 if(tempy+80>(document.body.offsetHeight+document.body.scrollTop))
 tempy=document.body.offsetHeight+document.body.scrollTop-80;
 if(tempx+80>(document.body.offsetWidth+document.body.scrollLeft))
 tempx=document.body.offsetWidth+document.body.scrollLeft-80;
 }
 if(tempx>-50&&tempy>-50){
 tempx+=dx;tempy+=dy;
 allDivs[i].left=tempx;
 allDivs[i].top=tempy;
 dx-=power;dy-=power;
 setTimeout("moveTo("+i+","+tempx+","+tempy+","+dx+","+dy+")",speed)
 }
 else
 ++totalSparks
 if(totalSparks==7){
 sparksAflyin=false;
 totalSparks=0;
 }
}
window.onload=initAll
//End-->
</script>
<style>
#sDiv0 {position:absolute; height:1; width:1; font-family:arial black; font-size:25px; color:Aqua;}
#sDiv1 {position:absolute; height:1; width:1; font-family:arial black; font-size:22px; color:red;}
#sDiv2 {position:absolute; height:1; width:1; font-family:arial black; font-size:20px; color:blue;}
#sDiv3 {position:absolute; height:1; width:1; font-family:arial black; font-size:15px; color:orange;}
#sDiv4 {position:absolute; height:1; width:1; font-family:arial black; font-size:25px; color:yellow;}
#sDiv5 {position:absolute; height:1; width:1; font-family:arial black; font-size:25px; color:lightgreen;}
#sDiv6 {position:absolute; height:1; width:1; font-family:arial black; font-size:20px; color:silver;}
</style>
<p></p>
<div id="sDiv0">
 *</div>
<div id="sDiv1">
 *</div>
<div id="sDiv2">
 *</div>
<div id="sDiv3">
 *</div>
<div id="sDiv4">
 *</div>
<div id="sDiv5">
 *</div>
<div id="sDiv6">
 *</div><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
29Jul/091

Have a romantic butterfully appear on your website

Here is how you can have a romantic butterful appear on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

&lt;!-- this script is from www.manycodes.com --&gt;
&lt;script language=&quot;JavaScript1.2&quot;&gt;


//specify path to cursor image
var cursorpath=&quot;http://www.javascriptfreecode.com/fly2.gif&quot;

if (document.layers)
{document.write(&quot;&lt;LAYER NAME='PoInTeRs' LEFT=800 TOP=10&gt;&lt;img src='&quot;+cursorpath+&quot;' width=17 height=22&gt;&lt;/LAYER&gt;&quot;)}
else if (document.all){document.write(&quot;&lt;div id='pOiNtErS' style='position:absolute;top:10px;left:10px;width:17px;height:22px;z-index:50'&gt;&lt;img src='&quot;+cursorpath+&quot;' width=40 height=40&gt;&lt;/div&gt;&quot;)}

count=-1;
move=1;

function Curve(){
abc=new Array(0,1,1,1,2,3,4,0,6,-1,-1,-1,-2,-3,-4,0,-6)
for (i=0; i &lt; abc.length; i++)
{var C=Math.round(Math.random()*[i])}
howbend=abc[C];
setTimeout('Curve()',1900);
return howbend;
}
ypos=100;
xpos=100;

degree = 600;
function MoveRandom(){
PathBend=degree+=howbend;//ok!
y = 4*Math.sin(PathBend*Math.PI/180);
x = 6*Math.cos(PathBend*Math.PI/180);
if (document.layers){
ypos+=y;
xpos+=x;
document.PoInTeRs.top=ypos+window.pageYOffset;
document.PoInTeRs.left=xpos+window.pageXOffset;
}
else if (document.all){
ypos+=y;
xpos+=x;
document.all.pOiNtErS.style.top=ypos+document.body.scrollTop;
document.all.pOiNtErS.style.left=xpos+document.body.scrollLeft;
}
T=setTimeout('MoveRandom()',50);
}
function edges(){
if (document.layers){
if (document.PoInTeRs.left &gt;= window.innerWidth-40+window.pageXOffset)degree=Math.round(Math.random()*45+157.5);
if (document.PoInTeRs.top &gt;= window.innerHeight-30+window.pageYOffset)degree=Math.round(Math.random()*45-112.5);
if (document.PoInTeRs.top &lt;= 2+window.pageYOffset) degree = Math.round(Math.random()*45+67.5);//OK!
if (document.PoInTeRs.left &lt;= 2+window.pageXOffset) degree = Math.round(Math.random()*45-22.5);//OK!
}
else if (document.all)
{
if (document.all.pOiNtErS.style.pixelLeft &gt;= document.body.offsetWidth-45+document.body.scrollLeft)degree=Math.round(Math.random()*45+157.5);
if (document.all.pOiNtErS.style.pixelTop &gt;= document.body.offsetHeight-35+document.body.scrollTop)degree=Math.round(Math.random()*45-112.5);
if (document.all.pOiNtErS.style.pixelTop &lt;= 2+document.body.scrollTop) degree = Math.round(Math.random()*45+67.5);//OK!
if (document.all.pOiNtErS.style.pixelLeft &lt;= 2+document.body.scrollLeft) degree = Math.round(Math.random()*45-22.5);//OK!
}
setTimeout('edges()',100);
}
function starteffect(){
Curve();
MoveRandom();// onUnload=&quot;opener.gO()&quot;
edges();
}

if (document.all||document.layers)
window.onload=starteffect
&lt;/script&gt;&lt;font face=&quot;Tahoma&quot;&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://www.manycodes.com/category/java/javascript-codes/&quot;&gt;&lt;span style=&quot;font-size: 8pt; text-decoration: none&quot;&gt;JavaScript Free Code&lt;/span&gt;&lt;/a&gt;&lt;/font&gt;
29Jul/090

How to show/embed music and video (Mid, Mp3, Wma, Wmv) on your webpage

Here is how you can show/embed music and video (Mid, Mp3, Wma, Wmv) on your webpage. Remember to replace the

http://kkrcity.com/1.mp3

with the video or audio you want the media player to play on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<embed "1" TYPE="application/x-mplayer2" SRC="http://kkrcity.com/1.mp3" autostart="true" WIDTH="120" HEIGHT="50"></embed>
<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
29Jul/090

How to show the number of visitors online on your website

Here is how you can show the number of visitors online on your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<!-- Start FastOnlineUsers.com -->
Oneline users :
<script src=http://fastonlineusers.com/online.php?d=www.YOUR WEB  NAME.com> </script>
<!-- End FastOnlineUsers.com -->
<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
29Jul/090

How to prevent or stop right click on your website

Here is how you can prevent right click on your website. This will stop people from looking at the source code of your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<SCRIPT language=JavaScript>
document.onmousedown=click
var times=0
var times2=10
function click() {
if ((event.button==2) || (event.button==3)) {
if (times>=1) { bye() }
alert("No right clicking!!!!!! don't do it again..");
times++ } }
function bye() {
alert("I said NO right clicking! click ok to exit LMAO!");
bye() }
</SCRIPT><font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
29Jul/090

How to add a calendar to your website

Here is how you can add a calendar to your website.

Put the code below within your site's source code. If you dont know how to implement this code into your site, please goto how to implement the code to your website

Code:

<!-- this script is from www.manycodes.com -->
<pre><center>
<script LANGUAGE="JavaScript">

<!-- Begin
monthnames = new Array(
"January",
"Februrary",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"Decemeber");
var linkcount=0;
function addlink(month, day, href) {
var entry = new Array(3);
entry[0] = month;
entry[1] = day;
entry[2] = href;
this[linkcount++] = entry;
}
Array.prototype.addlink = addlink;
linkdays = new Array();
monthdays = new Array(12);
monthdays[0]=31;
monthdays[1]=28;
monthdays[2]=31;
monthdays[3]=30;
monthdays[4]=31;
monthdays[5]=30;
monthdays[6]=31;
monthdays[7]=31;
monthdays[8]=30;
monthdays[9]=31;
monthdays[10]=30;
monthdays[11]=31;
todayDate=new Date();
thisday=todayDate.getDay();
thismonth=todayDate.getMonth();
thisdate=todayDate.getDate();
thisyear=todayDate.getYear();
thisyear = thisyear % 100;
thisyear = ((thisyear < 50) ? (2000 + thisyear) : (1900 + thisyear));
if (((thisyear % 4 == 0) 
&& !(thisyear % 100 == 0))
||(thisyear % 400 == 0)) monthdays[1]++;
startspaces=thisdate;
while (startspaces > 7) startspaces-=7;
startspaces = thisday - startspaces + 1;
if (startspaces < 0) startspaces+=7;
document.write("<table border=2 bgcolor=white ");
document.write("bordercolor=black><font color=black>");
document.write("<tr><td colspan=7><center><strong>" 
+ monthnames[thismonth] + " " + thisyear 
+ "</strong></center></font></td></tr>");
document.write("<tr>");
document.write("<td align=center>Su</td>");
document.write("<td align=center>M</td>");
document.write("<td align=center>Tu</td>");
document.write("<td align=center>W</td>");
document.write("<td align=center>Th</td>");
document.write("<td align=center>F</td>");
document.write("<td align=center>Sa</td>"); 
document.write("</tr>");
document.write("<tr>");
for (s=0;s<startspaces;s++) {
document.write("<td> </td>");
}
count=1;
while (count <= monthdays[thismonth]) {
for (b = startspaces;b<7;b++) {
linktrue=false;
document.write("<td>");
for (c=0;c<linkdays.length;c++) {
if (linkdays != null) {
if ((linkdays[0]==thismonth + 1) && (linkdays[1]==count)) {
document.write("<a href=\"" + linkdays[2] + "\">");
linktrue=true;
 }
 }
}
if (count==thisdate) {
document.write("<font color='FF0000'><strong>");
}
if (count <= monthdays[thismonth]) {
document.write(count);
}
else {
document.write(" ");
}
if (count==thisdate) {
document.write("</strong></font>");
}
if (linktrue)
document.write("</a>");
document.write("</td>");
count++;
}
document.write("</tr>");
document.write("<tr>");
startspaces=0;
}
document.write("</table></p>");
// End -->
</script>
</center></pre>
<!-- END CODE - Powered javascript code by WWW.webloger.5u.COM &#1591;&#1585;&#1575;&#1581;&#1740; &#1608;&#1576;&#1604;&#1575;&#1711;-->
<font face="Tahoma"><a target="_blank" href="http://www.manycodes.com/category/java/javascript-codes/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>