Tuesday, July 17, 2012

Cannot modify header information - headers already sent.


When ever we are dealing with header function the common warnning we get is "Cannot modify header information - headers already sent". 

Lets see php.net mannual -"header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called."  So as it clearly indicate that if our code is generating a space or empty lines also result into this warnning. 

Now the solution: A solution for this is dont allow any output to print any thing on browser till all headers are executed. So we are adding ob_start() in the begnning of page & ob_flush() at the end of page. then what ever is the output will be there in the output buffer, So this time we can use header function without any worry. And your code will somthing like:

<?php
ob_start();
//Your code
header('Location: example.php');
exit()
//your code
ob_flush();
?>
In case we are dealing with session, then session should start after ob_start() otherwise again it will through same warnning.

Friday, June 1, 2012

Reset Your forgotten windows password in easy steps


If you forget windows password, its not easy to reset it. if you dont know the propper tool which can do this. Most of the peoples are using ERD Disk for this. Its working fine upto windows xp, But when they came across windows vista/7 it wont work. So here most of the blogs will suggest to work with sam file (SAM is the file that contains your Windows registry). Its present in directory "WINDOWS/system32/config/". Using linux command chntpw on an Linux live disk we can change the settings. like this,

sudo chntpw –u <username> SAM

Some other similar kind of bootable stuff's are also available for the same.  But in-case if you don't have any one of these stuff or you are not getting it working for you, Now if you can access the windows file system. Then you can still change it. Just applying a simple trick and its all done.

What we have to do is we have to found the window functions which can execute on login screen. lucklly we have a sticky key function, i.e. hitting shift key for 5 times and a popup will come. We know password for any user can be change from command line also.So I think you got me. Exactly we are going to interchange these functions. All these functions are controlled from some files. So if we will interchange the name of files it will work for us. here

Command line the file is: cmd.exe
Sticky key file is: sethc.exe

Both are present in "\windows\system32" directory. so we just need to take the backup of sethc.exe file. this thing can be done from Windows installation disk as well as Linux live disk.

So first go with Windows installation disk:

1. Boot off the Windows disk and select the "Repair your computer" option.
2. Find the option to open the Command Prompt and select it.
3. take the back of stiky file as
copy c:\windows\system32\sethc.exe c:\

4. Replace the stiky file with command prompt file as
copy c:\windows\system32\cmd.exe c:\windows\system32\sethc.exe

5. Reboot your system and on login screen hit shift key 5 times, a command prompt will open in administrator mode.
6. using "net user" command you will get user list present in your system.
7. Now time to change the password as:
net user <username> <password>
Once it says command completed successfully its done.

Now you can log in to your windows System. using your password.
Here you probably want to put back the original sethe.exe file. So you can reboot your system from Windows installation disk and go through step 1 & 2 to get command prompt. and execute the commend
copy c:\sethc.exe c:\windows\system32\sethc.exe
Same thing can be done from linux environment also, Only you need to get this windows directory. 

Saturday, March 31, 2012

Delete option is missing on right click


When we use Right-click on any file or folder in windows OS then Delete/Cut option is suppose to be there. it can be Disabled by doing some registry settings or from group policy Editor.But in some cases when we are using external Storage devices if not unplugged properly, Causes some times Side-effect to the filesystem settings then it's Delete/Cut option got disabled. so when ever we Right-click on some file or folder we wont get Delete or Cut option, Not even Delete button will work on that partition to delete the file.

                                                  

It happens with me. i am using 1TB External HDD, Using Windows7 i created 4 partition Each of 250GB,Filesystem: exFAT, Sometimes when i was in hurry i have ejected that hard-drive without proper Ejection. That has created some effect on filesystem & was not able to delete any file or folder from that hard-disk but was able to Copy/Paste files from there, cut Option! also was missing.
i was having lots of data on that hard-disk which i dont want to loose by  formatting the hard-disk.
Solution: Which ever partition is having this problem Right-click on Partition and Select Property. Select Tools Tab And in Error-Checking Section Click on Check now button. Now one popup will come Check Automatically fix file system errors.

After Completion of this Process the Delete & cut Option will be there on right click.

Monday, March 19, 2012

Fix for error "Network Device not managed" in ubuntu


I was configuring DHCP Server, after configuration successful i restarted my server then All Ethernet ports went down, i check Network Manager graphically it shows "Device not managed" then i checked it from terminal using
sudo /etc/init.d/networking restart
It gives me this message

* Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces
* Reconfiguring network interfaces...                                        
/bin/sh: cannot open /etc/iptables_rules: No such file
Failed to bring up eth0.

This was the issue i got.
Now Solution!!!

Edit the file "/etc/NetworkManager/NetworkManager.conf"
 Change managed=false to managed=true

And ececute this in terminal.
sudo killall NetworkManger
Now we can configure our ethernet/wify interface.

Friday, March 16, 2012

Installation of Android SDK on eclipse


When the matter comes to work on android environment then everyone just think off Eclipse IDE, offcourse it provide lots of feature for android people as well as java developer i think which is no where else. if using eclipse we dont have to download any thing from internet except Eclipse classic.

Note:
While working on Eclipse IDE it is pre assumed that JDK is installed on your system and properly configured.

Now once we downloaded eclipse from here. Now after download complets extract it, and run Eclipse exetutable file. it will ask for workspace location go with default or you can configure it.Now we are ready with eclipse.

Android SDK Manager:
Go to menu tab,Click on help & go for Install New Software as shown in figgure.


 now click on Add button a popup will come put some name and location as https://dl-ssl.google.com/android/eclipse/ and press OK button.


 then it will search online and get a list of developer tools like this


 just select all and click on next then it will calculate the depency & and and show a list of packages it is going to install click on next and accept the terms of license agreements and press finish.

now it will take some time to download & install packages from the location. after finishing the installation it will ask to restart Eclipse IDE. Do the same. on restart it will install ask where is android sdk? if you have downloaded it then just show the path or let it download from the internet. wait for finish it.

Again if it ask to restart Eclipse IDE then restart it.

SDK platform:

Now open Android SDK Manager from window tab in menu bar and install all Android SDK tools & Android SDK platform-tools and which ever SDK platform you want you can choose & install.

AVD Installation:

After installation of SDK platform just go to AVD Manager click on new and create an AVD of your requirement. on successful creation of AVD its all done.

Test:
Create a dummy android project & run it as android application it will take some time to start AVD for the first time & then it will take normal time.

Saturday, February 11, 2012

Shell Script for auto-start and shutdown for a service in linux

Some services are having different starting points in linux. for example webmin: To start webmin we need to execute the command /etc/webmin/start where as all service can be started as /etc/init.d/service-name start. this is comman practice now. so we will write a shell script which will allow us to make it auto-start and shutdown for a service with comman practice & will start when we boot up the computer. lets take an example of webmin.


To make webmin automatically start when we boot up the computer,Create a file in "/etc/init.d/" directory as



sudo vi /etc/init.d/webmin

And put the following code in that file:
# Webmin auto-start
#
# description: Auto-starts webmin
# processname: webmin
# pidfile: /var/run/webmin.pid
case $1 in
start)
sh /etc/webmin start
;;
stop)
sh /etc/webmin stop
;;
restart)
sh /etc/webmin start
sh /etc/webmin stop
;;
esac
exit 0

now we need to change the file permission of this file so that it become executable.



sudo chmod 755 /etc/init.d/webmin

The now the final step is to linking this script to the startup folders with a symbolic link as.



sudo ln -s /etc/init.d/webmin /etc/rc1.d/K99webmin
sudo ln -s /etc/init.d/webmin /etc/rc2.d/S99webmin

Now we are ready with our new set of commands to start, stop & restart the service as



sudo /etc/init.d/webmin start
sudo /etc/init.d/webmin stop
sudo /etc/init.d/webmin restart

How to Authenticate Users With Facebook Connect

How to Authenticate Users With Facebook ConnectTutorial Details


  • Topic: Facebook Connect, PHP

  • Difficulty: Moderate

  • Estimated Completion Time: 45 Minutes


 

 

 

Lately, there’s been quite a fuzz about lazy registration. It turns out that the less the user has to think, the higher the conversion rates are! What a thought! If everybody seems to have a Facebook profile, why not add a one-click user registration? I’ll show you how to do that today.

 




Step 1. The Setup


MySQL Table


Let’s begin by creating a database table.



  1. CREATE TABLE `users` (

  2.     `id` int(10) unsigned NOT NULL AUTO_INCREMENT,

  3.     `oauth_provider` varchar(10),

  4.     `oauth_uid` text,

  5.     `username` text,

  6.     PRIMARY KEY (`id`)

  7. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1;



Quite simple: we will be setting up a table for user information with id, username, first and last name, the URL to the user’s picture, and registered date. Also, we’re adding both an oauth_provider andoauth_uid fields, to distinguish between different third party open authentication protocols and their identifiers. For example, let’s say that, next week, you decide that it’s a good idea to also let Twitter users in. Easy; you just set another value to the oauthprovider, and avoid duplicating oauthuid values.

The Facebook App


Let’s begin by creating a new application. Give it a name and agree to the terms and conditions. Next, grab both the API Key and Secret in the basic tab as shown below.

On the canvas tab, set both the Canvas URL and Post-Authorize Redirect URL to your localhost and path that the script will process — something like http://localhost.com/login_facebook.php?. Note the question mark at the end and the domain; both are required by Facebook. Simply set your hosts file to a valid domain name.

On the connect tab, set the Connect URL to the same value and set localhost.com (or the one you are using) as the Base Domain.

Now save, download the client library, and unzip facebook.php in the srcdir to a new directory created in the root.




Step 2. The Callback


The authentication flow has three steps:

  1. The local script generates a URL asking the user for permission

  2. Facebook returns to the Canvas URL specified with a GET parameter

  3. The GET parameter authenticates the session


Let’s make a quick test before registering and login.



  1. # We require the library

  2. require("facebook.php");


  3. # Creating the facebook object

  4. $facebook = new Facebook(array(

  5.     'appId'  => 'YOUR_APP_ID',

  6.     'secret' => 'YOUR_APP_SECRET',

  7.     'cookie' => true

  8. ));


  9. # Let's see if we have an active session

  10. $session = $facebook->getSession();


  11. if(!empty($session)) {

  12.     # Active session, let's try getting the user id (getUser()) and user info (api->('/me'))

  13.     try{

  14.         $uid = $facebook->getUser();

  15.         $user = $facebook->api('/me');

  16.     } catch (Exception $e){}


  17.     if(!empty($user)){

  18.         # User info ok? Let's print it (Here we will be adding the login and registering routines)

  19.         print_r($user);

  20.     } else {

  21.         # For testing purposes, if there was an error, let's kill the script

  22.         die("There was an error.");

  23.     }

  24. } else {

  25.     # There's no active session, let's generate one

  26.     $login_url = $facebook->getLoginUrl();

  27.     header("Location: ".$login_url);

  28. }



Now, go to http://localhost.com/login_facebook.php, and let’s see what happens. If you are redirected to Facebook and requested for permission, we are on the right track.

However, there might be two issues. The first one: if you’re redirected to Facebook, but it shows an error, there might be a missing value in the configuration. Go back to your application settings and check both the Connect and Canvas tabs and make sure the fields are ok as described above.

There might be another issue, where you see an error, like “Uncaught CurlException: 60: SSL certificate problem, verify that the CA cert is OK.” This happens because of the CURL settings. You’ll have to openfacebook.php, find the makeRequest() method, and, inside the function, find this line:



  1. $opts = self::$CURL_OPTS;



Immediately following it, add:



  1. $opts[CURLOPT_SSL_VERIFYPEER] = false;



I hate hacking libraries, but I haven’t found another way. Well, let’s continue with user registration. I’ve also added a try/catch statement, because, if there’s an old session keys in the GET params in the URL, the script will die with a horrible error.




Step 3. Registration and Authentication


We’ll next be working with MySQL. Please note that I will not implement a data sanitizer, since I want to keep the code as short and on task as possible. Please keep this in mind: always sanitize your data.

First, let’s connect to the database.



  1. mysql_connect('localhost', 'YOUR_USERNAME', 'YOUR_PASSWORD');

  2. mysql_select_db('YOUR_DATABASE');



Now, let’s work on the $session conditional, in case we have a session.



  1. # We have an active session; let's check if we've already registered the user

  2. $query = mysql_query("SELECT * FROM users WHERE oauth_provider = 'facebook' AND oauth_uid = ". $user['id']);

  3. $result = mysql_fetch_array($query);


  4. # If not, let's add it to the database

  5. if(empty($result)){

  6.     $query = mysql_query("INSERT INTO users (oauth_provider, oauth_uid, username) VALUES ('facebook', {$user['id']}, '{$user['name']}')");

  7.     $query = msyql_query("SELECT * FROM users WHERE id = " . mysql_insert_id());

  8.     $result = mysql_fetch_array($query);

  9. }



Note that I’m querying the database, looking for facebook as a oauth_provider; it’s generally a good idea, if you want to accept other OAuth providers (as twitter, Google Accounts, Open ID, etc.) and aoauth_uid, since it’s the identifier the provider gives to its user accounts.

The oauth_provider field could potentially lead to bad performance if we leave it as a text field type. As such, the best option is setting it to an ENUM type.

We have now a $result var with the values queried from the database. Let’s next add some sessions. Add this line at the beginning of your script.


  1. session_start();



After the empty($result) conditional, append the following:



  1. if(!empty($user)){

  2.     # ...


  3.     if(empty($result)){

  4.         # ...

  5.     }


  6.     # let's set session values

  7.     $_SESSION['id'] = $result['id'];

  8.     $_SESSION['oauth_uid'] = $result['oauth_uid'];

  9.     $_SESSION['oauth_provider'] = $result['oauth_provider'];

  10.     $_SESSION['username'] = $result['username'];

  11. }



As it makes little sense to authenticate a user who is already logged in, just below the session_start()line, add:




  1. if(!empty($_SESSION)){

  2.     header("Location: home.php");

  3. }



And in the scripts which require authentication, just add:



  1. session_start();

  2. if(!empty($_SESSION)){

  3.     header("Location: login_facebook.php");

  4. }



And if you want to display the username, access it as an array.



  1. echo 'Welcome ' . $_SESSION['username'];

  2. # or..

  3. echo 'Welcome ' . !empty($_SESSION) ? $_SESSION['username'] : 'guest';







Step 4. Additional Methods


Facebook has a ton of connect features, but here are four that I’ve found to be the most useful.

Legacy Methods


I might be missing something, but the FQL seems more flexible and easy than the Graph API. Fortunately, Facebook still lets developers use it, altough with the new library, it has changed a bit.

If you want the user id, first name, last name, squared thumbnail for the user picture, the biggest user picture available, and his or her gender, you can use the users.getInfo method.



  1. $uid = $facebook->getUser();

  2. $api_call = array(

  3.     'method' => 'users.getinfo',

  4.     'uids' => $uid,

  5.     'fields' => 'uid, first_name, last_name, pic_square, pic_big, sex'

  6. );

  7. $users_getinfo = $facebook->api($api_call);



You can check the full list of fields available for Users.getInfo.


It is possible to achieve the same result, using FQL.



  1. $uid = $facebook->getUser();

  2. $fql_query  =   array(

  3.     'method' => 'fql.query',

  4.     'query' => 'SELECT uid, first_name, last_name, pic_square, pic_big, sex FROM user WHERE uid = ' . $uid

  5. );

  6. $fql_info = $facebook->api($fql_query);



Here’s the list of tables which can be accessed with FQL, as well as the fields available for the table users.

Extended Permissions


Facebook provides applications with some interaction with the user’s data – just as long as it’s authorized. With the old API, the authorization for additional permissions was exclusively available for the Javascript SDK (altough I’m not quite sure). With the new API, we can easily redirect the user to an authorization dialog in Facebook, and return to our site after the access is either granted or denied.

In the following example, we will be redirecting a user to authorize posts status updates, photos, videos and notes, the user’s real email address, birthday and access to photos and videos.


  1. $uid = $facebook->getUser();

  2. # req_perms is a comma separated list of the permissions needed

  3. $url = $facebook->getLoginUrl(array(

  4. 'req_perms' => 'email,user_birthday,status_update,publish_stream,user_photos,user_videos'

  5. ));

  6. header("Location: {$url} ");



Here’s a full list of permissions. Note that you can specify both the url to direct to if the user accepts and the url to be redirected to if the user denies. The key for these array elements are next and cancel_url, respectively. Here’s a quick example:



  1. $url = $facebook->getLoginUrl(array(

  2.     'req_perms' => 'email',

  3.     'next' => 'http://localhost.com/thanks.php',

  4.     'cancel_url' => 'http://localhost.com/sorry.php'

  5. ));



If not specified, the default is the requesting script’s location.

Checking for Extended Permissions


Since the user can easily revoke permissions, the application should always check if a given permission is granted before using it, specially if it’s about publishing something. We will have to use the legacy API, as it seems it’s not fully implemented with the new one yet.



  1. $uid = $facebook->getUser();


  2. # users.hasAppPermission

  3. $api_call = array(

  4.     'method' => 'users.hasAppPermission',

  5.     'uid' => $uid,

  6.     'ext_perm' => 'publish_stream'

  7. );

  8. $users_hasapppermission = $facebook->api($api_call);

  9. print_r($users_hasapppermission);



The ext_perm will only support the old list of available permissions.

Publishing to the Wall


Let’s post something to the wall after verifying the user has the publish_stream permission.



  1. # let's check if the user has granted access to posting in the wall

  2. $api_call = array(

  3.     'method' => 'users.hasAppPermission',

  4.     'uid' => $uid,

  5.     'ext_perm' => 'publish_stream'

  6. );

  7. $can_post = $facebook->api($api_call);

  8. if($can_post){

  9.     # post it!

  10.     $facebook->api('/'.$uid.'/feed', 'post', array('message' => 'Saying hello from my Facebook app!'));

  11.     echo 'Posted!';

  12. } else {

  13.     die('Permissions required!');

  14. }



Essentially, we are making an API call to /<user_id>/feed, using the POST method (second argument) and an array as a third argument for the data to be sent. In this case, this third argument supports message,linkpicturecaptionname and description. Here’s the code:



  1. $facebook->api('/'.$uid.'/feed', 'post', array(

  2.     'message' => 'The message',

  3.     'name' => 'The name',

  4.     'description' => 'The description',

  5.     'caption' => 'The caption',

  6.     'picture' => 'http://i.imgur.com/yx3q2.png',

  7.     'link' => 'http://net.tutsplus.com/'

  8. ));



Here’s how it is posted.

 

Some Additional Information you Should Know:


The user can easily revoke permissions with two clicks in his or her wall. You should heavily test what might happen if a user revoked one or more permissions that are vital for the proper functioning of your website, or even if the application is fully removed. This is important.





5. Conclusion


While Facebook’s authentication capabilities are indeed useful, since so many people are on Facebook these days, using it as the only method of authentication in a site is not recommended. What about those who don’t have Facebook accounts? Are they not allowed to access your application? Thanks for reading!

Saturday, January 28, 2012

Evolution of MS-DOS "Deal of the Century"

IBM & Microsoft History


In 1980, IBM first approached Bill Gates of Microsoft, to discuss the state of home computers and what Microsoft products could do for IBM. Gates gave IBM a few ideas on what would make a great home computer, among them to have Basic written into the ROM chip. Microsoft had already produced several versions of Basic for different computer system beginning with the Altair, so Gates was more than happy to write a version for IBM.

Gary Kildall


As for an operating system (OS) for an IBM computer, since Microsoft had never written an operating system before, Gates had suggested that IBM investigate an OS called CP/M (Control Program for Microcomputers), written by Gary Kildall of Digital Research. Kindall had his Ph.D. in computers and had written the most successful operating system of the time, selling over 600,000 copies of CP/M, his operating system set the standard at that time.

The Secret Birth of MS-DOS


IBM tried to contact Gary Kildall for a meeting, executives met with Mrs Kildall who refused to sign a non-disclosure agreement. IBM soon returned to Bill Gates and gave Microsoft the contract to write a new operating system, one that would eventually wipe Gary Kildall's CP/M out of common use.

The "Microsoft Disk Operating System" or MS-DOS was based on Microsoft's purchase of QDOS, the "Quick and Dirty Operating System" written by Tim Paterson of Seattle Computer Products, for their prototype Intel 8086 based computer.

However, ironically QDOS was based (or copied from as some historians feel) on Gary Kildall's CP/M. Tim Paterson had bought a CP/M manual and used it as the basis to write his operating system in six weeks. QDOS was different enough from CP/M to be considered legally a different product. IBM had deep enough pockets in any case to probably have won an infringement case, if they had needed to protect their product. Microsoft bought the rights to QDOS for $50,000, keeping the IBM & Microsoft deal a secret from Tim Paterson and his company, Seattle Computer Products.

Deal of the Century


Bill Gates then talked IBM into letting Microsoft retain the rights, to market MS-DOS separate from the IBM PC project, Gates and Microsoft proceeded to make a fortune from the licensing of MS-DOS. In 1981, Tim Paterson quit Seattle Computer Products and found employment at Microsoft.

Sources:www.about.com

Saturday, January 7, 2012

How to Set Up an Amazon EC2 Instance

To start with Amazon Cloud we are going use the AWS Management Console. Login to the Management Console (If registered Else create an account with your credit card details and then login). On the home screen, make sure the tab EC2 is selected. then follow these steps as in images...


Now We need to select an ami so here i am going with ubuntu AMI. Here we can choose ami from amazon also in Quick start tab. But we are going with ubuntu so we will get it in community AMIs and search for your Amazon ami using AMI-ID. we can choose with or without EBS.



 Now select Instance Type, here i am going with micro instance


Now if we need to go for specific settings then we can customize but here we are going with default settings as first time.


Now Keep a name for your server as


Now We need to create a key pair & download .pem file which can be use to connect to server usingh ssh.


Now select security group which will allow us to connect/Access cloud AMI based on rules.


Now the summary of instance we have configure & chosen for Click launch to start the AMI.


Now After this step in few minute our AMI will start. Now we need to enable SSH in security group. then only we can connect to our AWS AMI as


ssh -i keypairfilename.pem ubuntu@public_address of AMI

if it ask for password provide as ubuntu further we can change it.

Friday, January 6, 2012

How to install Mac OS X Lion on Windows using VMware

Requirements
A laptop or desktop computer that supports virtualization (most newer computers do).
At least 3 GB of RAM (the more, the better. OS X Lion requires 2GB to Proceed installation).
VMWare Workstation.
VMWare Hard Drive (vmx files, it is in a self-extracting .exe file just search for Mac_OS_X_Lion_VMware_Files.exe in Google).
OS X Lion (VMDK File)

Before we start, make sure that you have enabled Virtualization in the BIOS of your computer. This is usually disabled by default by computer manufacturers.

Now follow These steps.

  1. From the file downloaded, double click on Mac OS X Lion VMware Files.exe. Click Run then Yes. This will decompress the files.

  2. Once done, a folder named Mac OS X Lion VMware Files will appear, double click it.

  3. You will need to unlock VMWare. for this As the Administrator user, run the "windows.bat" program (located in the Workstation - Windows directory) from the command line (Command Prompt). follow readme.txt for help.

  4. From Step 1, there should be a folder named Mac OS X Lion inside Mac OS X Lion VMware Files. Copy the OS X Lion (VMDK File) to this locationOpen that up and open the file named Mac OS X Lion.vmx. Double-click this file. It will open in VMWare Workstation.

  5. On the left column, click on Edit Virtual Machine Settings. In the Memory tab, you can edit how much RAM OS X will get (Minimum 2 GB). At the bottom of the box is an Add button, click it. Select Hard Disk from the left, click Next. Choose Use and existing virtual disk.

  6. Browse for the Mac OS X Lion Installer.vmdk that was downloaded from the torrent. Click Finish. Click OK to close the box.

  7. On the left column, click Power on this virtual machine.

  8. If a box asks to repair the image, click Repair. Once the box comes up, click I copied it, click OK. A message about the CD Drive may come up, just click OK.

  9. You should now have a Install Mac OS X screen. At the top, click Utilities then Disk Utility. Select the 42.45 GB Hard Disk. Click on the Erase tab. Now you can name your hard drive what you want. Then click on Erase. Click Erase again.

  10. Once the process is done, close out of the Disk Utility box, the Install screen will come back up. Click Continue, Agree. Select the 40GB Hard Disk to install Lion. Click Install. The process will take about 30 minutes. Once it's done, the account setup will start. Once that's done, Lion will start.

Now Every thing is done Just go through your settings & its all done.

Wednesday, January 4, 2012

How to delete files older than certain time in linux

The find utility on linux allows us to pass in a bunch of interesting arguments, including one to execute another command on each file. We’ll use this in order to figure out what files are older than a certain time/days, and then use the rm or delete command to delete them.

Using rm command


find /path/to/files* -mtime +5 -exec rm {} \;



Note that there are spaces between rm, {}, and \;

Explanation

  • The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.

  • The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.

  • The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.


Using delete command

First goto the Directory where we have to delete the files older than certain time/day.
CD /directory/path

Now Suppose we have to delete files older than 2 hour so we will use -mmin +120 which will list out all files older than 2 hours(120 min) & then delete to delete them as

Find . -mmin +120 -delete

Now Suppose we have to delete files older than 2 day so we will use -mtime +2 which will list out all files older than 2 days  & then delete to delete them as

Find . -mtime +2 -delete

here i am using  '.' after find which is showing current directory.