hadoop hdfs directory size shown as 0
It is working as designed. Hadoop is designed for big files and one should not expect it to give the size of each and every time one run hadoop fs -ls
command. If Hadoop works in way you want then try to think from another person point of view who might just want to see whether directory exists or not; but end up waiting long time just because Hadoop is calculating size of folder; not so good.
Ruby File.size for directory returns 0
Directories are files. Well, I suppose in some operating systems they aren't, but in all Unix-based ones they are.
Of course, in Unix systems, directories in "regular" file systems (i.e., ones that have real files, not /proc
or the like) have non-zero size too.
File.size('/etc')
=> 12288
Why directory copied with cp command has less size than the original one
This can have a number of reasons because you are asking for the used disk size, not for the amount of bytes stored in both trees.
- In a file system files are stored with a specific amount of overhead. This overhead depends on the file system. Maybe the two storages are using different file systems which are not equally efficient (use different block sizes for example which might be due to different disk sizes).
- Another reason might be hardlinked files in the original. The copy might have copied the hardlinked files several times so that in the copy they aren't hardlinked anymore.
- A third reason might be sparse files which contain large areas of zero-bytes which in some file systems can be efficiently stored by assigning them no blocks.
To rule out at least the first reason (the most likely one), I propose to use du -bs
on both trees.
My ArrayList size becomes zero(0) after calling function. where is my error?
You have created the 3 lists, I can see as mentioned below:
- searchItem
- filteredMediaList
- mediaList
So once you call the method "load_Directory_Files_Search", it is filling up the list searchItem and memory is allocated.
Now the code:
mediaList = Constant.searchItem;
over here the same memory allocated to searchItem is referred by mediaList. That being said it means no new memory is created for mediaList. So any changes made to mediaList will affect searchItem as well.
After that, in below mentioned line of code:
Constant.filteredMediaList = mediaList;
filterMediaList refers to the list which is being pointed by mediaList.
So, now all the 3 lists that you have created searchItem, mediaList and filteredMediaList all are pointing to same memory. So changes made in any of the list will change all the 3 lists.
Since you have mentioned below mentioned line in filter() method:
Constant.filteredMediaList.clear();
it clears all the 3 lists, and that's the reason you are getting your list cleared out.
If you don't want other list to get effected while making changes to any other, below is the way to do so
I am writing the code for onCreate method below:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
editTextSearch = findViewById(R.id.editTextSearch);
recyclerViewSearch = findViewById(R.id.recyclerViewSearch);
allPath = new StoragePath(getExternalFilesDirs(null)).getDeviceStorages();
for(String path:allPath){
Log.d("allPath",path);
File directory=new File(path);
Method.load_Directory_Files_Search(directory);
}
mediaList = new ArrayList<>(searchItem);
Constant.filteredMediaList = new ArrayList<>(searchItem);
Log.d("SearchAllSize",String.valueOf(Constant.searchItem.size())+" | "+
String.valueOf(Constant.filteredMediaList.size())+" | "+
String.valueOf(mediaList.size()));
//initializing everything above
recyclerViewSearch.setLayoutManager(new LinearLayoutManager(this,RecyclerView.VERTICAL,false));
recyclerViewAdapterSearch = new RecyclerViewAdapterSearch(this);
recyclerViewSearch.setAdapter(recyclerViewAdapterSearch);
Log.d("SearchAllSize",String.valueOf(Constant.searchItem.size())+" | "+
String.valueOf(Constant.filteredMediaList.size())+" | "+
String.valueOf(mediaList.size()));
//working fine till now
editTextSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
String text = editable.toString();
filter(text);
}
});
I hope this solution helps you.
why the size of File.length() in java is not same with that of linux du command
On Linux / Unix systems, there is a concept of a "block size". This block size is the minimum amount of space the OS can hand a file. du reports the block size, rather than the exact file size. This is how much space the file is taking up on the OS, not the size of the file.
The du utility displays the file system block usage...
For clarification, let's say my block size = 4 KB (which is fairly common.) If I create a text file that is 2 KB, then the size of the file is 2 KB, but the amount of space the file takes up on the system is 4 KB because that is the minimum amount the OS can hand out.
Similarly, if I made a file that was 11 KB, then the file size is 11 KB, but it actually takes up 12 KB. This is because we need 3 blocks to be able to hold the file.
:Edit: stat -f will show you the block size on a drive in bytes. For example,
stat -f /dev/sda1
...
File: "/dev/sda1"
Block size: 4096
...
Then you can pair that with ls -ls to give a directory listing that includes the number of blocks a file uses. The blocks are the left-most column.
ls -ls
1 -rw-r--r--. 1 brasmussen someGroup 0 Jan 29 16:24 f1
You can see here that even thought file "f1" has a size of 0 bytes, it still takes up one block. Therefore, its OS size is 4KB, and its file size is 0KB.
Linux delete file with size 0
This will delete all the files in a directory (and below) that are size zero.
find /tmp -size 0 -print -delete
If you just want a particular file;
if [ ! -s /tmp/foo ] ; then
rm /tmp/foo
fi
Related Topics
Specify CPU Frequency as a Kernel Cmd_Line Parameter of Linux on Boot
Setuid on an Executable Doesn't Seem to Work
Why Can't I Install Any Packages with Ghc 7.8.4 on Raspberry Pi
Inotify Fd - Why Is The Limit Per User Id and Not Per Process
How to I Detect Whether a Tty Belonging to a Gsm/3G-Modem Is a Data or Control Port
Git Error: Cannot Handle Https
Count Number of Column in a Pipe Delimited File
Awk: Find and Replace in Certain Field Only
Convert Object File to Another Architecture
Svn Keeps Prompting Me for Passwords and Refuses to Cache My Credentials
How The File Size Is Limited on a Specific File System
How to Use Opengl Without a Window Manager in Linux
Shared Library Symbol Conflicts and Static Linking (On Linux)