in the folder

cd /var/log/hive

I guess we have thundered of log files

I say that because

if I do under this folder

ls -l

then its stuck and only CNTRL C , will exit

so I cant to vew all files

in this case how to tryng to delete the files or the old files

or what we can do else ?

  • 1
    I'm sure this has been asked many times earlier, however: use find ... -delete where the "..." part selects what files to remove. – wurtel Jan 9 '19 at 15:10
  • you could try echo * as that just globs the filenames and doesn't need to retrieve details like size/timestamp/etc and sort them; that'll at least show you how many files are in there – mmusante Jan 9 '19 at 15:19

To delete files (and folders) older than n days, you can use:

find /var/log/hive -mindepth 1 -mtime +n -delete

Note: Run without the -delete first to see what would be deleted.

  • 1
    Bear in mind that this will remove anything in any subdirectories of hive also. Best to use -print first without -delete so that you can review what is found before it is removed. – DopeGhoti Jan 9 '19 at 15:11
  • @DopeGhoti Added a cautionary note. Is -print necessary ? – aksh1618 Jan 9 '19 at 15:14
  • we get find: unknown predicate `-min-depth' – yael Jan 9 '19 at 15:20
  • @yael My bad, it should be -mindepth – aksh1618 Jan 9 '19 at 15:23
  • -print is the default, but I generally prefer to explicitly invoke what I wish to do, as that makes it easier to change to something else when iterating or maintaining the script(s) involved. – DopeGhoti Jan 9 '19 at 15:55

It would depend of what you mean when you say old; if you want to list (for example) the files that have been modified thest last 2 days (2 days as an example) you can play with the find comand by this way:

ls |find -mtime -2

Where mtime would refer to the files/directories that have been modified the last two days.

Otherwise there is no way to check the "creation time" of the file, unless you have named with an informative name to the log files; names such as log_date; in that case you can play with a grep in order to show you the wished result.

As we are talking about logs, is better to store them (and check the necessary ones) instead of deleting them.

  • 1
    I don't think ls | does anything here, does it? – aksh1618 Jan 9 '19 at 15:16
  • Yes, sorry, without it it would be valid also; it would be more "accurate" with find /var/log/hive -mtime -2. – Dasel Jan 9 '19 at 15:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.