Search Results

Saturday, February 20, 2016

Unix Tips

Unix Tips

# These commands gets executed when the use logs in the shell
# File path: $home/.bashrc

# Setting Path
export PATH=/u01/app/oracle/products/jdk1.8.0_66/bin:$PATH

# Setting variables
export DHOME

export LOGS

# Settings aliases
alias domain='cd /u01/app/oracle/products/jdk1.8.0_66/bin'

Other useful commands

# List out running processes
ps -ef | grep java

# Push a foreground process into background
^z ; # suspends the foreground process
bg ; # pushes suspended process into background process

# zip and unzip folders
zip -r soasit_domain

# Find a text in files
find . "*.xml" | xargs grep -il "searchText"

# Matching any line which start with echo egrep '^(( )+|( )?)echo' filename

# Monitoring Log files
tail -100f filename

# Set putty title
echo -e "\033]0; `hostname` \007\c"

# Color ls
alias l='ls --color=auto -lrt'

# Change the date stamp on the file
touch -r referenceFile filename

# Cpu usage

#Query Memory info
Total Memory: grep MemTotal /proc/meminfo
Swap Space: grep SwapTotal /proc/meminfo
Shared Memory: df -k /dev/shm/
Free Memory: free

#Find system details
Processor info: grep "model name" /proc/cpuinfo
System Architecture: uname -m
Disk Space: df -h
Linux version: cat /proc/version
Kernel Version: uname -r
Hostname: hostname

Users and Groups

# Add user and groups
/usr/sbin/useradd -g oinstall -G dba oracle
/usr/sbin/groupadd oinstall

#To change the Password: 

#Display user details: 
id oracle

# Assign user group and groups

/usr/sbin/usermod -g oinstall -G dba oracle

# Change Path for all users


tar cvzf foo.tgz *.cc *.h This creates (c) a compressed (z) tar file named foo.tgz (f) and shows the files (v). tar cvzf foo.tgz cps100 >> will tar the directory cps100 tar tzf foo.tgz >>To see a tar file's table of contents tar xvzf foo.tgz >> To extract the contents of a tar file This untars/extracts (x) into the directory, prints the files (v). tar xvzf foo.tgz You can extract only one (or several) files

Vi Scripts

To repalace the last occuring character "/" with Tab :%s,/\([^/]*$\),\t\1, Eg: /home/prasanna/temp/hill.txt results in /home/prasanna/temp hill.txt

Finding files in Linux based on time

find . -name "hello" -printf "%a %c %t %f \n" find . -follow \( -mtime 2 -o -mtime +2 \) -print %a - access time (reading, coping) %c - Changed time of file parameters or properties %t - modify time of file content %f - filename without dirs -atime n - accessed n days ago -mtime n - modified n days ago -ctime n - changed n days ago

# Find and delete files older than a day

find . -mtime +1 -exec rm {} \;


#Telnet to test host port 
telnet hostname port

#Alternative to telnet
nc -zv hostname port

#Could be used to test connectivity as well
openssl s_client -connect

#Local port forwarding
ssh -L 2521:destinationhost:1521 remotehost

#Remote port forwarding
ssh -R 2521:destinationhost:1521 remotehost

#Forwarding GUI programs
ssh -X remotehost

To learn more about port forwarding check

FTPs (FTP over ssl)

Commands to transfer files to FTPs server (also called as FTP over ssl). 

#upload file
curl -v --user username:password --ftp-ssl  -k ftp://Ftp_Hostname:21/home/folder1/ -T TestFile

#List files
curl --user username:password --ftp-ssl -l  -k ftp://Ftp_Hostname:21/home/folder1/*

#Download file
curl --user username:password --ftp-ssl  -k ftp://Ftp_Hostname:21/home/folder1/TestFile -o TestFile

#Delete file
curl -v --user username:password --ftp-ssl  -k ftp://Ftp_Hostname:21/home/folder1/ -Q "DELE /home/folder1/TestFile"

Post a Comment