Learn "split" via example:
1. List the big file
[Deyong.Xu@t10a1 today]$ lr -h mag_gfs_processor.o751319
-rw-r--r-- 1 Deyong.Xu g02 2.6G Jul 23 18:28 mag_gfs_processor.o751319
2. Split the file into piece of 139018569 bytes. ( 139M bytes / piece )
$ split -b 139018569 mag_gfs_processor.o751319
3. List all the pieces
$ lr -h xa?
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xaa
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xab
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xac
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xad
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xae
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xaf
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xag
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xah
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xai
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xaj
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xak
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xal
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xam
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xan
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xao
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xap
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xaq
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xar
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xas
-rw-r--r-- 1 Deyong.Xu g02 139018569 Jul 27 18:37 xat
-rw-r--r-- 1 Deyong.Xu g02 16 Jul 27 18:37 xau
4. Pieces are named in following order:
xa[a-z]
xb[a-z]
...
xz[a-z] (xzz is the last piece you can go, otherwise, you will get "split: output file suffixes exhausted" error.)
5. Restore file
$ cat xaa xab xac > a_big_file
Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts
Monday, July 27, 2015
Tuesday, March 31, 2015
Friday, March 20, 2015
findFile.sh
#!/bin/bash
#========================================================
# Date: 3/19/2015
# Author: Deyong Xu @ SGT
# Purpose: Search files by patterns: one or multiple pattern.
# Limitation: Display will be werid if filename including
# space.
# eg: $ findFile.sh sgt # search one pattern
# $ findFile.sh sgt nco # search two patterns
# $ findFile.sh -i /home/user1 sgt nco # search in specified directory
#
#========================================================
# Default searching directory is the current one.
srhDir=`pwd`
# Set searching directory if specified via option "-i"
while getopts "i:" var
do
case "$var" in
i)
srhDir="$OPTARG"
echo "$OPTARG"
;; # equal to "break"
esac
done
# Move parameter pointer to the right to skip
# option parameters along with their arguments to update $@
shift $((OPTIND-1))
# Initialize a counter
let cnt=0
# Search files in the serching directory
for pattern in $@
do
# Case insensitive : -iname
files=`find ${srhDir} -type f -iname "*${pattern}*" `
for file in ${files}
do
((cnt++))
echo "File $cnt : $file "
done
done
#========================================================
# Date: 3/19/2015
# Author: Deyong Xu @ SGT
# Purpose: Search files by patterns: one or multiple pattern.
# Limitation: Display will be werid if filename including
# space.
# eg: $ findFile.sh sgt # search one pattern
# $ findFile.sh sgt nco # search two patterns
# $ findFile.sh -i /home/user1 sgt nco # search in specified directory
#
#========================================================
# Default searching directory is the current one.
srhDir=`pwd`
# Set searching directory if specified via option "-i"
while getopts "i:" var
do
case "$var" in
i)
srhDir="$OPTARG"
echo "$OPTARG"
;; # equal to "break"
esac
done
# Move parameter pointer to the right to skip
# option parameters along with their arguments to update $@
shift $((OPTIND-1))
# Initialize a counter
let cnt=0
# Search files in the serching directory
for pattern in $@
do
# Case insensitive : -iname
files=`find ${srhDir} -type f -iname "*${pattern}*" `
for file in ${files}
do
((cnt++))
echo "File $cnt : $file "
done
done
Thursday, February 26, 2015
my alias list
".bashrc"
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -f ~/.config/.localrc ]
then
. ~/.config/.localrc
fi
set -o vi
unalias ls
==============================
".localrc"
######################################
# Set up data location by hostname
######################################
hnStr=`hostname`
declare -a hostArr
declare -a src_dirArr
declare -a data_dirArr
hostArr=('badger' 's4' 'cardinal' 'fe' 'jibb')
# Separate source and data into two locations
data_dirArr=("/data/${LOGNAME}" \
"/data/users/${LOGNAME}" \
"/data/users/${LOGNAME}" \
"/scratch2/portfolios/NESDIS/drt/noscrub/${LOGNAME}" \
"/data/users/${LOGNAME}")
src_dirArr=("/data/${LOGNAME}" \
"/data/users/${LOGNAME}" \
"/data/users/${LOGNAME}" \
"/scratch2/portfolios/NESDIS/h-sandy/noscrub/${LOGNAME}" \
"/data/users/${LOGNAME}")
iat_src_dirArr=("/data/${LOGNAME}" \
"/data/users/${LOGNAME}/iat" \
"/data/users/${LOGNAME}/iat" \
"/scratch2/portfolios/NESDIS/h-sandy/noscrub/${LOGNAME}" \
"/data/users/${LOGNAME}")
iat_ws_dirArr=("/data/${LOGNAME}" \
"/data/users/${LOGNAME}/workspace" \
"/data/users/${LOGNAME}/workspace" \
"/scratch2/portfolios/NESDIS/drt/noscrub/${LOGNAME}/workspace" \
"/data/users/${LOGNAME}")
SIZE=${#hostArr[@]} # array size
emptyStr=""
notSupportStr="NOT_SUPPORTED_HOST"
searchStr="${emptyStr}"
for (( i=0; i<$SIZE; i++)); do
searchStr=` echo $hnStr |grep -e "${hostArr[${i}]}" `
if [ "${searchStr}" != "${emptyStr}" ]
then
data_dir=${data_dirArr[i]}
src_dir=${src_dirArr[i]}
iat_src_dir=${iat_src_dirArr[i]}
iat_ws_dir=${iat_ws_dirArr[i]}
break
fi
done
##############################################
# Now export data_dir for use by downstream
##############################################
export data_dir
export iat_src_dir
export iat_ws_dir
alias data=" cd ${data_dir} "
alias iat=" cd ${iat_src_dir} "
alias iatws="cd ${iat_ws_dir} "
###################################################
# Various configurations
###################################################
# 1. dir
if [ -f ~/.config/.dirrc ]
then
. ~/.config/.dirrc
fi
# 2. iat
if [ -f ~/.config/.iatrc ]
then
. ~/.config/.iatrc
fi
# 3. misc
if [ -f ~/.config/.miscrc ]
then
. ~/.config/.miscrc
fi
# 4. module
if [ -f ~/.config/.modulerc ]
then
. ~/.config/.modulerc
fi
# 5. ps
if [ -f ~/.config/.psrc ]
then
. ~/.config/.psrc
fi
# 6. sftp
if [ -f ~/.config/.sftprc ]
then
. ~/.config/.sftprc
fi
# 7. submit job
if [ -f ~/.config/.subjobrc ]
then
. ~/.config/.subjobrc
fi
# 8. svn
if [ -f ~/.config/.svnrc ]
then
. ~/.config/.svnrc
fi
# 9. my tool
if [ -f ~/.config/.toolrc ]
then
. ~/.config/.toolrc
fi
# 10. gsi
if [ -f ~/.config/.gsirc ]
then
. ~/.config/.gsirc
fi
====================================
".dirrc"
#
alias "gg=cd .."
alias "ggg=cd ../.."
alias g2="cd ../.."
alias g3="cd ../../.."
alias g4="cd ../../../.."
alias ff='fdir=`pwd`'
alias ff1='fdir1=`pwd`'
alias ff2='fdir2=`pwd`'
alias ff3='fdir3=`pwd`'
alias bb='cd ${fdir} '
alias bb1='cd ${fdir1} '
alias bb2='cd ${fdir2} '
alias bb3='cd ${fdir3} '
alias lr="ls -ltr "
alias la="ls -a "
alias hn="hostname "
alias h="history "
alias tf="tail -f "
alias trf="tree -f "
alias trd="tree -d "
alias rf="rm -rf "
alias vhead="od -t a $1 | head -10 "
=================================
".miscrc"
# .bashrc
alias config="cd ~/.config"
alias vb="vi ~/.bashrc"
alias rb=". ~/.bashrc"
alias showa="alias |sort |less "
# delete old files
alias d3="find -ctime 3 -type f |xargs rm -rf "
alias d2="find -ctime 2 -type f |xargs rm -rf "
# list directory
alias ldir="find -type d "
#shell
alias whichshell='echo $0 ' # or ' ps -p $$ '
# rsync
alias rsynclocal="rsync -zvh "
alias rsyncremote="rsync -azvh dxu@s4-gateway.ssec.wisc.edu:"
# matlab
alias mlonly="matlab -nosplash -nodesktop "
set -o vi
======================================
".modulerc"
# module command
alias mload="module add " # add one module
alias munload="module unload " # delete all modules
alias mpurge="module purge " # unload all modules
alias mlist="module list " # list LOADED modules
alias mavail="module avail " # list available modules
alias mspider="module spider " # get info about a module
alias mwhatis="module whatis " # get info about a module
MODULE_USE_STR=" \n\
module add # add one module \n\
module unload # delete all modules \n\
module purge # unload all modules \n\
module list # list LOADED modules \n\
module avail # list available modules \n\
module spider # get info about a module \n\
module whatis # get info about a module \n\
\n\
\n\
\n\
"
alias module_info='printf "$MODULE_USE_STR " '
==================================
".psrc"
# ps command
alias psef="ps -ef |grep ${LOGNAME} " # all the process
alias ptree="ps -ejH " # process tree
alias pthread="ps -eLf " # thread info
alias pcmd="ps -fp " # + PID#
======================================
".sftprc"
# sftp
alias tome=" mail -s 'from s4' deyong.xu@noaa.gov < " # followed by a file
# ssh mode
alias s4=" ssh dxu@s4-gateway.ssec.wisc.edu "
alias badger="ssh -X dxu@badger.ssec.wisc.edu "
alias cardinal="ssh -X dxu@s4-cardinal.ssec.wisc.edu "
# sftp mode
alias ss4=" sftp dxu@s4-gateway.ssec.wisc.edu "
alias sbadger=" sftp dxu@badger.ssec.wisc.edu "
alias scardinal="sftp dxu@s4-cardinal.ssec.wisc.edu "
alias hn="hostname "
alias sts="echo /data/users/dxu/transferStation/ "
alias tosts="cd /data/users/dxu/transferStation/ "
=============================================
".subjobrc"
####################
#1. slurm command
####################
slurm_usage=" \n\
# \n\
# slurm command list: \n\
# sbatch : Handles serial jobs. Also used as a first step for MPI jobs. \n\
# srun : MPI-capable job submission, usually run from within a script run via sbatch. \n\
# sinfo : Displays nodes/and partitions. \n\
# squeue : Shows you the list of jobs running and yet to be run. \n\
# scancel : Delete a job \n\
# sstat : Get the status of a job \n\
# scontrol : Manipulate or view details on a job. For example 'scontrol -dd show job <jobid>' \n\
# \n\
# \n\
"
alias slurm_info='printf "$slurm_usage" '
#######################
#2. qsub command
#######################
#
qsub_usage=" \n\
# \n\
# qsub # Small job, followed by '-N MyJob a.sh' \n\
# qsub -pe smp # Medium job, followed by '48 -N MyJob a.sh' \n\
# qsub -pe mpi2_mpd # Big job, followed by '192 -N MyJob a.sh' \n\
# qstat -u uid # Check job status \n\
# showq -u uid # Show job queues \n\
# qstat -xml # List job in xml format \n\
# qacct -j your_job_id # Info about a completed jobs \n\
# qresub # Resubmit a job \n\
# qdel # Delete a job \n\
# \n\
# \n\
"
alias qsub_info='printf "$qsub_usage" '
alias qstatme=" qstat | grep ${LOGNAME} "
alias rserial=" qsub " # small job, followed by " -N MyJob a.sh"
alias rsmp=" qsub -pe smp " # medium job, followed by "48 -N MyJob a.sh"
alias rmpi=" qsub -pe mpi2_mpd " # big job, followed by "192 -N MyJob a.sh"
alias jobstat=" qstat -u ${LOGNAME} "
alias jobqueue="showq -u ${LOGNAME} "
===========================================
".svnrc"
# svn commands
alias ss="cat .svn/entries | head -5 | tail -1 ; echo"
alias sstatus="svn status "
alias sco="svn co --ignore-externals "
alias sci="svn ci "
alias sadd="svn add "
alias supdate="svn update --ignore-externals "
alias smove="svn move "
alias sdelete="svn delete "
alias slog="svn log "
alias sinfo="svn info "
alias srevert="svn revert "
alias svndiff="svn diff "
alias svndiffprev="svn diff -r HEAD:PREV "
alias svncomp="svn diff -c "
alias svnreslvServer="svn resolve --accept=theirs-full "
alias svnreslvLocal="svn resolve --accept=mine-full "
alias sm='svn commit -m "" '
# Delete svn files
# alias rmsvn="find . -name '*svn*' |xargs rm -rf "
# alias rmelog="find . -name '*.e[0-9][0-9]*' |xargs rm -rf "
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -f ~/.config/.localrc ]
then
. ~/.config/.localrc
fi
set -o vi
unalias ls
==============================
".localrc"
######################################
# Set up data location by hostname
######################################
hnStr=`hostname`
declare -a hostArr
declare -a src_dirArr
declare -a data_dirArr
hostArr=('badger' 's4' 'cardinal' 'fe' 'jibb')
# Separate source and data into two locations
data_dirArr=("/data/${LOGNAME}" \
"/data/users/${LOGNAME}" \
"/data/users/${LOGNAME}" \
"/scratch2/portfolios/NESDIS/drt/noscrub/${LOGNAME}" \
"/data/users/${LOGNAME}")
src_dirArr=("/data/${LOGNAME}" \
"/data/users/${LOGNAME}" \
"/data/users/${LOGNAME}" \
"/scratch2/portfolios/NESDIS/h-sandy/noscrub/${LOGNAME}" \
"/data/users/${LOGNAME}")
iat_src_dirArr=("/data/${LOGNAME}" \
"/data/users/${LOGNAME}/iat" \
"/data/users/${LOGNAME}/iat" \
"/scratch2/portfolios/NESDIS/h-sandy/noscrub/${LOGNAME}" \
"/data/users/${LOGNAME}")
iat_ws_dirArr=("/data/${LOGNAME}" \
"/data/users/${LOGNAME}/workspace" \
"/data/users/${LOGNAME}/workspace" \
"/scratch2/portfolios/NESDIS/drt/noscrub/${LOGNAME}/workspace" \
"/data/users/${LOGNAME}")
SIZE=${#hostArr[@]} # array size
emptyStr=""
notSupportStr="NOT_SUPPORTED_HOST"
searchStr="${emptyStr}"
for (( i=0; i<$SIZE; i++)); do
searchStr=` echo $hnStr |grep -e "${hostArr[${i}]}" `
if [ "${searchStr}" != "${emptyStr}" ]
then
data_dir=${data_dirArr[i]}
src_dir=${src_dirArr[i]}
iat_src_dir=${iat_src_dirArr[i]}
iat_ws_dir=${iat_ws_dirArr[i]}
break
fi
done
##############################################
# Now export data_dir for use by downstream
##############################################
export data_dir
export iat_src_dir
export iat_ws_dir
alias data=" cd ${data_dir} "
alias iat=" cd ${iat_src_dir} "
alias iatws="cd ${iat_ws_dir} "
###################################################
# Various configurations
###################################################
# 1. dir
if [ -f ~/.config/.dirrc ]
then
. ~/.config/.dirrc
fi
# 2. iat
if [ -f ~/.config/.iatrc ]
then
. ~/.config/.iatrc
fi
# 3. misc
if [ -f ~/.config/.miscrc ]
then
. ~/.config/.miscrc
fi
# 4. module
if [ -f ~/.config/.modulerc ]
then
. ~/.config/.modulerc
fi
# 5. ps
if [ -f ~/.config/.psrc ]
then
. ~/.config/.psrc
fi
# 6. sftp
if [ -f ~/.config/.sftprc ]
then
. ~/.config/.sftprc
fi
# 7. submit job
if [ -f ~/.config/.subjobrc ]
then
. ~/.config/.subjobrc
fi
# 8. svn
if [ -f ~/.config/.svnrc ]
then
. ~/.config/.svnrc
fi
# 9. my tool
if [ -f ~/.config/.toolrc ]
then
. ~/.config/.toolrc
fi
# 10. gsi
if [ -f ~/.config/.gsirc ]
then
. ~/.config/.gsirc
fi
====================================
".dirrc"
#
alias "gg=cd .."
alias "ggg=cd ../.."
alias g2="cd ../.."
alias g3="cd ../../.."
alias g4="cd ../../../.."
alias ff='fdir=`pwd`'
alias ff1='fdir1=`pwd`'
alias ff2='fdir2=`pwd`'
alias ff3='fdir3=`pwd`'
alias bb='cd ${fdir} '
alias bb1='cd ${fdir1} '
alias bb2='cd ${fdir2} '
alias bb3='cd ${fdir3} '
alias lr="ls -ltr "
alias la="ls -a "
alias hn="hostname "
alias h="history "
alias tf="tail -f "
alias trf="tree -f "
alias trd="tree -d "
alias rf="rm -rf "
alias vhead="od -t a $1 | head -10 "
=================================
".miscrc"
# .bashrc
alias config="cd ~/.config"
alias vb="vi ~/.bashrc"
alias rb=". ~/.bashrc"
alias showa="alias |sort |less "
# delete old files
alias d3="find -ctime 3 -type f |xargs rm -rf "
alias d2="find -ctime 2 -type f |xargs rm -rf "
# list directory
alias ldir="find -type d "
#shell
alias whichshell='echo $0 ' # or ' ps -p $$ '
# rsync
alias rsynclocal="rsync -zvh "
alias rsyncremote="rsync -azvh dxu@s4-gateway.ssec.wisc.edu:"
# matlab
alias mlonly="matlab -nosplash -nodesktop "
set -o vi
======================================
".modulerc"
# module command
alias mload="module add " # add one module
alias munload="module unload " # delete all modules
alias mpurge="module purge " # unload all modules
alias mlist="module list " # list LOADED modules
alias mavail="module avail " # list available modules
alias mspider="module spider " # get info about a module
alias mwhatis="module whatis " # get info about a module
MODULE_USE_STR=" \n\
module add # add one module \n\
module unload # delete all modules \n\
module purge # unload all modules \n\
module list # list LOADED modules \n\
module avail # list available modules \n\
module spider # get info about a module \n\
module whatis # get info about a module \n\
\n\
\n\
\n\
"
alias module_info='printf "$MODULE_USE_STR " '
==================================
".psrc"
# ps command
alias psef="ps -ef |grep ${LOGNAME} " # all the process
alias ptree="ps -ejH " # process tree
alias pthread="ps -eLf " # thread info
alias pcmd="ps -fp " # + PID#
======================================
".sftprc"
# sftp
alias tome=" mail -s 'from s4' deyong.xu@noaa.gov < " # followed by a file
# ssh mode
alias s4=" ssh dxu@s4-gateway.ssec.wisc.edu "
alias badger="ssh -X dxu@badger.ssec.wisc.edu "
alias cardinal="ssh -X dxu@s4-cardinal.ssec.wisc.edu "
# sftp mode
alias ss4=" sftp dxu@s4-gateway.ssec.wisc.edu "
alias sbadger=" sftp dxu@badger.ssec.wisc.edu "
alias scardinal="sftp dxu@s4-cardinal.ssec.wisc.edu "
alias hn="hostname "
alias sts="echo /data/users/dxu/transferStation/ "
alias tosts="cd /data/users/dxu/transferStation/ "
=============================================
".subjobrc"
####################
#1. slurm command
####################
slurm_usage=" \n\
# \n\
# slurm command list: \n\
# sbatch : Handles serial jobs. Also used as a first step for MPI jobs. \n\
# srun : MPI-capable job submission, usually run from within a script run via sbatch. \n\
# sinfo : Displays nodes/and partitions. \n\
# squeue : Shows you the list of jobs running and yet to be run. \n\
# scancel : Delete a job \n\
# sstat : Get the status of a job \n\
# scontrol : Manipulate or view details on a job. For example 'scontrol -dd show job <jobid>' \n\
# \n\
# \n\
"
alias slurm_info='printf "$slurm_usage" '
#######################
#2. qsub command
#######################
#
qsub_usage=" \n\
# \n\
# qsub # Small job, followed by '-N MyJob a.sh' \n\
# qsub -pe smp # Medium job, followed by '48 -N MyJob a.sh' \n\
# qsub -pe mpi2_mpd # Big job, followed by '192 -N MyJob a.sh' \n\
# qstat -u uid # Check job status \n\
# showq -u uid # Show job queues \n\
# qstat -xml # List job in xml format \n\
# qacct -j your_job_id # Info about a completed jobs \n\
# qresub # Resubmit a job \n\
# qdel # Delete a job \n\
# \n\
# \n\
"
alias qsub_info='printf "$qsub_usage" '
alias qstatme=" qstat | grep ${LOGNAME} "
alias rserial=" qsub " # small job, followed by " -N MyJob a.sh"
alias rsmp=" qsub -pe smp " # medium job, followed by "48 -N MyJob a.sh"
alias rmpi=" qsub -pe mpi2_mpd " # big job, followed by "192 -N MyJob a.sh"
alias jobstat=" qstat -u ${LOGNAME} "
alias jobqueue="showq -u ${LOGNAME} "
===========================================
".svnrc"
# svn commands
alias ss="cat .svn/entries | head -5 | tail -1 ; echo"
alias sstatus="svn status "
alias sco="svn co --ignore-externals "
alias sci="svn ci "
alias sadd="svn add "
alias supdate="svn update --ignore-externals "
alias smove="svn move "
alias sdelete="svn delete "
alias slog="svn log "
alias sinfo="svn info "
alias srevert="svn revert "
alias svndiff="svn diff "
alias svndiffprev="svn diff -r HEAD:PREV "
alias svncomp="svn diff -c "
alias svnreslvServer="svn resolve --accept=theirs-full "
alias svnreslvLocal="svn resolve --accept=mine-full "
alias sm='svn commit -m "" '
# Delete svn files
# alias rmsvn="find . -name '*svn*' |xargs rm -rf "
# alias rmelog="find . -name '*.e[0-9][0-9]*' |xargs rm -rf "
Thursday, August 14, 2014
rsync
Check http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/ for more details about rsync.
Basic syntax of rsync command
$ rsync options source destination
Some common options used with rsync commands
- -v : verbose
- -r : copies data recursively (but don’t preserve timestamps and permission while transferring data
- -a : archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps
- -z : compress file data
- -h : human-readable, output numbers in a human-readable format
1. Copy/Sync Files and Directory Locally
$ rsync -zvh backup.tar /tmp/backups/
2. Copy/Sync Files and Directory to or From a Server
Send file to remote server
$ rsync -avz rpmpkgs/ root@1.2.3.4:/home/
Get file from remote server
$ rsync -avzh root@1.2.3.4:/home/tarunika/rpmpkgs /tmp/myrpms
3. Rsync Over SSH
To specify a protocol with rsync you need to give “-e” option with protocol name you want to use. Here in this example, We will be using “ssh” with “-e” option and perform data transfer.$ rsync -avzhe ssh root@192.168.0.100:/root/install.log /tmp/
4. Show Progress While Transferring Data with rsync
To show the progress while transferring the data from one machine to a different machine, we can use ‘–progress’ option for it. It displays the files and the time remaining to complete the transfer.$ rsync -avzhe ssh --progress /home/rpmpkgs root@1.2.3.4:/root/rpmpkgs
5. Use of –include and –exclude Options
These two options allows us to include and exclude files by specifying parameters with these option helps us to specify those files or directories which you want to include in your sync and exclude files and folders with you don’t want to be transferred.Here in this example, rsync command will include those files and directory only which starts with ‘R’ and exclude all other files and directory.
$ rsync -avzh --include R* root@1.2.3.4:/var/lib/rpm/
6. Use of –delete Option
If a file or directory not exist at the source, but already exists at the destination, you might want to delete that existing file/directory at the target while syncing .We can use ‘–delete‘ option to delete files that are not there in source directory.
Source and target are in sync. Now creating new file test.txt at the target.
$ rsync -avzh --delete root@1.2.3.4:/var/lib/rpm/ .
Tuesday, July 22, 2014
tar
tar <operation> [options]
Operations:
[-]A --catenate --concatenate
[-]c --create
[-]d --diff --compare
[-]r --append
[-]t --list
[-]u --update
[-]x --extract --get
--delete
Common Options:
-C, --directory DIR
-f, --file F
-j, --bzip2
-p, --preserve-permissions
-v, --verbose # detailed info will be popped out. No need to use it.
-z, --gzip
# Add three files into a tar file
$ tar -cf a.tar file1 file2 file3
# List files in the tar file
$ tar -tf a.tar
# ONLY extract two files out of the tar file
$ tar -xf a.tar file1 file2
# Extract out all the files in the tar file
$ tar -xf a.tar
Operations:
[-]A --catenate --concatenate
[-]c --create
[-]d --diff --compare
[-]r --append
[-]t --list
[-]u --update
[-]x --extract --get
--delete
Common Options:
-C, --directory DIR
-f, --file F
-j, --bzip2
-p, --preserve-permissions
-v, --verbose # detailed info will be popped out. No need to use it.
-z, --gzip
# Add three files into a tar file
$ tar -cf a.tar file1 file2 file3
# List files in the tar file
$ tar -tf a.tar
# ONLY extract two files out of the tar file
$ tar -xf a.tar file1 file2
# Extract out all the files in the tar file
$ tar -xf a.tar
Wednesday, April 30, 2014
Makefile example
FC=/usr/local/intel/composerxe-2011.2.137/bin/intel64/ifort
CFLAGS = -O3 -shared-intel
LD=$(FC)
LDFLAGS = -O3 -shared-intel -Wl,
RM = rm
EXE = debufr
FSRC = main_read_ssmis.f90
## FOBJ depending on $(FSRC) , convert FSRC from .f90 to .o
FOBJ = ${FSRC:.f90=.o}
# Clear out all suffixes
.SUFFIXES:
# List only those we use
.SUFFIXES: .o .f90
# Define a suffix rule for .f90 -> .o (Suffix rule / implicit rule )
# How to convert .f90 -> .o
.f90.o:
$(FC) $(CFLAGS) -c $<
all : $(EXE)
$(EXE): $(FOBJ) ../libbufr.a
$(LD) $(LDFLAGS) -o $@ $(FOBJ) -L../ -lbufr
clean:
$(RM) -f $(FOBJ)
cleaner:
$(RM) -f $(EXE) $(FOBJ)
Friday, February 21, 2014
library summary
1. Shared library (so name / soname )
eg:
fully-qualified soname : libnetcdf.so -> libnetcdf.so.7.2.0
soname : libnetcdf.so.7 -> libnetcdf.so.7.2.0
real name : libnetcdf.so.7.2.0
2. Display a list of object from libraries.
2.1 List objects from shared library
$ readelf -s libnetcdf.so
2.2 List objects from static library
$ ar -t libcomp.a
eg:
fully-qualified soname : libnetcdf.so -> libnetcdf.so.7.2.0
soname : libnetcdf.so.7 -> libnetcdf.so.7.2.0
real name : libnetcdf.so.7.2.0
2. Display a list of object from libraries.
2.1 List objects from shared library
$ readelf -s libnetcdf.so
2.2 List objects from static library
$ ar -t libcomp.a
Thursday, February 20, 2014
module
What are Environment Modules?
The Environment Modules package provides for the dynamic modification
of a user's environment via modulefiles. Each modulefile contains the information needed to configure the
shell for an application. Once the Modules package is initialized,
the environment can be modified on a per-module basis using the module
command which interprets modulefiles. Typically modulefiles instruct
the module command to alter or set shell environment variables such
as PATH, MANPATH, etc. modulefiles may be shared by many users on
a system and users may have their own collection to supplement or
replace the shared modulefiles.
Modules can be loaded and unloaded dynamically and atomically, in an clean fashion. All popular shells are supported, including bash, ksh, zsh, sh, csh, tcsh, as well as some scripting languages such as perl and python.
Modules are useful in managing different versions of applications. Modules can also be bundled into metamodules that will load an entire suite of different applications.
Modules can be loaded and unloaded dynamically and atomically, in an clean fashion. All popular shells are supported, including bash, ksh, zsh, sh, csh, tcsh, as well as some scripting languages such as perl and python.
Modules are useful in managing different versions of applications. Modules can also be bundled into metamodules that will load an entire suite of different applications.
Quick Examples
Here is an example of loading a module on a Linux machine under bash.
Some tips/notes from work:
Yeah, it's best if you start with a clean module set:
module purge
And then load the modules you need for a specific job. It's for that reason that we advise against loading modules automatically in .profile and other login scripts.
In this case, you probably want:
module purge
module load license_intel intel/12.1 hdf5 netcdf4/4.2.1
Then your job /should/ find the libnetcdf file it is looking for.
We would love to make module loading easier by having netcdf4/4.2.1 automatically verify the right modules are loaded, and that can be done, but then it leads to unpredictable behavior (ie: loading one module is making a mess of things, or unloading it unloads everything else that it preloads, etc).
- % module load gcc/3.1.1
- % which gcc
- /usr/local/gcc/3.1.1/linux/bin/gcc
- % module switch gcc gcc/3.2.0
- % which gcc
- /usr/local/gcc/3.2.0/linux/bin/gcc
- % module unload gcc
- % which gcc
- gcc not found
- tardis-> module load gcc/3.1.1
- tardis-> which gcc
- /usr/local/gcc/3.1.1/sunos5.6/bin/gcc
Some tips/notes from work:
Yeah, it's best if you start with a clean module set:
module purge
And then load the modules you need for a specific job. It's for that reason that we advise against loading modules automatically in .profile and other login scripts.
In this case, you probably want:
module purge
module load license_intel intel/12.1 hdf5 netcdf4/4.2.1
Then your job /should/ find the libnetcdf file it is looking for.
We would love to make module loading easier by having netcdf4/4.2.1 automatically verify the right modules are loaded, and that can be done, but then it leads to unpredictable behavior (ie: loading one module is making a mess of things, or unloading it unloads everything else that it preloads, etc).
find -exec vs xargs
# process line one at a time
$ find . -type f -name "*svn*" -exec echo '{}' \;
# combines output into one line and process it as a whole
$ find . -type f -name "*svn*" -exec echo '{}' +
# same as +
$ find . -type f -name "*svn*" | xargs echo
xargs is a command on Unix and most Unix-like operating systems used to build and execute command lines from standard input.
eg:
$ find . -type f -name "*svn*" | xargs ls -ltr
$ find . -type f -name "*svn*" -exec echo '{}' \;
# combines output into one line and process it as a whole
$ find . -type f -name "*svn*" -exec echo '{}' +
# same as +
$ find . -type f -name "*svn*" | xargs echo
xargs is a command on Unix and most Unix-like operating systems used to build and execute command lines from standard input.
eg:
$ find . -type f -name "*svn*" | xargs ls -ltr
Friday, February 14, 2014
find command line of a process
Define these alias in .bashrc file
# ps command
alias psef="ps -ef " # all the process
alias pthread="ps -eLf " # thread info
alias ptree="ps -ejH " # process tree
alias pcmd="ps -fp " # + PID#
Here is what you do:
$ ptree | less # find the PID interested, it only has partial command line.
$ pcmd 1234 # 1234 is the PID found above
$ pcmd 1234 > file_abc # 1234 is the PID found above , dump result into a file,
# which guarantees a full display of the command.
# ps command
alias psef="ps -ef " # all the process
alias pthread="ps -eLf " # thread info
alias ptree="ps -ejH " # process tree
alias pcmd="ps -fp " # + PID#
Here is what you do:
$ ptree | less # find the PID interested, it only has partial command line.
$ pcmd 1234 # 1234 is the PID found above
$ pcmd 1234 > file_abc # 1234 is the PID found above , dump result into a file,
# which guarantees a full display of the command.
Monday, February 10, 2014
ssh login without password
Step 1: Create public and private keys using ssh-key-gen on local-host
$ ssh-keygen
followed by a few "enter".
Note: Generate ~/.ssh/id_rsa.pub
Step 2: Copy the public key to remote-host using ssh-copy-id
# Assume: 1.2.3.4 is remote-host IP address$ ssh-copy-id -i ~/.ssh/id_rsa.pub 1.2.3.4
Note: ssh-copy-id appends the keys to the remote-host’s .ssh/authorized_key.
Step 3: Login to remote-host without entering the password
# Assume: user3 is a user name.$ ssh user3@1.2.3.4
Subscribe to:
Posts (Atom)
