Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-14-2011, 08:16 AM
|
#1
|
|
Member
Registered: Sep 2011
Posts: 82
Rep: 
|
Delete empty files and folders
Code:
#!/bin/bash
echo 'Folder name'
read f
if [ -d "$f" ]
then
cd "$f"
for i in `find -maxdepth 1 -mindepth 1 -empty`
do
Hello. I am creating script which deletes empty files and folders within directory and shows filename and date when file was created. I want to ask if I am starting to do it in good way and how to make script to show file names and dates when files was created?
|
|
|
|
10-14-2011, 09:57 AM
|
#2
|
|
Member
Registered: Sep 2011
Posts: 82
Original Poster
Rep: 
|
Atleast maybe someone can tell which command shows only file names and date when they were created because i can't find.
Last edited by trintukaz; 10-14-2011 at 09:58 AM.
|
|
|
|
10-14-2011, 10:05 AM
|
#3
|
|
Member
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 618
|
I don't thing the filesystem contains such information. You can, however, get last access or modification time with stat
|
|
|
|
10-14-2011, 10:18 AM
|
#5
|
|
Senior Member
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794
Rep: 
|
Assuming some ext filesystem
Quote:
|
Ext4 also adds support for date-created timestamps. But, as Theodore Ts'o points out, while it is easy to add an extra creation-date field in the inode (thus technically enabling support for date-created timestamps in ext4), it is more difficult to modify or add the necessary system calls, like stat() (which would probably require a new version), and the various libraries that depend on them (like glibc). These changes would require coordination of many projects. So, even if ext4 developers implement initial support for creation-date timestamps, this feature will not be available to user programs for now.
|
|
|
|
|
10-14-2011, 10:21 AM
|
#6
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Quote:
then
cd "$f"
for i in `find -maxdepth 1 -mindepth 1 -empty`
do
|
You could use
Code:
find "$dir" -maxdepth 1 -mindepth 1 -empty
to list empty files and directories in $dir/.
You can have more than one directory. If you want to find all empty files, why cd into directories and use -maxdepth?
You can use "-type f" to list just files.
Also look in the find info manual at the section for "-printf". This allows you to print out a number of characteristics of a file, in the format you want. Look at -ls, which prints results in a form similar to "ls -l".
|
|
|
|
10-14-2011, 10:39 AM
|
#7
|
|
Member
Registered: Sep 2011
Posts: 82
Original Poster
Rep: 
|
Thank you but now I just need command which shows date when folder or file was created because I can't find it.
|
|
|
|
10-14-2011, 10:57 AM
|
#8
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Run the stat command on a file. Is there a date listed for the birth?
If not, it may not be recorded. If it exists, you can use stat with the '%w' option to provide the date a file was created. While the stat command provides the birth of a file, if the kernel doesn't record it when a file is created, you won't get a value.
Last edited by jschiwal; 10-14-2011 at 11:17 AM.
|
|
|
|
10-14-2011, 11:15 AM
|
#9
|
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,568
|
As was mentioned above, there is no creation date for most files. Unix has traditionally had only three file date fields: atime (time of last access), mtime (time of last modification, and ctime (time the inode was last updated).
Proud's post shows how a true creation time field has recently been added to the ext4 file system, but also that the system tools that would use it have yet to be updated to support it (stat seems to be one that has).
So you'll likely never find a file that has a recorded crtime. It's too new.
Therefore, the closest you'll come to a "creation" date for most files is the mtime, the last time the file contents changed.
|
|
|
|
10-14-2011, 11:16 AM
|
#10
|
|
Member
Registered: Sep 2011
Posts: 82
Original Poster
Rep: 
|
Thank you for the help.
Last edited by trintukaz; 10-14-2011 at 11:27 AM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:22 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|