Posts

Block devices and block sizes

Block Device:    A  block device  is a device you can read blocks from. For example hard disks, cdrom drives and floppies are block devices, but not the keyboard. You can receive data from the keyboard and regard them as blocks, but you cannot seek on the keyboard. You can tell a hard disk "give me block 5433", then block 7707, then block 1807 and you cannot do this with a keyboard, so, a keyboard is no block device. Block Sizes: Disk block sizes Typically, a hard disk cannot read less than 512 bytes, if you want to read less, read 512 bytes and discard the rest. This is why dd reads one block à 512 bytes in the following example: dd if=/dev/sda1 of=/dev/null count=1 1+0 records in 1+0 records out 512 bytes (512 B) copied, 1.8977e-05 s, 27.0 MB/s   File System block sizes Every file system needs to split up a partition into bloc...

Stat Utility

The stat utility allows you to see all information about either a file or a directory.  You can use wildcards if you want to see info for more than one object at a time. stat process.sh File: `process.sh' Size: 158           Blocks: 16         IO Block: 4096   regular file Device: 305h/773d    Inode: 98134       Links: 1 Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root) Access: 2010-08-18 11:16:37.000000000 -0600 Modify: 2010-08-16 09:44:57.000000000 -0600 Change: 2010-08-16 09:44:57.000000000 -0600 Most of this should be self-explanatory, but a few items bear explaining. * Blocks–Each file occupies a certain number of filesystem blocks on the hard drive.  Here, we see that this file occupies eight blocks. * IO Block–This i...

Inode

Inode Table: All files in linux are having an inode number which is residing inside the inode table of a partition. For every partition there is an inode table, so an inode number will be unique for a partition, and thats the reason why we cannot hardlink between two partitions. Inode number contains a file's uid, gid, access time, modification time, change time and size of the file. inode number DOESNT hold a file's NAME. we can retrieve the contents of a file even if the file is deleted unless and until the inode number corresponding to that file is overwritten. The inode number can be viewed with the -i switch with the 'ls' command..! $ls -i filename Script to determine where the inode usage was most : for i in `ls -1A`; do echo “`find $i | sort -u | wc -l` $i”; done | sort -rn | head -5 With this you can Track it down to a directory then execute this command : find ./ -type f -mtime +10 | wc -l or  find ./ -type f -mtime +10 | xargs rm ...

Ulimit

A single user who starts too many processes can make a system unusable for everyone else. A fork bomb -- a denial of service attack in which a process continually replicates itself until available resources are depleted -- is a worst case of this.  To see the limits associate with your login, use the command ulimit -a. If you're using a regular user account, you will likely see something like this: $ ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 32767 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes ...

XARGS

xargs: Execute a command, passing constructed argument list(s). The arguments are typically a long list of filenames (generated by ls or find) that are passed to xargs via a pipe. Syntax       xargs [ options ] [ command ] Options    -0    --null             Expect filenames to be terminated by NULL instead of whitespace.             Do not treat quotes or backslashes specially.    -e[ string ]    -E[ string ]    --eof[= string ]             Set EOF to _ or, if specified, to string.    --help             Print a summary of the options to xargs and then exit.    -i[ string ]    -I[ string ]    --replace[= strin...