Sponsored Content
Top Forums Shell Programming and Scripting How to traverse directory structure and sum size of files? Post 302432442 by zaxxon on Friday 25th of June 2010 05:15:06 AM
Old 06-25-2010
Half a million files can take their time. Add a -print in front of your -exec to see if it's stuck.

---------- Post updated at 11:15 AM ---------- Previous update was at 09:54 AM ----------

You should also use the -mtime option instead of -atime since -atime timestamp will be updated even if you had just a reading action on the file. -mtime resembles to the date you see when you do a ls -l.
To express a "starting" and "ending" time you can also combine 2 -mtime like:
Code:
find . -mtime -730 -mtime +365 -print -exec rm '{}' \;

which should delete all files older than 1 year but not older than 2 years ie. the year before the last year.
When experimenting with this, leave out the -exec rm so you do not accidentally delete things if something is not according to your needs.

Last edited by zaxxon; 06-25-2010 at 06:15 AM.. Reason: added info
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

MV files from one directory structure(multiple level) to other directory structure

Hi, I am trying to write a script that will move all the files from source directory structure(multiple levels might exist) to destination directory structure. If a sub folder is source doesnot exist in destination then I have to skip and goto next level. I also need to delete the files in... (4 Replies)
Discussion started by: srmadab
4 Replies

2. UNIX for Dummies Questions & Answers

copy files with directory structure

i have a text file as. /database/sp/NTR_Update_Imsi_List.sql /database/sp/NTR_Update_Imsi_Range_List.sql /database/sp/NTR_Vlr_Upload.sql /database/tables/StatsTables.sql /mib/ntr.mib /mib/ntr.v2.mib /scripts/operations/ntr/IMSITracer.ph /scripts/operations/ntr/IMSITracer.pl ... (3 Replies)
Discussion started by: adddy
3 Replies

3. Shell Programming and Scripting

find size, cp breaks directory structure

I'm using this now: find /some/path/with/sourcefiles -type f -size -7M -exec /bin/cp -uv {} /some/path/ \; but it doesn't preserve the directory structure, also I've tried it with find /some/path/with/sourcefiles -type f -size -7M -exec /usr/bin/rsync -auv {} /some/path/ \; but that doesn't... (9 Replies)
Discussion started by: unclecameron
9 Replies

4. Shell Programming and Scripting

Sum up files whose size Kbytes and Mbytes

Hello Friends, When i type du -sh *.jar | sort -n under a library directory i get a result similar below output: 1M 1.jar 2.4M 2.jar 4.5M 3.jar . . . . . . 1K (n-2).jar 15K (n-1).jar 77.7K n.jar I want to sum up the size... (1 Reply)
Discussion started by: EAGL€
1 Replies

5. Shell Programming and Scripting

Sum of file size in directory / subdirectory

Hi , I am trying to write something to find the size of particular type of files in a directory & it's subdirectory and sum the size .. These types of file are found at directory level or its subdirectories level .. #!/bin/ksh FNAME='.pdf' S_PATH=/abc/def/xyz find $S_PATH -exec ls -lad... (4 Replies)
Discussion started by: Vaddadi
4 Replies

6. Shell Programming and Scripting

Traverse file structure from top and rename the immediate parent

Hello All, I am trying to write a script to:- 1. Traverse entire file system, look for directories which has .git directory in it 2. Rename the immediate parent directory to <orignal_name.git> 3. Traverse new file structure and look for all directories with <original_name>.git 4. cd to... (2 Replies)
Discussion started by: sahil_jammu
2 Replies

7. UNIX for Dummies Questions & Answers

How to get the set of files size as a sum in a directory.

Hi, Can someone help me to get the complete files size (sum) over a perod time (1 day,2days)in a directory. eg: Directory :ABC I have a1,a2,a3 files are created in last 24 hours so I need to get the some of all these files. I am using the below find command but its giving me the... (1 Reply)
Discussion started by: gaddamja
1 Replies

8. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

9. Shell Programming and Scripting

Archiving files keeping the same structure directory

Hello Team, We would like to backup a lot of files inside of a structure of directories, four, five or more levels in some Ubuntu, Mac and Solaris systems. For instance: /home/chuck/sales/virgin/rent-quote.pdf /home/chuck/sales/marriott/vacation-quote.pdf... (2 Replies)
Discussion started by: csierra
2 Replies
SYSLOGOUT(8)						      System Manager's Manual						      SYSLOGOUT(8)

NAME
syslogout - modular centralized shell logout mechanism DESCRIPTION
syslogout is a generic approach to enable centralized shell logout actions for all users of a given system in a modular and centralized way mostly aimed at avoiding work for lazy sysadmins. It has only been tested to work with the bash shell. It basically consists of the small /etc/syslogout shell script which invokes other small shell scripts having a .bash suffix which are con- tained in the /etc/syslogout.d/ directory. The system administrator can drop in any script he wants without any naming convention other than that the scripts need to have a .bash suffix to enable automagic sourcing by the /etc/syslogout script. For shell sessions, the contents of /etc/syslogout.d/" will be sourced by every user at logout if the following lines are present in his $HOME/.bash_logout: if [ -f /etc/syslogout ]; then . /etc/syslogout fi If used for X sessions it is advisable to include the former statement into the Xreset script of the X display manager instead to prevent that closing of an terminal emulator window yields unexpected results in your running X session if your X11 terminal emulator is using a login shell. Be sure then to run it under the user-id of the X session's user. See the example files in /usr/share/doc/syslogout/ for illustration. Users not wanting /etc/syslogout to be sourced for their environment can easily disable it's automatic mechanism. It can be disabled by simply creating an empty file called $HOME/.nosyslogout in the user's home directory using e.g. the touch(1) command. Any single configuration file in /etc/syslogout.d/ can simply be overridden by any user by creating a private $HOME/.syslogout.d/ directory which may contain a user's own version of any configuration file to be sourced instead of the system default. It's names have just to match exactly the system's default /etc/syslogout.d/ configuration files. Empty versions of these files contained in the $HOME/.syslo- gout.d/ directory automatically disable sourcing of the system wide version. Naturally, users can add and include their own private scripts to be automagically executed by /etc/syslogout at logout time. OPTIONS
There are no options other than those dictated by shell conventions. Anything is defined within the configuration scripts themselves. SEE ALSO
The README files and configuration examples contained in /usr/share/doc/syslogout/ and the manual page for bash(1), xdm(1x), xdm.options(5), and wdm(1x). Recommended further reading is everything related with shell programming. If you need a similar mechanism for executing code at login time check out the related package sysprofile(8) which is a very close compan- ion to syslogout. BUGS
syslogout in its current form is mainly restricted to bash(1) syntax. In fact it is actually a rather embarrassing quick and dirty hack than anything else - but it works. It serves the practical need to enable a centralized bash configuration until something better becomes available. Your constructive criticism in making this into something better" is very welcome. Before i forget to mention it: we take patches... ;-) AUTHOR
syslogout was developed by Paul Seelig <pseelig@debian.org> specifically for the Debian GNU/Linux system. Feel free to port it to and use it anywhere else under the conditions of either the GNU public license or the BSD license or both. Better yet, please help to make it into something more worthwhile than it currently is. SYSLOGOUT(8)
All times are GMT -4. The time now is 03:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy