Hot answers tagged

110

blockdev --getsize64 /dev/sda returns size in bytes. blockdev --getsize /dev/sda returns size in sectors.


47

find ./photos/john_doe -type f -name '*.jpg' -exec du -ch {} + | grep total$ If more than one invocation of du is required because the file list is very long, multiple totals will be reported and need to be summed.


43

fdisk doesn't understand the partition layout used by my Mac running Linux, nor any other non-PC partition format. (Yes, there's mac-fdisk for old Mac partition tables, and gdisk for newer GPT partition table, but those aren't the only other partition layouts out there.) Since the kernel already scanned the partition layouts when the block device came into ...


27

This is the size of space on the disk that is used to store the meta information for the directory (i.e. the table of files that belong to this directory). If it is i.e. 1024 this means that 1024 bytes on the disk are used (it always allocate full blocks) for this purpose.


26

Depending on your platform, ttylinux is maybe something for you: This smallest ttylinux system has an 8 MB file system and runs on i486 computers within 28 MB of RAM, but provides a complete command line environment and is ready for Internet access. Started in 2001 and latest release is from 2015-03-05 so it is still maintained.


18

It seems that you have a lot more files than normal expectation. I don't know whether there is a solution to change the inode table size dynamically. I'm afraid that you need to back-up your data, and create new filesystem, and restore your data. To create new filesystem with such a huge inode table, you need to use '-N' option of mke2fs(8). I'd ...


13

du -ch public_html/images/*.jpg | grep total 20M total gives me the total usage of my .jpg files in this directory. To deal with multiple directories you'd probably have to combine this with find somehow. You might find du command examples useful (it also includes find)


12

You can use the unzip utility with the -v flag: unzip -v files.zip Archive: files.zip Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 0 Stored 0 0% 11-23-2011 15:02 00000000 file1 0 Stored 0 0% 11-23-2011 15:02 00000000 file2 -------- ...


11

A directory reserves 4096 bytes (at minimum) for meta-data about itself and its contents. Also, 4096 bytes is the default allocation unit (block) for ext2/ext3/ext4 filesystem and therefor a directory cannot be any smaller. On different filesystems you might find directories with different default sizes, that is due to the default block size of the ...


11

If you are scripting downloads, you should consider using curl instead. Wget can parse output and recursively fetch whole sites, but curl has way more options relating to the actual download of a specific file. Here is the relevant option in the man page: --max-filesize Specify the maximum size (in bytes) of a file to download. If the file ...


11

The dot file, like every directory, contains a list of names for the files in this directory and their inode numbers. So if you once had lots of files in that directory (not unlikely for a "tmp" directory) that would have made the directory entry grow to this size. After the files are gone, the file system doesn't automatically shrink the directory file ...


10

If your program doesn't need to write any OTHER files that would be larger than this limit, you can inform the kernel of this limit using ulimit. Before you run your command, run this to setup a 200MB file size limit for all process run in your current shell session: ulimit -f $((200*1024)) This will protect your system but it might be jaring for the ...


10

This does the whole job in one go - in all child directories, all in a single stream without any filename problems. It'll copy from smallest to largest every file you have. You will need to mkdir ${DESTINATION} if it doesn't already exist. find . ! -type d -print0 | du -b0 --files0-from=/dev/stdin | sort -zk1,1n | sed -zn 's/^[^0-9]*[0-9]*[^.]*//p' | tar --...


9

How about: fdisk -l This will give you a list of all your disks with their respective capacity, usage, and more.


8

If your application (ie. run_program) does not support limiting the size of the log file, then you can check the file size periodically in a loop with an external application or script. You can also use logrotate(8) to rotate your logs, it has size parameter which you can use for your purpose: With this, the log file is rotated when the specified size ...


8

Using sgdisk You can use sgdisk to print detailled information: sgdisk --print <device> […] Disk /dev/sdb: 15691776 sectors, 7.5 GiB Logical sector size: 512 bytes […] When you multiply the number of sectors with the sector size you get the exact byte count that should match the output of dd. Using /sys directly You can also get those numbers ...


8

Here is a quick and dirty method using rsync. For this example I am considering anything under 10 MB to be "small". First transfer just the small files: rsync -a --max-size=10m srcdir dstdir Then transfer the remaining files. The previously transferred small files will not be re-copied unless they were modified. rsync -a srcdir dstdir From man 1 rsync ...


8

You can just do the whole thing with (GNU) find and sort, no need for du: $ find . -iname '*png' -printf '%s %p\n' | sort -rn 68109 ./7.png 21751 ./2.png 21751 ./1.png 5393 ./6.png 2542 ./5.png 1717 ./4.png 1003 ./3.png 878 ./10.png 793 ./9.png 587 ./8.png


7

Create an extended partition spanning the new free space, and create a logical partition inside it. (You could create a primary partition, but that would reduce your options later, because of the limit of 4 primary partitions or 3 primary and one extended.) You can do this with fdisk or cfdisk or parted. Set the type of the new partition to 8e (“Linux LVM”). ...


7

Virtualbox images can be resized from outside Virtualbox. Run this command on the VDI: VBoxManage modifyhd SLACK.vdi --resize 100000 That last number is the size in MiB.


7

Primarily, you need two things: the -c option to du, to tell it to produce a grand total; either find or ** to traverse subdirectories. du -ch -- **/*.jpg | tail -n 1


7

You need to use logrotate. Do something like this cat /etc/logrotate.conf /path/foo.txt { size 50M create 700 root root rotate 5 } size 50M – logrotate runs only if the filesize is equal to (or greater than) this size. create – rotate the original file and create the new file with specified permission, user and group. rotate – limits ...


6

You can truncate the output with head: size=$((200*1024*1024-$(stat -c %s myprogram.log))) run_program | head -c ${size} >> myprogram.log


6

The -a in an explicit AND operator that allows you to conjoin two primaries. In this case creating a range using -size. find . -size +386b -a -size -390b -exec rm -f {} \; Note the size is a numeric argument that can optionally be prepended with + and -. From man 1 find: Numeric arguments can be specified as +n for greater than n, -n ...


6

find . -size -1M will only show file of size less than 1M, that is 0M. Yes, I know, it's confusing. find . -size 1M will show you files whose size (rounded up to the upper MiB) is 1M (so any file size from 1 to 1048576). If you want from 0 to 1048575 (< 1M), that would be: find . -size -1048576c If you want from 0 to 1048576 (<= 1M) find . -size -...


6

blockdev --getsize /dev/sda


6

If you specifically want the size of the files that are present under hourly.2 but not under hourly.1, you can obtain it a little indirectly with du. If du processes the same file more than once (even under different names, i.e. hard links), it only counts the file the first time. So what du hourly.1 hourly.2 reports for hourly.2 is the size you're looking ...


6

find ... -exec cmd {} + will execute cmd as many times as necessary so as not to break the limit of the size of the arguments passed to a command. When using find . -exec du {} +, the size of the file list is smaller than when using find verylongdirname -exec du {} +. So it's likely the find verylongdirname will run more du commands than the find . one. ...



Only top voted, non community-wiki answers of a minimum length are eligible