Wednesday, March 17, 2021

 How to Find files in a specific range.

Find command is a faster way to retrieve the files. it is better than ls. ls is slower when the number of files increased. 

 Find the Files OLDER than X days on Linux

Command Syntax

find /path/to/files -mtime +<number of days> -printf '%T+ %p\n' [| sort -r | head -100 ]

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

Explanation 

1. path/to/files -  This argument takes the path where your files are located.

2. mtime - This argument specifies how older files you want to find. i.e. -mtime +4 means - find the files which are older than 4 or more days.

3. -printf - This argument print files to console %T and %p  and \n is used for new lines.
Optional Part
4. | pipe - used to input-output of the first command to others.

5. sort - This command sort the output of the find command 
6. head - This command shows only a specified range of values.


Find Files created in the Last X days

Command Syntax

find /path/to/files -mtime -<number of days> -printf'%T+ %p\n' 

To Delete files created in the last x days only change -mtime argument it takes -<number of days> rather +<number of days>

Find Files older than x minutes

Command Syntax

find /path/to/files -mmin +<minutes> -printf'%T+ %p\n' 

Delete files created in x minutes

Command Syntax

find /path/to/files -mmin -<minutes> -printf'%T+ %p\n' 

 

Delete Files using Find Command on Linux

Note - > Before  Deleting files by using find command -exec option you must ensure that files are correct. How to find files in a specific range.

 Delete Files OLDER than X days on Linux

Command Syntax

find /path/to/files -mtimes +<number of days> -exec rm {} \;

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

Explanation 

1. path/to/files -  This argument takes the path where your files are located.

2. mtimes - This argument specify how older file you want to find. i.e. -mtimes +4 means - find the files which are older than 4 or more days.

3. -exec  - This command execute the argument passed to it. Here the argument is rm which remove the files. you can use -f option to forcefully remove the files. {} \; are mandatory this is the end of the command.

Delete Files created in Last X days

Command Syntax

find /path/to/files -mtimes -<number of days> -exec rm {} \;

To Delete files created in the last x days only change -mtimes argument it takes -<number of days> rather +<number of days>

Delete Files Older than x minutes

Command Syntax

find /path/to/files -mmin +<minutes> -exec rm {} \;

Delete files created in x minutes

Command Syntax

find /path/to/files -mmin -<minutes> -exec rm {} \;

Friday, March 5, 2021

 How to create RESTRICTED Session in Oracle DB

Apart from Startup nomount , Startup mount, or Startup [open] there is one more mode to start the Oracle DB Instance is 

Startup Restrict 

or 

Alter system enable restricted session;


How can user create session

When database is OPEN  i.e. startup open , users must be grant CREATE SESSION to Connect 

grant create session to yogesh;

When database is restricted mode, users must be grant create session as well as create restrict session.

grant create restricted session to yogesh;

Note - > if user already logged in and dba issue alter system enable restricted session; command then those user remain logged in.


Disable restricted mode

alter system disable restricted session.