Delete empty files and folders
Code:
#!/bin/bash |
Atleast maybe someone can tell which command shows only file names and date when they were created because i can't find.
|
I don't thing the filesystem contains such information. You can, however, get last access or modification time with stat
|
First of all, don't use a for loop to read the output of a command. The shell does word-splitting on it before the loop gets to use it.
http://mywiki.wooledge.org/DontReadLinesWithFor http://mywiki.wooledge.org/BashFAQ/001 A while+read loop with null-separators is the recommended way, as detailed in the second link. Also, $(..) is highly recommended over `..`. And as long as you're using bash, the new [[ test keyword is also recommended over the old [ test. http://mywiki.wooledge.org/BashFAQ/031 As for getting details about a file, try using the stat command. Other than that, it looks like a pretty good start. |
Assuming some ext filesystem
Quote:
|
Quote:
Code:
find "$dir" -maxdepth 1 -mindepth 1 -empty 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". |
Thank you but now I just need command which shows date when folder or file was created because I can't find it.
|
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. |
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. |
Thank you for the help.
|
All times are GMT -5. The time now is 07:37 PM. |