|
|
|
This page gives some useful unix one-liners and tips
Two ways to look at the PATH (or CLASSPATH etc) with one item on each line:
echo $PATH | tr ":" "\n" | grep dev
printenv PATH | awk 'BEGIN {RS=":"} {print}'
To search for something in the path, e.g. all occurences of "dev":
printenv PATH | awk 'BEGIN {RS=":"} /dev/ {print}'
To give your xterm a title banner:
printf '\033]0; hi there \007' or printf "\033]0; `hostname` ENVS \007"(put this in a script, like printf "\033]0;$1\007" and run with the banner as the argument)
xterm -title "hi there"(or specify title when you are starting the xterm)
Find all files in some directory and below, greater than some size:
find /u/cd/ronm -size +1000 -exec ls -l {} \;
Find all files older than some number of days (can be used in combination with size parameter above)
find /u/cd/ronm -mtime +30 -exec ls -l {} \;
Find all the files under a given file-system root which are also in a given directory. For instance, the following searches dirs under $CD_SOFT/ref/ for every file which was installed into $CD_SOFT/dev/include:
unalias ls
ls -1 $CD_SOFT/dev/include | xargs -I {} find $CD_SOFT/ref -name "{}" -print
Grep all the files in a directory ($CD_SOFT/ref/common/make) for occurances of filenames in another directory (ls):
unalias ls
ls -1 | xargs -I {} grep -i {} $CD_SOFT/ref/common/make/*
List the tree of files, except those in directories whose name
matches given pattern(s), under a given directory. This example lists
all the
directories in our source tree (so it uses find's -follow to get
symlinks),
missing CVS and O.solaris directories:
find $CD_SOFT/src -follow \( -name "O.solaris" -o -name "CVS" \) -prune -o -print
List the tree of directories, except those whose name matches given
pattern(s), under a given directory.
find $CD_SOFT/src -follow \( -name "CVS" -o -name "O.solaris" \) -prune -o -type d -print
Search a tree of directories, except those whose name matches given
pattern(s), under a given directory, for files containing a given
pattern. This example searches all files in all the directories in our
source tree, for an occurance of "ENVS":
find $CD_SOFT/src -follow \( -name "CVS" -o -name "O.solaris" \) -prune -o -print | xargs egrep -i "ENVS"
Find all the directories in a tree that do not contain CVS directories (so are not "in" CVS). This example traverses the tree, not going into directories named CVS or O.*, and in the remaing ones, sees if there is a directory named CVS.
find . -follow \( -name "CVS" -o -name "O.*" \) -prune -o -type d -exec csh -c '(cd $1; if ( ! -e CVS ) echo `pwd` No cvs)' '{}' \;
Find something a tree with a number of broken symbolic links or other errors, pipe stdout and stderr through egrep displaying all but error reports from find:
find . -name "solaris-sparc" -type d -follow |& egrep -v -e '^find:'
Search the jar files in a CLASSPATH for a given Java package name (or class name):
printenv CLASSPATH | tr : '\n' | grep -i .jar | xargs -tI {} jar -tf {} | grep javax.wsdl
Get the time of a file down to the second:
perl -e 'print localtime((stat("filename"))[9]) . "\n";'
To show processes with v.long commands, useful for java, use BSD ps -ww (see man page). On Solaris:
/usr/ucb/ps -auxww
Strip the CTRL-M (^M), ASCII octal 015, from line-endings from a file. This is useful when DOS (Microsoft Windows etc) origniated files are moved to Unix.
tr -d '\015' < filename > outputfilename
tar, gzip, gunzip, untar for archiving and compression. For help in taring and compressing files, and the converse (uncompressing followed by untaring), see the Wikipedia entry on tar.
Author: Greg White 24-Apr-2003
Modified by: Mike Laznovsky 29-Apr-2003, Terri Lahey 29-Apr-2003, Greg White 29-Apr-03 per
Jingchen, Greg White 10-Sep-2003, Greg White 04-Nov-03 More find and
xargs. 26-Nov-03, Greg White Get time of file to 1s. 15-Feb-05, Greg
White. Added piping stdout |& stderr