Linux

Copy files using tar

This is a oneliner to copy files from current directory to another target directory using tar, preserving file attributes, dates etc. #!/bin/sh fromdir=/path/from todir=/path/to/target echo “cd $fromdir; tar cf – . | (cd $todir; tar xpf -)” cd $fromdir; tar cf – . | (cd $todir; tar xpf -)

Read More
Misc

IP address change notifier script

This is a simple bash script that is run by crontab every 5 minutes on a linux box. It e-mails me the new address when a change of IP address is detected. The script (ipchangemail.sh) #!/bin/bash # Check if IP-address has changed. If a change has occured, mail me the new address # Add the […]

Read More
Linux

Share a bash session using screen

This is a short post on how you can “share” a bash session/prompt with other users. User A connects to the server and types in the command # screen User A hist the key combination <Ctrl + a> and the type :multiuser on User B connects to the same server as user A and can […]

Read More
Scripting

Oneliner to determine directory size

This is a simple oneliner to determine which user has used most diskspace in their /home directory du -sm $(find /home -type d -maxdepth 1 -xdev) | sort -g The result could look something like this … 215 /home/userT 1367 /home/userB 10865 /home/userL 25326 /home/userY 116328 /home/userH 154426 /home/ The numbers to the left is […]

Read More