Linux

Mount SMB Share

mount -t smbfs -o username=uname,password=passwd //smbserv/share /destination

Label fat32 vfat Filesystem

mlabel -i /dev/sdc1 ::FOOBAR

ACL

setfacl -m u:foo:r-- DEST
setfacl -x u:foo DEST
setfacl -m g:bar:r-- DEST
setfacl -x g:bar DEST
setfacl -m d:u:foo:r-- DIR
setfacl -m d:g:bar:r-- DIR
setfacl -m m:r-- DEST
setfacl -m d:m:r-- DIR

Archiving / Backup

Backup Remotehost with tar

ssh root@otherhost -c blowfish 'cd /YOURPATH; tar -f - -p -P -c --exclude=/YOURPATH/tmp --exclude=/YOURPATH/var/cache /' | dd of=/daten/backup.tar

Add redundancy to files

par2 create myparfiles foo*

Create a DVD image larger than 2GB

mkisofs -udf -allow-limited-size -o foo.img foo

Complete Compressed Partionbackup Into an Image

mount /dev/hda1 / -o remount,rw;
dd if=/dev/zero of=/delme1 bs=4048; rm /delme1;
mount /dev/hda1 / -o remount,ro;

Local

dd if=/dev/hda1 bs=4048 | bzip2 > /mountpoint/image_hda1.bz;

Remote


ssh host -c blowfish 'dd if=/dev/hda1 bs=4048 | bzip2' | dd of=/image_hda1.bz

Detect interactive shells

if shopt -q login_shell ; then
 ...
else
 ...
fi

Change output of a shellscript and restore output again later

exec 3>&1
exec 1>>/var/log/mylogfile.txt
...
exec 1>&3
exec 3>&-

Change file content without temporary files with sponge

Usually you have to use temporary files if you want to change the content of a file, as you can not read and write to a file simultaneously. This can be very inconvenient, especially as secure creation of temp files is not too easy. One solution for this problem is sponge:

cat foo.txt | sed s/t/T/ | sponge foo.txt

However, this does only work if sponge writes to a file. If you redirect its output this will not work. In Debian sponge can be found in the moreutils package.

System Infos

# free -m
# df -ah
# top -n1
htop
# vmstat 5 3
smartctl --all /dev/sda
memstat -w

Who blocks a mounted drive

If you can not unmount a mounted drive find out who blocks it

lsof +D /mnt/foo
fuser /mnt/foo

Benchmarks

Use zcav to measure the speed of a mass storage device depending on the position on the drive you are currently reading from

zcav /dev/sdb > zcav.txt
gnuplot
 set yrange [0:*]
 set format y '%g Blocks/s'
 set format x '%g MB'
 plot "zcav.txt" using 1:2 title "Foo"

Benchmark a drive with bonnie++

bonnie++ -u root -d /mnt/mnt/

Networks

Show which settings the networkmanager is using, for example show DNS server that is being used

nmcli dev show