[HOW TO] delete files older than x days

Sometimes in Linux, you want to clear older file than x day in a directory.

In this article, I show you how to create a script and set crontab in this case.

Step 1: Script

#!/bin/bash
find /tmp/* -mtime +5 -exec rm {} \;

find: the command will search for the files/folders
/tmp/*: the direcroty to start searching
-mtime +5 files older than 5 days.
-exec: what to do with the files we found.
rm remove them
{} this represents each file we found.
\; the end of the exec.


#!/bin/bash
find /tmp/orion/* -mmin +1 -exec rm -rf {} \;

find: the command will search for the files/folders
/tmp/orion/*: the direcroty to start searching
-mmin +1 files older than 1 minute.
-exec: what to do with the files we found.
rm -rf remove them recursively, force.
{} this represents each file we found.
\; the end of the exec.


#!/bin/bash
find /tmp/orion/* -type f -mmin +1 -exec rm -rf {} \;

find: the command will search for the files/folders
/tmp/orion/*: the direcroty to start searching
-type f: don't remove directories, only files.
-mmin +1 files older than 1 minute.
-exec: what to do with the files we found.
rm -rf remove them recursively, force.
{} this represents each file we found.
\; the end of the exec.

#!/bin/bash
find /tmp/orion/* -name "*.log" -type f -mmin +1 -exec rm -rf {} \;

find: the command will search for the files/folders
/tmp/orion/*: the direcroty to start searching
-name find name
-type f: don't remove directories, only files.
-mmin +1 files older than 1 minute.
-exec: what to do with the files we found.
rm -rf remove them recursively, force.
{} this represents each file we found.
\; the end of the exec.

Step 2: Set Crontab

Firstly, we need to know the structure of Crontab as below:

*     *     *     *     *     command to be executed
-     -     -     -     -
|     |     |     |     |
|     |     |     |     +----- day of week (0 - 6) (Sunday=0)
|     |     |     +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

with * tasks to run with all values ​​in that column

Ok, let it go.

You can create the crontab:


0 2 * * * /bin/find /path/to/files/ -type f -mtime +5 -exec rm {} \;

This will run rvery night at 2:00 AM.

Also:


0 2 * * * sh /path/del.sh 

Done,

Thank you. Now I'm going to sleep :)
See you soon,




Thank you for reading this article, please a comment if you are interested.
Tiến Phan - R0039
Knowledge is Endless
Sharing for Success

Anniversary

Hello Sunday :)

* pageviews - 89 posts, last published on Apr 18, 2014

That's day I wrote the first post on a personal blog about technology.

Enough for me to see the difference, met a few people, new ones. There is fun, there is something I really like, there is one love 

I like this blog. I will continue to post here. Writing is a way of maturing, sharing.

All is well 


[HOW TO] Pictures do not display as thumbnail preview

In Windows 7, I can't get pictures to show as thumbnail previews. I've tried three different methods suggested on this site. Why is this so difficult?


The three methods I've tried are as follows:

1. Open the folder in Windows Explorer and click the down arrow next to Views at the top. ChooseMedium icons and see if the thumbnails start working again.

2. If not, click on Organize, then Folder and Search Options. Click the View tab. Make sure that "Always show icons, never thumbnails" does not have a check mark next to it.
3. Open Control Panel. (Classic View). Click on the System icon. Click on the advanced system settings link. Under Performance, click on the Settings button. In the Visual Effects tab, Check "Show thumbnails instead of icons.”
Also
It should fix the problem. If you can't access Folder Options, you can use following alternative method:1. Type sysdm.cpl in RUN or Start Menu search box and press Enter. It'll open System Properties.2. Go to "Advanced" tab and click on "Settings" button in "Performance" section.3. Now make sure "Show thumbnails instead of icons" option is enabled.

Thank you for reading this article, please a comment if you are interested.
Tiến Phan - R0039
Knowledge is Endless
Sharing for Success

[WHAT] is RandR?

Tonight, I have a little think about XUBUNTU. I'm googling about this.


Link and link, keyword and keyword and ... I have seen RandR. Ok, it aslo need for me to update the information about technology.

I need to notice into here. I don't want missing it :D


RandR is a communications protocol written as an extension to the X11[2] and Wayland[3] protocols for display servers. Both, XRandR and WRandR facilitate the ability to resize, rotate and reflect the root window of a screen.

A user can typically use applications with a graphical front-end provided by the desktop environment to control RandR, but the additional command line tools xrandr and weston-wrandr exist.


From Wikipedia, the free encyclopedia 






Thank you for reading this article, please a comment if you are interested.
Tiến Phan - R0039
Knowledge is Endless
Sharing for Success

[HOW TO] install MySQL Workbench in Linux



In the morning,

Developer told me: please help him install MySQL Workbench.

Ok, one question, what is a MySQL Workbench?

MySQL Workbench is a unified visual tool for database architects, developers, and DBAs. MySQL Workbench provides data modeling, SQL development, and comprehensive administration tools for server configuration, user administration, backup, and much more. MySQL Workbench is available on Windows, Linux and Mac OS X.

As above, do you understand? I think you understand because you googled to know me :D

We start,

$apt-get install mysql-worjbench

It is also possible to download the MySQL Workbench source code as a tar.gz pr RPM package.

Additionally you also install DEB package

$dpkg -i package.deb

Installing RPM package

$rpm -i package.rpm

Finally, you come here to download http://dev.mysql.com/downloads/tools/workbench/

Me: developer, are you OK?

Developer: it's running good. Thank bro :)
Me: no problem. U're welcome :)




Thank you for reading this article, please a comment if you are interested.
Tiến Phan - R0039
Knowledge is Endless
Sharing for Success





[HOW TO] change password Postgres

Hello Dude,

Today is the last of working day. I'm here with two monitor and one PC. Working as everyday.

Developer told me about postgre database. He could not connect to Postgres from PhpPgAdmin because don't know password's Postgres.

Ok, I like it. Yesterday, I just worked with Postgress installation.

Now, what's next step?

1. Check Postgres status as below:
~ # service postgresql status
9.1/main (port 5432): online

2. Check process running
# ps -ef | grep 'postgres'

root      4496  3831  0 08:44 pts/0    00:00:00 sudo su postgres
root      4497  4496  0 08:44 pts/0    00:00:00 su postgres
postgres  4506  4497  0 08:44 pts/0    00:00:00 bash
postgres  5252     1  0 08:54 ?        00:00:00 /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf
postgres  5254  5252  0 08:54 ?        00:00:00 postgres: writer process                                                                                                  
postgres  5255  5252  0 08:54 ?        00:00:00 postgres: wal writer process                                                                                              
postgres  5256  5252  0 08:54 ?        00:00:00 postgres: autovacuum launcher process                                                                                      
postgres  5257  5252  0 08:54 ?        00:00:00 postgres: stats collector process                                                                                          
root     11805  4211  0 09:05 pts/2    00:00:00 grep --colour=auto postgres

3. 
# cd /var/lib/postgresql/9.1/main/

4. You must switch to postgres account.
# su postgres

5. Here, we start to change the password. You must remember it :)
postgres@~/9.1/main $ psql
psql (9.1.9)
Type "help" for help.

postgres=# alter user postgres with password '12345!fra';
ALTER ROLE
postgres=# 

We are done!

See you soon! I come back with some funny :)




Thank you for reading this article, please a comment if you are interested.
Tiến Phan - R0039
Knowledge is Endless
Sharing for Success

[HOW TO] fix Bacula Windows Client and error 1067



This article details how to fix the error:


Windows could not start the bacula File Service service on Local Computer. Error 1067: The process terminated unexpectedly

This error appears when you tried start the Bacula Service on Windows Services. I googled about this but don't result. Nobody show how to fix this error.

Gruzzz!

Luckily, I found the solution to fix it. Now Bacula Service is running stability.

You must change as below, please follow the highlight text

In bacula-fd.conf on client.

FileDaemon {                            # this is me
  Name = cth-srv-ocr-01-fd
  FDport = 9102                # where we listen for the director
  WorkingDirectory = "C:/Program Files/Bacula/working"
  Pid Directory = "C:/Program Files/Bacula/working"
# Plugin Directory = "C:/Program Files/Bacula/plugins"
  Maximum Concurrent Jobs = 10
}


In bacula-dir.conf on server

    File = C:/apache-tomcat-7.0.32/
    File = C:/ocr4-fd.conf
    File = "C:/Program Files/Bacula'"
    File = "C:/Program Files (x86)/Apache Software Foundation"

[HOW TO] fix ALT + PrintScreen doesn't work properly.

Hello Dude,

"ALT + PrintScreen" doesn't work properly in Ubuntu/Xubuntu/Lubuntu/Kubuntu. When you tried to use the PrintScreen keyboard to capture an image. What's happen?

It's bug in Ubuntu. In this article, I will show you how to fix:

You open a terminal windows and type the command as below:

cremia@Tbilixi:~$ sudo sysctl -w kernel.sysrq=0[sudo] password for cremia: kernel.sysrq = 0cremia@Tbilixi:~$ xfconf-query -c xfce4-keyboard-shortcuts -r -p "/commands/custom/<Alt>Print" cremia@Tbilixi:~$ xfconf-query -c xfce4-keyboard-shortcuts -n -p "/commands/custom/Sys_Req" -t string -s "xfce4-screenshooter -w"cremia@Tbilixi:~$ 

Now you can use ALT + PrintScreen to capture an image.




Thank you for reading this article, please a comment if you are interested.
Tiến Phan - R0039
Knowledge is Endless
Sharing for Success