User Tools

Site Tools


quickreference:unix

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
quickreference:unix [2018/08/26 23:11]
rodolico
quickreference:unix [2019/01/29 01:18] (current)
rodolico
Line 21: Line 21:
 for dir in `ls`; do echo -n " $dir " ; find $dir/​Maildir/​cur -type f | wc -l ; done for dir in `ls`; do echo -n " $dir " ; find $dir/​Maildir/​cur -type f | wc -l ; done
 </​code>​ </​code>​
 +
 +==== create multiple zero filled files ====
 +
 +Sometimes, especially before doing a full disk backup using compression,​ it is good to write 0's to all unused disk space. This can be done quite easily with a simple dd command (assuming the current directory is on the partition you wish to do this to).
 +
 +<code bash>
 +dd if=/​dev/​zero of=./​deleteme
 +rm deleteme
 +</​code>​
 +
 +This will create a single file, deleteme, which contains nothing but 0's in it (and thus is very compressible),​ then deletes the file.
 +
 +However, I have found that I like to have several files which I can then leave on the disk in case I need to perform the copy in the future. I can leave myself plenty of disk space to do my work, and if I need more space, I simply delete some of the files I created. In this case, I'm assuming I have 49.5 gigabytes of free disk space, and I want to zero it all out, then free up 10G for running the system.
 +
 +<code bash>
 +for i in {01..50} ; do echo Loop $i ; dd if=/​dev/​zero of=./​deleteme.$i bs=1M count=1024 ; done
 +for i in {41..50} ; do rm deleteme.$i ; done
 +</​code>​
 +
 +This will create 50 1 gigabyte files in the current directory, each filled with zeros. Since I am trying to write 50 gigabytes but only have 49.5, the last write will fail since I have no more disk space to write to.
 +
 +I then delete the last 10 files I created, which gives my system some space to run in.
 +
 +==== break a file apart into pieces ====
 +
 +In many cases, you have to take a large file and break it into smaller pieces. In this case, use the Unix command //split// to do so. In the following example, I'm taking the 23 Gigabyte file and breaking it into 23 1 Gigabyte files, with numeric suffixes beginning with 07, then 08, all the way to 30.
 +
 +<code bash>
 +split --suffix-length=2 --bytes=1G --numeric-suffixes=07 --verbose deleteme deleteme.
 +</​code>​
 +
 +note that the original file (deleteme) is not modified, so you will need as much space as it occupies, plus a little for overhead.
 ===== ssh ===== ===== ssh =====
  
quickreference/unix.txt ยท Last modified: 2019/01/29 01:18 by rodolico