I have a file, which contains the name of some files. I want to find the total size of files in the list.
#cat filelist
/tmp-directory/connector_db_ connector_db
/tmp-directory/connector_db -connector_db
/tmp-directory/connector_db_connector_db
As you can see the names of the file contains space, and more badly a hyphen (-). I am trying to find the total size of these files with below command.
#du -sch `cat filelist`
du: invalid option -- 'o'
du: invalid option -- 'n'
du: invalid option -- 'n'
du: invalid option -- 'e'
du: invalid option -- 't'
du: invalid option -- 'o'
du: invalid option -- 'r'
du: invalid option -- '_'
du: invalid maximum depth `b'
I tried adding " " as shown below and then tried which also failed
#cat filelist
"/tmp-directory/connector_db_ connector_db"
"/tmp-directory/connector_db -connector_db"
"/tmp-directory/connector_db_connector_db"
#du -sch `cat filelist`
du: invalid option -- 'o'
du: invalid option -- 'n'
.....
But this works when I use below command, directly in shell.
#du -sch "/tmp-directory/connector_db -connector_db"
0 /tmp-directory/connector_db -connector_db
0 total
So, how to handle such a situation. I have filelist of 3 lac files. More badly, "du -sch" is not handling the list when file list exceeds around 20000. I am splitting the list into 20000 lines with split command. Is there any alternate method for finding the size of 3 lac files easily?