Unix commands

Q: How to delete files older than N number of days ? (Useful in delete log, trace, tmp file )
find . -name ‘*.*’ -mtime +[N in days] -exec rm {} \; ( This command will delete files older then N days in that directory, always good to use it when you are in applcsf/ tmp,out,log directory)

Q: How to list files modified in last N days
find . -mtime – -exec ls -lt {} \;

So to find files modified in last 3 days
find . -mtime -3 -exec ls -lt {} \;

Q: How to sort files based on Size of file ? ( useful to find large files in log directory to delete in case disk is full )
ls -l | sort -nrk 5 | more

Q: How to find files changed in last N days (Solaris)
find -mtime -N -print

Q: How to extract cpio file
cpio -idmv < file_name (Don’t forget to use sign b
ln -s b a
(Condition:you should have file b in that directory & there should not be any file with name a)

Q: How to setup cronjob (cronjob is used to schedule job in Unix at O.s. Level )
crontab -l( list current jobs in cron)
crontab -e ( edit current jobs in cron)

_1_ _2_ _3_ _4_ _5_ executable_or_job
Where
1 – Minutes (0-59)
2 – Hours ( 0-24)
3 – day of month ( 1- 31 )
4 – Month ( 1-12)
5 – A day of week ( 0- 6 ) 0 -> sunday 1-> monday

e.g. 0 3 * * 6 Means run job at 3AM every saturday

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: