I am trying to get the total size of a folder?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers I am trying to get the total size of a folder?
# 1  
Old 08-08-2010
I am trying to get the total size of a folder?

I am trying to get the total size of the folder using the below command

but its not working. any ideas?


Code:
du -bc <foldername>/|grep total|tr -s " "|cut -d" " -f1

the output i am getting is

78996 total

but i just want it to be as

78996

please help

Last edited by DukeNuke2; 08-08-2010 at 06:00 PM..
# 2  
Old 08-08-2010
One way:

Code:
du -bc directory  | awk ' /total/ { print $1 }'

Your command may be failing as the du command might be separating the total token from the value with tabs rather than spaces.
# 3  
Old 08-08-2010
Quote:
Originally Posted by classic
I am trying to get the total size of the folder using the below command

but its not working. any ideas?


Code:
du -bc <foldername>/|grep total|tr -s " "|cut -d" " -f1

the output i am getting is

78996 total

but i just want it to be as

78996

please help
This should work
Code:
 du -bc <folder_name>| grep total | cut -f1

I think the problem with ur code was tr -s " " where u r squeezing space but actually its a tab. so tr is not making any difference. In my code, since tab is the default delimiter for cut, it works.
# 4  
Old 08-08-2010
Code:
du -bc /tmp | tail -1|cut -f1

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Counting total files with different file types in each folder

Trying to count total files with different file types with thousands of files in each folder. Since some files do not have extensions I have to use below criteria. Count Total Files starting with --> "^ERROR" Count Total Files starting with --> "^Runtime" Count Everything else or files... (3 Replies)
Discussion started by: kchinnam
3 Replies

2. Shell Programming and Scripting

Total number of files in the folder should be listed

Hi All, When i give the ls -lrt to list out all files with total number of files , i get the output as ls -lrt total 72 -rw-r--r-- 1 hari staff 796 Jul 11 09:17 va.txt -rw-r--r-- 1 hari staff 169 Jul 13 00:20 a.log -rwxr-xr-x 1 hari staff 659 Aug... (9 Replies)
Discussion started by: Kalaihari
9 Replies

3. Solaris

Need command to know the total size

:mad:i need command to know the total size of project in my system by Giga bit i try #du -s /*/projectname but i need total size for this project by G.B can you help me (6 Replies)
Discussion started by: ayman
6 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Touch 10% of the total files inside a folder

I'm trying to make this code below to work but I can't find the way to do the following: I want to make the script to touch only 10% of the total amount of files counted inside the given directory instead of all like it is now. I would greatly appreciate it if someone can give me a direction on... (9 Replies)
Discussion started by: regraphix
9 Replies

5. UNIX for Dummies Questions & Answers

get total size of files

as we use du - sh *.frm In This command It will show the list of files and size But I want the Total size that these files in directory with extension .frm How can we do This (6 Replies)
Discussion started by: kaushik02018
6 Replies

6. Shell Programming and Scripting

total size

I have a directory that contains files like aaa-2010-05-30.txt ddd-2010-05-30.txt www-2010-05-30.txt i have total 2000 files, i need to calculate total size of files for *2010-05-30.txt like aaa-2010-05-30.txt 200MB ddd-2010-05-30.txt 10GB www-2010-05-30.txt 4GB Total 14.2 GB... (5 Replies)
Discussion started by: learnbash
5 Replies

7. Shell Programming and Scripting

check how many files in folder or total files in folder

Hi all, I have copied all my files to one folder.and i want to check how many files (count) in the folder recently moved or total files in my folder? please send me the query asap. (3 Replies)
Discussion started by: durgaprasad
3 Replies

8. UNIX for Dummies Questions & Answers

Find total size for some files?

Hi, I'm newbie to Unix. I'd like to count the total size of those files in my directory by date. For example, files on this period 05/01/08 - 05/31/08. If possible can we count by byte instead of kb. if I use $ du - ks , it will add up all files in the dir. thanks, Helen (5 Replies)
Discussion started by: helen008
5 Replies

9. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

10. HP-UX

total size taken by directory

HI ALL, i am a beginner in unix world. can anyone please tell me the way to find total size taken by each directory (including size of all subdirectories and files) present under /var. e.g what is space occupied by /var/adm , /var/admin etc. its a simple question but still i dont know the... (2 Replies)
Discussion started by: jyoti
2 Replies
Login or Register to Ask a Question