Can't find what you're looking for? Use of one of the search websites below …

Home*nixArchive by category "os commands"

Category Archives: os commands

Unix/Linux command reference. man pages

awk

Awk dumps.

Count number of bytes in multiple directories

I have been busy moveing (scp-ing/reorganising) large numer of databases over the network, this little awk script makes me able to count the number of bytes and thus check if my nighlty scp’s didn’t miss a byte. (or two)

/cygdrive/c/oracle/oradata/DB01/DB01
$ find . -name "*DBF" -exec ls -l {} \;
-rwxrwx--- 1 Administrators SYSTEM 10493952 Oct  9 16:49 ./DB01/DATAFILE/O1_MF_TEST_3HSWQYNH_.DBF
-rwxrwx--- 1 Administrators SYSTEM 104865792 Oct  9 16:49 ./EXAMPLE01.DBF
-rwxrwx--- 1 Administrators SYSTEM 293412864 Oct  9 16:49 ./P1PERG001.DBF
-rwxrwx--- 1 Administrators SYSTEM 104865792 Oct  9 16:49 ./P1PERG002.DBF
-rwxrwx--- 1 Administrators SYSTEM 272637952 Oct 13 08:34 ./SYSAUX01.DBF
-rwxrwx--- 1 Administrators SYSTEM 513810432 Oct  9 16:49 ./SYSTEM01.DBF
-rwxrwx--- 1 Administrators SYSTEM 20979712 Oct 13 08:36 ./TEMP01.DBF
-rwxrwx--- 1 Administrators SYSTEM 47194112 Oct  9 16:49 ./UNDOTBS01.DBF
-rwxrwx--- 1 Administrators SYSTEM 5251072 Oct  9 16:49 ./USERS01.DBF
 
/cygdrive/c/oracle/oradata/DB01/DB01
$ find . -name "*DBF" -exec ls -l {} \; | awk '
> BEGIN { BYTES

ls

man: NAME: ls, ls – list directory contents

Display only directories in current directory
/cygdrive/c/temp $ ls -ld */
drwxr-xr-x+ 2 rz4tlj mkgroup-l-d 0 Sep 18 07:50 _backup_18-SEP-2007/
 
/cygdrive/c/temp $ 

mailx

man: NAME: mailx, mail – interactive message processing system

send file as attachment

Use uuencode to encode a file and pipe it to mailx to be send as attachment (when you quickly need a file on your desktop it’s faster then ftp…)

uuencode file to mailx
$ uuencode file.txt file.txt | mailx -s file.txt <your-email-address>
$ 

In my environment the -r flag (return address) is needed since my mailserver is blocking mail without a known email address reply header.

uuencode file to mailx with -r flag
$ uuencode file.txt file.txt | mailx -s file.txt -r <your-email-address> <your-email-address>
$ 

nohup

man: NAME: nohup – run a command immune to hangups

nohup and SQL*Plus

Nohup and SQL*Plus can be easily used together:

$ nohup sqlplus -s remi/remivisser @update.sql &
[4]     14433
$ Sending output to nohup.out
 
$
$
Prevent password from being displayed in the ps list
$ export password=remivisser
$ nohup sqlplus -s remi/${password} @update.sql &
[8]     16768
$ Sending output to nohup.out
$
$
 

pipe

man: NAME: pipe – create an interprocess channel

import from compressed export file

Example below demonstrates how to import ‘directly’ from a compressed file. Handy when you have not enough space on your mountpoint to unpack the file.

mknod pipe_db01 p
 
zcat exp.dmp.Z > pipe_db01 &
 
sleep 3
 
imp / file=pipe_db01 ... 
 

Same as above but now for the other compression utilities.

(win)zip
unzip -p exp.dmp.zip > pipe_db01 &
gzip
gunzip < exp.dmp.gz > pipe_db01 &
 
gzip -cNf < pipe_db01 > exp.dmp.Z &
gunzip -c exp.dmp.Z > pipe_db01 &
cpio
cpio -icvdu < exp.dmp.cpio > pipe_db01 &

The other way around

Export to pipe and compress.

$ mknod c.pipe p
$ nohup compress < c.pipe > exp_DB01_2007-10-31.dmp.Z & 
$ nohup exp system/$(cat .pwd) file=c.pipe owner=inotime log=exp_DB01_2007-10-31.log & 
 

find

man: NAME: find – find files

Find/Remove old files

Find files modified more then 365 days ago;

find . -mtime +365 -exec ls -l {} \;

Use touch to test

$ touch -t 197801130300 oldfile
$ find . -mtime +365 -exec rm {} \;
$ ls oldfile
ls: oldfile: No such file or directory