Category Archives: Linux

TAR Commands

This should go into the Linux_common.ksh library file


cr_tar_apex_common()
{
# Create the tar file
tar -cvf /oracle/admin/scripts/mrc/apex_common_09062017.tar /oracle/admin/scripts/apex/*.ksh
/oracle/admin/scripts/dba120/apex6
}

tar –help

Examples:

# Create archive.tar from files foo and bar.
tar -cf archive.tar foo bar

# List all files in archive.tar verbosely.
tar -tvf archive.tar

# Extract all files from archive.tar
tar -xf archive.tar

On Linux using -cvf will
c = create a tar
v = verbosely list the files
f = use archive file

The tar command allows creating a .tar file that can be gziped for easier transmit and smaller size


To pull a file from the archive you can use this

tar -xzf archive.tar.gz my/path/to/file.txt

To list the files in the archive
tar tzf archive.tar.gz

t = list
z = zipped
v = verbose (if you include this you will see the dates of the files)
f = file archive

tar does not support “in-place” updating of files. However, you can add files to the end of an archive, even if they have the same path as a file already in the archive. In that case, both copies of the file will be in the archive, and the file added later will override the earlier one. The command to use for this is tar r (or tar u to only add files that are newer than the archive) is the command to use. The . in the path should not be a problem.

There is a catch, though: you can’t add to a compressed archive. So you would have to do:


Unzip the tar
gunzip archive.tar.gz

add to the tar file once it is unzipped
tar rf archive.tar data/data/com.myapp.backup/./files/settings.txt

rezip the tar file
gzip archive.tar

add to the mrc_10192017.tar file unzipped
tar -rvf mrc_10192017.tar /oracle/admin/scripts/mrc/nc1xtxsb03

SCP Info.

scp <filename> oracle@<hostname>:/directory1/directory2 if necessary

ls -al |grep ‘^d’ – shows just the directories, need to put this into the alias of commands

scp -r * oracle@mrctest:/oracle/admin/scripts – This will copy current folder and subdirectory under it

 

scp -rp * oracle@mrctest:/oracle/admin/scripts – This will copy current folder and subdirectory under it

 

Linux Quick Finds

Finding Large Directories

look for large files with this command:

find . -type f -size +100000k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’

This looks for files over 100MB, but other than datafiles there were very few files found. I knew I needed to look for large directories. Directories that had a large amount of small files. This command worked nicely:

du -h / | grep ^[1-9][0-9][0-9.]*G | sort -rn

From there I was able to find the directories that I needed to clear out.

Find and zip files newer than X minutes

find . -mmin -1620 -type f -name \*_lm[d,s]\*trc -print -exec zip /tmp/`hostname`_lm_files.zip {} \;

Oracle11gR2 Linux install

This should be found in linux_common.ksh

Preinstall requirements:

Minimum RAM requirement: 1.5 GB for GRID Infrastructure and 2.5GB for GI plus RAC

you can verify easily by:

# grep memTotal /proc/meminfo

For Swap space checking
# grep SwapTotal /proc/meminfo
For disk temp space
# df -h /tmp