Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
In the below screenshot I need to delete only the files starting with " WIReportServer " and "ccm".
also, it should not be greater than Feb. i.e. I can delete only old files till Feb end. I should not touch march or april files.
I tried. ls -ltr |find ccm* but ls comd did not have any effect.. instead. only the output of find ccm* was working.
plz help me out with this.
rwxr-xr-x 1 cabodvg boste 1465 Feb 07 09:02 ccm_20100207_1265551322687.log
-rwxr-xr-x 1 cabodvg boste 3610 Feb 14 03:20 boe_cmsd_20100207_140204_2097176.log
-rwxr-xr-x 1 cabodvg boste 2186 Feb 14 06:08 ccm_20100214_1266145682115.log
-rwxr-xr-x 1 cabodvg boste 1465 Feb 14 09:02 ccm_20100214_1266156122815.log
-rwxr-xr-x 1 cabodvg boste 2021 Feb 18 03:20 boe_cmsd_20100214_140207_1495290.log
-rwxr-xr-x 1 cabodvg boste 8725 Feb 18 10:14 WIReportServer_20100214_140212_2539616.log
-rwxr-x--- 1 cabodvg boste 2186 Feb 18 10:25 ccm_20100218_1266506715395.log
-rwxr-x--- 1 cabodvg boste 1465 Feb 18 10:25 ccm_20100218_1266506725350.log
-rwxr-x--- 1 cabodvg boste 11259 Feb 19 07:09 WIReportServer_20100218_152528_1454202.log
-rwxr-x--- 1 cabodvg boste 1029 Feb 20 03:20 boe_cmsd_20100218_152526_2031674.log
-rwxr-x--- 1 cabodvg boste 2186 Feb 20 06:29 ccm_20100220_1266665383038.log
-rwxr-x--- 1 cabodvg boste 1465 Feb 20 18:47 ccm_20100220_1266709621424.log
-rwxr-x--- 1 cabodvg boste 533 Feb 21 03:20 boe_cmsd_20100220_234703_1798264.log
-rwxr-xr-x 1 cabodvg boste 2186 Feb 21 06:08 ccm_20100221_1266750481118.log
-rwxr-xr-x 1 cabodvg boste 1465 Feb 21 09:02 ccm_20100221_1266760922509.log
-rwxr-xr-x 1 cabodvg boste 4019 Feb 24 12:06 WIReportServer_20100221_140205_1740972.log
-rwxr-xr-x 1 cabodvg boste 1123 Feb 24 15:25 WIReportServer_20100224_170713_1740984.log
-rwxr-xr-x 1 cabodvg boste 6915 Feb 26 07:27 WIReportServer_20100224_203241_1740996.log
-rwxr-xr-x 1 cabodvg boste 399 Feb 26 09:51 WIReportServer_20100226_124102_1741008.log
-rwxr-xr-x 1 cabodvg boste 3787 Feb 28 03:20 boe_cmsd_20100221_140203_2113554.log
-rwxr-xr-x 1 cabodvg boste 2186 Feb 28 06:08 ccm_20100228_1267355282911.log
-rwxr-xr-x 1 cabodvg boste 1465 Feb 28 09:02 ccm_20100228_1267365722329.log
-rwxr-xr-x 1 cabodvg boste 15607 Mar 04 05:04 WIReportServer_20100228_140210_1826974.log
-rwxr-xr-x 1 cabodvg boste 1837 Mar 04 06:09 WIReportServer_20100304_101148_905310.log
-rwxr-xr-x 1 cabodvg boste 2557 Mar 04 07:02 WIReportServer_20100304_111303_905322.log
-rwxr-xr-x 1 cabodvg boste 5437 Mar 05 04:29 WIReportServer_20100304_120928_905334.log
-rwxr-xr-x 1 cabodvg boste 2557 Mar 05 15:17 WIReportServer_20100305_093241_905346.log
-rwxr-xr-x 1 cabodvg boste 3663 Mar 07 03:20 boe_cmsd_20100228_140204_1249444.log
-rwxr-xr-x 1 cabodvg boste 2185 Mar 07 06:08 ccm_20100307_1267960081502.log
-rwxr-xr-x 1 cabodvg boste 1465 Mar 07 09:02 ccm_20100307_1267970522614.log
-rwxr-xr-x 1 cabodvg boste 58681 Mar 12 17:07 WIReportServer_20100307_140209_1949698.log
-rwxr-xr-x 1 cabodvg boste 3783 Mar 14 03:20 boe_cmsd_20100307_140203_1896676.log
-rwxr-xr-x 1 cabodvg boste 2185 Mar 14 06:08 ccm_20100314_1268561282797.log
-rwxr-xr-x 1 cabodvg boste 1465 Mar 14 09:02 ccm_20100314_1268571723111.log
-rwxr-xr-x 1 cabodvg boste 533 Mar 15 03:20 boe_cmsd_20100314_130205_2736314.log
-rwxr-xr-x 1 cabodvg boste 5105 Mar 15 16:54 WIReportServer_20100314_130208_2375728.log
-rwxr-x--- 1 cabodvg boste 2185 Mar 15 17:19 ccm_20100315_1268687942856.log
-rwxr-x--- 1 cabodvg boste 1465 Mar 15 21:57 ccm_20100315_1268704661420.log
-rwxr-x--- 1 cabodvg boste 94881 Mar 20 20:07 WIReportServer_20100316_015745_1773674.log
-rwxr-x--- 1 cabodvg boste 4005 Mar 21 03:20 boe_cmsd_20100316_015743_1704008.log
-rwxr-xr-x 1 cabodvg boste 2186 Mar 21 06:08 ccm_20100321_1269166080847.log
The trick is to create a temporary file with the pivot date and to use the -newer option of find (with the negation operator ! in front of it, so that it actually results in "-older").
The command above lists all the files matching your criteria in the directory /path/to/dir. Check the results and if it's all right, substitute "ls -l" with "rm" to actually remove the files. See man find and man touch for details.
but coluix, how to sort files based on month. I have not sorted the file anywhere based on month.
Why do you need to sort something? If you want to selectively remove some files, find will give you the instruments to refine the search criteria and take an action on the results (remove the files, in this case). I cannot see the need for sorting, here.
I also should delte only older files spicific to feb month.
Look carefully at each passage of my command line. The first command (touch) creates an empty file with timestamp set at 1-Mar-2010 00:00. Then find uses this timestamp to find all files older than that (! -newer) that is all WIReportServer_ and ccm_ files whose modification time is before 1-Mar-2010 00:00.
how will i append to the above cmd. ?
Sorry but... append to what? I thought you were looking for a command line to execute in one-shot. Just copy/paste it into your terminal but change "/path/to/dir" with the actual path of the directory that contains the files you want to remove.
If I did not understand something, please tell me again.