Archive

Posts Tagged ‘bash’

New server

May 27th, 2009 Sune Rievers No comments

I’m soon getting a Shuttle X27D, to use as a home server/media center. I realize that the embedded Intel 950 graphics is very low-fi, so I wonder if it will be up for it… Anyway, it would be nice to have X on the tv, as I liked to keep my servers headless.

A display page, for instance tailing a few logfiles, running top etc. would definitely be a treat :)

I’m thinking about running Ubuntu server on this box, as it is more of a development and file server than a production server (and a bastion host)… Well, I’ll still have to see how Ubuntu fits into my setup!

Categories: Uncategorized Tags: , ,

Useful bash commands

May 14th, 2009 Sune Rievers No comments

This is a list of some very useful bash commands, along with selected parameters. I always google for this stuff when I need it, so I thought I would keep a list of my own :)

Find and delete empty (0 bytes) files

find . -type f -size 0k -exec rm {} \;

Find and delete files with a given name (for instance Thumbs.db)

find . -name "Thumbs.db" -exec rm {} \;

Move all files from subfolders to current folder
find . -type f -exec mv {} . \;

Iterate over files with a given extension

for file in `find . -name *.txt`; do
echo $file
done

Follow a growing log file

tail -f /var/log/messages

Multiple files could be listed like this, eg.
tail -f /var/log/messages /var/log/dmesg

Backup using tar (here everything in /etc)

tar -Pczf /mnt/backup/backup/etc.tar.gz /etc/*

Count number of words in LaTeX file

detex file.tex | wc -c

Find duplicate files

# Check sizes first and only checksum files of the same size
find . ! -empty -type f -printf "%s " -exec ls -dQ {} \; | \
sort -n | uniq -D -w 1 | \
cut -d" " -f2- | \
xargs md5sum | sort | \
uniq -w32 -d --all-repeated=separate | \
cut -c35-

Categories: bash Tags: ,