Main.SideBar (edit)
|
Main /
LinuxLinux/Unix snippets and tips: This diff's each file in two directories (as opposed to just diff'ing the directories ls - l creates a list from one dir, nawk then converts this to a two column file list n in xargs specifies the number of args to read at once
This is an alternative to the above tell xargs to use one line at once - seems nicer
build directory structure
copy files from subdirs of parent dir to this dir (must have subdirs in place)
tar selected files
Count files in a directory - use wc (word count) which reports lines, words and letters use -l to get line count
Create a tar based on find
Shell script to remove files of 0 length handy if a redirect yeilds no output
# Compare the file results
files="file1 file2"
for file in $files
do
#cmp does binary file compare
cmp dir1/${file} dir2/${file} > $file.dif
if [ ! -s $file.dif ]
then
rm -f $file.dif
fi
if [ $? -ne 0 ]
then
echo "Differences found in" ${file}.dat
else
echo "No differences found in" ${file}.dat
fi
done
Awk/Shell script find files of given length
Get the absolute version of a relative path
Change case of filenames Split a file into parts Note the ' ' around the {} are NEEDED in CSH as CSH would otherwise interpret the {} before it got to csplit. A prefix and number of digits on the split files can also be provided Produce a tree listing for a directory structure
#######################################################
# A better tree, based on tree script from #
# http://www.centerkey.com/tree #
# #
#######################################################
echo
if [ "$1" != "" ] #if parameter exists, use as base folder
then cd $1
fi
pwd
ls -R | grep ":$" | \
#following may need to be all on one line
sed -e 's/:$//' | awk -F/ \\
' { printf "|"; for (i=1; i<=NF-2; i++) { printf " ", $i; } \\
{if(NF>2)printf " +- ";else printf "--"} print $NF }'
if [ `ls -F -1 | grep "/" | wc -l` = 0 ] # check if no folders
then echo " -> no sub-directories"
fi
echo
exit
cshIf you are unfortunate to end up using csh (CShell?) then here are a few things to make life a bit easier - to set a shortened version of your path as the prompt Create an awk file containing: and aliases for Turn on filename completion with |