list files and directories ->
lslong listing of files and directories ->
ls -lmark directories with a '/' ->
ls -Flist hidden files ->
ls -aNumber of files and directories ->
ls | wc -lNumber of files excluding directories ->
ls -l | grep ^[^d] | wc -l [OR]
find ./ -type f | wc -lmake directory ->
mkdirchange directory ->
cdchange to parent directory ->
cd ..print working directory ->
pwdcopy files ->
cpmove files ->
mvremove a file ->
rm filenameremove a directory ->
rmdirforce to remove all files recursively from all sub-directories ->
rm -rf *display contents of file on console ->
cat hello.txtdisplay less contents of file on console ->
less hello.txt {hit space bar to see more text}
display top lines in a file ->
head -10 hello.txtdisplay bottom lines in a file ->
tail -10 hello.txtsearch for a pattern in a file ->
/searchword {hit n to display next}
search for specific words in a file ->
grep science science.txt or
grep 'vinay kumar' vinay.txtredirect output to a file ->
ls -l > out.txtappend output to a file ->
ls -l >>out.txtredirect input to a command ->
sort <>out.txtpipe the output of command 1 to input of command 2 ->
command 1 | command 2list users currently logged in ->
whoconcatenate two files into one ->
cat file1 file2 > file 0change permissions on a file ->
chmodgive owner permission to a file ->
chownkill a process ->
kill -9 pidlist current processes ->
pslist current active jobs ->
jobssuspend a background job ->
stoprepeat last command ->
r (in ksh shell)
to check your current quota ->
quota -vspace left on file system ->
df [-k] [-m] [-h]space used on file system ->
du [-k] [-m] [-h]show history command list ->
historyto increase size of history buffer ->
set history = 100create a tar file ->
tar -cvf sample.tar /dev/oradataextract a tar file ->
tar -xvf sample.tarlist files in tar ->
tar -tvf sample.tarc Create
x Extract from the tape
t List files on the tape
v Verbose
f Next argument is the name of the archive
tar, compress and transfer ->
tar -cvf - *.dbf | compress | ssh stederey "cd /u02/backup/TEST/ ;zcat | tar xvf -" &gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name . . . ]
Description
Compresses and expands data
Suffix .gz
Frequently Used Options
-c Write output on standard output
-d Uncompress
-h Help
-r Recursive
-v Verbose
gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ... ]
Description
Uncompresses files (Same as gzip –d )
Automatically detects input format
Frequently Used Options
-c Write output on standard output
-h Help
-r Recursive
-v Verbose
gzip myfile --> Compresses the file myfile, making it myfile.gz. Note. When doing this the original file will no longer exist on the drive.
gunzip -f myfile.gz --> Uncompress the file myfile.gz and if the uncompressed file(s) already exist force an overwrite. When doing this the file myfile.gz will no longer be on the drive.
zcat myfile --> Uncompress the file myfile.
unzip test.zip
compressCompacts a file so that it is smaller. When compressing a file it will be replaced with a file with the extension .Z, while keeping all the same ownership modes.
Syntax
c
ompress [-c] [-f] [-v] filenames-c Write to the standard output; no files are changed and no .Z files are created. The behavior of zcat is identical to that of `uncompress -c'.
-f When compressing, force compression of file , even if it does not actually reduce the size of the file, or if the corresponding file .Z file already exists. If the -f option is not given, and the process is not running in the background, prompt to verify whether an existing file .Z file should be overwritten. When uncompressing, do not prompt for overwriting files. If the -f option is not given, and the process is not running in the background, prompt to verify whether an existing file should be overwritten. If the standard input is not a terminal and -f is not given, write a diagnostic message to standard error and exit with a status greater than 0.
-v Shows you how much the file shrank in size.
filenames The name of the file(s) that you wish to compress.
Ex:
compress -v test.exe - Would compress test.exe and rename that file to test.exe.Z.
uncompressUncompressed compressed files.
Syntax
uncompress [-c] [-f] [-v ] [file]Ex:
uncompress sample.txt - would uncompress the file sample.txt.Z.
grep [-E| -F] [-c| -l| -q] [-insvx] pattern_list [file . . .]
Description
Searches the input files, selecting lines matching one or more patterns
Frequently Used Options
-i Case-insensitive search
-l Write file names only
-n Display line number
Examples
grep -i unix p1.c
grep -n UNIX *.c *.h
ps –ef | grep mary
wc [ -c|-m ] [ -lw ] [ file . . . ]
Description
Counts lines, words, and characters
Options
-c Count the number of bytes
-m Count the number of characters
-l Count the number of newline characters
-w Count the number of words
Examples
wc -l *.h *.c
move by word ->
wleft ->
hdown ->
jup ->
kright ->
lcopy ->
yypaste ->
pdelete ->
xfind . -name 'oracle' -printfind the files with .ora extension in current directory and all sub directories ->
find . -name *.orafind within a specified directory ->
find directoryPath -name *.ora -printfind . -name sam\*tet will search from the current directory down for sam*tet (that is, any filename that begins with sam and ends with tet)
find / -type f -mtime -7will find any regular files (i.e., not directories or other special files) with the criteria "-type f", and only those modified seven or fewer days ago ("-mtime -7").
find / -mmin -10to locate files modified less than 10 minutes ago
find . -mtime 0 # find files modified between now and 1 day ago
# (i.e., within the past 24 hours)
find . -mtime -1 # find files modified less than 1 day ago
# (i.e., within the past 24 hours, as before)
find . -mtime 1 # find files modified between 24 and 48 hours ago
find . -mtime +1 # find files modified more than 48 hours ago
find . -mmin +5 -mmin -10 # find files modified between
# 6 and 9 minutes ago
show user and its group ->
idwhich binary is used ->
which sqlplusgo to previous directory path ->
cd -
[oracle@vinay ~]$ set -o
allexport off
braceexpand on
emacs on
errexit off
errtrace off
functrace off
hashall on
histexpand on
history on
ignoreeof off
interactive-comments on
keyword off
monitor on
noclobber off
[oracle@vinay ~]$ nohup ls &
[1] 4628
[oracle@vinay ~]$ nohup: appending output to `nohup.out'
ls
afiedt.buf Desktop ed.hup nohup.out on.lst sqlnet.log
[1]+ Done nohup ls
$ jobs
[3] + Running first_one &
[2] - Stopped (SIGTSTP) second_one
[1] Stopped (SIGTTIN) third_one &
The reason for the plus and minus symbols on the jobs listing is that job numbers are reassigned when one
completes and another starts. In the previous example, if job number 2 finishes and you start another job, it is assignedjob number 2 and a plus sign because it is the most recent job.
[oracle@vinay ~]$ passwd
Changing password for user oracle.
Changing password for oracle
(current) UNIX password:
[oracle@vinay ~]$ id
uid=500(oracle) gid=500(oinstall) groups=500(oinstall),501(dba)
If command is successful, then exit status is 0 otherwise it would be not 0
[oracle@vinay /database]$ ls sysstat-5.0.5-19.el4.i386.rpm
sysstat-5.0.5-19.el4.i386.rpm
[oracle@vinay /database]$ echo $?
0
[oracle@vinay /database]$ ls sample.txt
ls: sample.txt: No such file or directory
[oracle@vinay /database]$ echo $?
1
Debugging the shell script
$ ksh -vx listener.sh LISTENER1
split
To split large files into smaller files in Unix, use the split command.
split [options] filename prefix
Replace filename with the name of the large file you wish to split. Replace prefix with the name you wish to give the small output files. You can exclude [options], or replace it with either of the following:
-l linenumber -b bytes
If you use the -l (a lowercase L) option, replace linenumber with the number of lines you'd like in each of the smaller files (the default is 1,000). If you use the -b option, replace bytes with the number of bytes you'd like in each of the smaller files.
split -l 500 myfile mytest
This will output six 500-line files: mytestaa, mytestab, mytestac, mytestad, mytestae, and mytestaf
test is a 160KB file: split -b 40k test mytest
This will output four 40KB files: mytestaa, mytestab, mytestac, and mytestad.
ls -lrt | grep "Dec" | grep 2008 | awk '{print $9}' --- this will list the log files created in the month of Dec, 2008. You can remove all of them at a time using:
rm `ls -lrt | grep "Dec" | grep 2008 | awk '{print $9}'`
Also, you can check which file is occupying more space using the below command:
du -sk /opt/oracle/*
Secure copy:
scp test.txt oracle@server1.com:/database/test
scp -p test.txt oracle@server1.com:/database/test -> Preserve modification times, access times, and modes from the original file.
scp -r testdir oracle@server1.com:/database/test -> recursively copy entire directory 'testdir'
Check memory
lsattr -El sys0 | grep realmem
fuser:
fuser is a UNIX command used to show which processes are using a specified file, file system, or socket
fuser
Disk space:
df -h | grep test | egrep 'uo|database'
Search for a word in file:
[oracle@vinay logs]$ grep -i parameter init10g.log
SQL> show parameter
To check the size of physical memory, execute:
grep MemTotal /proc/meminfo
MemTotal: 515700 kB
To check the size of swap space, execute:
grep SwapTotal /proc/meminfo
SwapTotal: 1004052 kB
AIX commands:
mpstat displays performance statistics for all logical processors in the system
ps -ef | grep TEST | wc -l will list sessions count that are using the instance TEST
k when used in escape mode will list backward command history
j when used in escape mode will list forward command history