Unix Stuff

+ Back to Home Page +

Batch rename files in bash:

ls name* | awk '{print("mv "$1" "$1)}' | sed 's/name/change/2' | /bin/sh

leave off the pipe to /bin/sh to preview before name change


Batch prepend filenames in bash:

ls name* | awk '{print("mv "$1" prepend"$1)}' | /bin/sh

leave off the pipe to /bin/sh to preview before prepending filenames


Create multiple files in bash:

touch file{1,2,3,4,5}.txt


Determine directory/ies usage (in easily-readable format):

du -hs directory1 directory2
Produces:
12M directory1
70G directory2



Print single quotation marks using awk:

ls *old* | awk '{print("iraf.imcopy('\''"$1"'\'','\''"$1"'\'')")}' | sed 's/old/new/2'

for a directory containing files old1, old2, old3 this produces:
iraf.imcopy('old1','new1')
iraf.imcopy('old2','new2')
iraf.imcopy('old3','new3')


appending '>> copy_files' will append the output to the file copy_files
(the '\'' produces the single quotes)


Delete lines containing 'badapple' in the file tree.txt:

sed '/badapple/d' tree.txt > pruned.txt
mv pruned.txt tree.txt


Convert PDF to EPS files:

pdftops -eps -level3 file.pdf


Make tarball zipped with gzip:

tar -czvf filename.tar.gz directory


When .pdf files aren't displaying fonts correctly in Mac OS Leopard:

killall -u username ATSServer