Archive for the ‘File Manipulation’ Category
Transferring files with netcat {nc}
Why? If you ever are in the situation of being stuck behind a firewall or VPN connection and want to transfer a file from the machine inside the VPN or firewalled back to your local desktop.
On the server we’re going to pipe the output of file through cat and set netcat to listen on port 4009
# cat file-i-want-to-send.ext | nc -l 4009
On my desktop im going to open a nc session to port 4009 and redirect the output to a local file.
# nc server.ip.address 4009 > file-i-want-to-recieve.ext
And viola! you can verify the file is intact by doing a md5sum on the server and compare it to the one locally
On Server
# md5sum file-i-want-to-send.ext
# e4ef527eac8f5afe26d8464a963694ad file-i-want-to-send.ext
On Client
# md5sum file-i-want-to-recieve.ext
# e4ef527eac8f5afe26d8464a963694ad file-i-want-to-recieve.ext
Data recovery the quick and easy way with ubuntu desktop linux 9.04
Ever had a failing disk? Using some hard drive recovery tools we can make salvaging our valueble data something possible.
Using dd_rescue we are going to make an image of the hard drive onto a reliable storage area, then we can run whatever filesystem recovery utilities we want.
The beauty of ddrescue is that it is fully automated and will rescue all the blocks that it can read successfully on the first pass, and with any bad blocks it will come back and retry as much as possible.
Install ddrescue tools
sudo apt-get install ddrescue
Connect the failed disk to your system
By either plugging the drive directly into system, or using one of those usb enclosure or slotted drive device you’ll need to have your failing hard disk connected and unmounted before we can begin.
sudo dd_rescue /dev/sdb disk-image.img
mnk0@earth:~$ sudo dd_rescue /dev/sdb disk-image.img
[sudo] password for mnk0:
Summary for /dev/sdb -> disk-image.img:r: 0.0k, succxfer: 228352.0k
dd_rescue: (info): ipos: 229376.0k, opos: 229376.0k, xferd: 229376.0k
errs: 0, errxfer: 0.0k, succxfer: 229376.0k
+curr.rate: 26249kB/s, avg.rate: 28391kB/s, avg.load: 13.5%
We can now mount this image on our system and take a look at the files.
mount -t ext3 -o loop disk-image.img /mnt/tmp
Using a swapfile to increase the swap space on your system
This can be a very handy function if we want to use a file, instead of a partition, and with modern filesystems the performance is almost on par with using a dedicated partition for your swap area.
1. Using dd lets make a zero’d file for the swap
dd if=/dev/zero of=/swapfile bs=1048576 count=1000
This example would create a swapfile of 1 gig using a blocksize of a megabyte (1048576).
2. Make file as a swapfile
mkswp /swapfile
3. Activate swapfile
swapon /swapfile
4. Verify that our swapfile has been activated
swapon -s
We should see something like this in the list ..
Filename Type Size Used Priority
/swapfile file 9999992 0 -2
If you want to have this a permanent solution, then adding the entry to fstab would probally be a better idea,
open up /etc/fstab in your favourite editor and add the following line.
/swapfile swap swap defaults 0 0