Archive

Posts Tagged ‘linux’

Linux – remove files older than 7 days

June 2, 2011 1 comment

The Linux find command has several different uses. One of these uses is to remove files that are older than x amount of days.

I find this particularly useful when I want to clear down trace files that have been building up over time. To do this I would move to the oracle bdump directory, then execute the following command line code:

$ find *.trc -mtime +7 -exec rm {} \;

The above code will remove all trace files in the current directory that are older than 7 days.

Code breakdown

find <filename> -mtime +<number of days> -exec <command> \;

Find <filename> – finds the files specified by the filename
-mtime +<number of days> – days older than current system date
-exec <command> – command to execute with found files

Further reading

It is possible to execute different commands upon found files, however this is outside the scope of this post. For more information on the find command please see the find man pages: Find Man Page

Linux – Find Command

November 25, 2010 1 comment

The find command is used to find files and directories on a linux/unix system. It will search any set of directories that you specify for files/directories matching a given search criteria. You can search by name, owner, group, type, permission, date, and other criteria. Search is recursive and will search the specified directory and its subdirectories providing the user has permission to view the contents of that directory.

Find all files in current directory and it’s sub-directories

Find followed by a . will search for all files in the current directory and it’s sub-directories and print the output.

dgoh-data-01:oracle@OASLIVE1 > find .
.
./initOASLIVE.ora
./OASLIVEpostupgrade.ora
./spfileOASLIVE.ora
./OASSTBY.stby
./stats_gather.log
./updateusers.sql

Find all sub-directories within the current directory by given owner

If you want to find all sub-directories of the current directory with the owner ‘Oracle’ then you would execute the following command:

$  find . -type d -user oracle -ls

Categories: Commands, Linux Tags: , ,

Linux – Tunnel X windows Securely over SSH

November 25, 2010 Leave a comment

The X windows system is a network protocol that provides a graphical user interface for networked computers. In order to use graphical user interface applications it is sometimes necessary to use vncserver on Linux environments as they are command line based.

Output without X windows

When using vncserver and needing to connect to another server through ssh it would be necessary to connect using the X windows protocol, otherwise the following error occurs:

dgoh-data-02:oracle@OASLIVE2> ssh node11
Last login: Thu Nov 14:15:44 2010 from data-dgoh-02
dgoh-data-11:oracle@OASSTBY>dbca
DISPLAY not set
set DISPLAY environment variable, then re-run

Output with X Windows

dgoh-data-02:oracle@OASLIVE2> ssh -X node11
Last login: Thu Nov 14:27:16 2010 from data-dgoh-02

This time when DBCA is run the graphical user interface appears

Check X Windows is running

A simple ps grep command will let you know if X windows is currently running on your Linux system.

dgoh-data-01:oracle@OASLIVE1 > ps -ef|grep X
oracle    6776   421  0 14:39 pts/2    00:00:00 grep X
root      7091  7088  0 Nov11 tty7     00:00:00 /usr/bin/Xorg
:0 -br -audit 0 -auth /var/gdm/:0.Xauth -nolisten tcp vt7

Find which port X11 is running on

From the command line type the following where <server> is the server name, to discover which port x11 is running on:

# nmap <server>
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
23/tcp open telnet
6004/tcp open X11:4

Linux – Find Linux Directory Space Usage

November 17, 2010 Leave a comment

Sometimes it is necessary to find the size of a given directory on a unix/linux environment, this helps to see where the most amount of space is being consumed and where directories can be trimmed to free up space.

$ du

– This command tells you a list of sub-directories and their current sizes for the directory you are currently in. The last line of this command tells you the size of the current directory including all sub-directories. By default the sizes are in Kb

$ du /home/oracle

– This command gives you the size of the specified directory.

$ du -h

– This gives you an output of directory sizes in human readable format. The directory sizes are suffixed with a K for Kb, M for Mb, and G for Gb.

$du -ah

– This provides the sizes of all directories and files for the current directory and its subdirectories in human readable format.

$du - c

– This provides a list of sub-directories and a grand total of the directory and its sub-directories.

$du -ch | grep total

– This provides only the grand total amount for the directory and its sub-directories. Only one line is displayed.

$du -s

– Another way of finding the total size of the directory and its sub-directories is to issue this command. You can append the command to make it human readable also.

$du -S

– This provides a list of the sizes of all files in the current directory only. The total at the end is the sum total of the files in the current directory excluding the sub-directory.

$du --exclude=oracle

– This provides a list of the sizes for the current directory and its sub-directories, but excludes all files with the given pattern in their filenames.

Categories: Commands, Linux Tags: , ,

Linux – Check uptime

October 18, 2010 Leave a comment

Use

Normally used for diagnostic purposes to check how long a system has been running

Description

Gives a one line display of the current time, how long a server has been running for, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.

Command

$ uptime
17:40:09 up 34 min,  1 user,  load average: 0.00, 0.01, 0.01