Need to store information relating to certain files


 
Thread Tools Search this Thread
Operating Systems Linux Need to store information relating to certain files
# 1  
Old 05-07-2008
Need to store information relating to certain files

I need to save information relating to certain files that are projected to deleted.

I am using
Code:
find $defPath/archive/sub/subchild -type f -mtime +365 > LOGFILE 
cat LOGFILE| 
while read line
do
ls -l $line | cut -d" " -f 10-15
done

But, since cut is cutting columns on space (single space is like a field) the out put fields are irregular.

I want to retrieve information of a file like,
  1. The file size,
  2. Date of created/modified
  3. File name.

Is there any way that I can get these vital details other than using cut command?

Please suggest.

R.
# 2  
Old 05-07-2008
Sure Smilie Try with awk:

Code:
find $defPath/archive/sub/subchild -type f -mtime +365 -exec ls -l {} \; | \
awk '{ for (i=5;i<=NF;i++) printf("%s%s", $i, i==NF?"\n":" ") }'

This implies that the fields you require are:

$5 = Size
$6, $7, $8 = Date (the output may depend on the international settings)
All the remaining = File name
# 3  
Old 05-08-2008
Thank you a lot.

Quote:
(the output may depend on the international settings)
Not sure about them, but it worked in my case.

A very BIG thank you Smilie

R
# 4  
Old 05-08-2008
Oh, well, ignore that Smilie

Depending on the LANG variable, the output may vary but it doesn't change the behaviour of the script (also if the date format eventually comprises more than three fields) because it prints all the fields, starting from 5th.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Store output in variables instead of files

Hi All, I have written a (bash) function which generates multiple files say file1 file2 file3 now I want to reduce the generation of these three files i.e. store the output of three files in variables, and generate the same results, in-order to avoid multiple creation of files how is that... (7 Replies)
Discussion started by: sam@sam
7 Replies

2. Shell Programming and Scripting

search information in multiple files and save in new files

hi everyone, im stuck in here with shell :) can you help me?? i have a directory with alot files (genbank files ... all ended in .gbk ) more than 1000 for sure ... and i want to read each one of them and search for some information and if i found the right one i save in new file with new... (6 Replies)
Discussion started by: andreia
6 Replies

3. IP Networking

Using Apache2 to Store Files for Accessing with wget?

Hello All, I have a Virtual Machine that I basically use for just testing stuff on. It is running SLES 11.1 and Apache2. I was able to get Apache2 set-up and working... I was able to insert a basic index.html page (i.e. a simple "Hello World" html page) just to check and make sure I can... (4 Replies)
Discussion started by: mrm5102
4 Replies

4. Programming

store information in hash and display number of keys.

I am trying to store this information (info and number) in hash. number is the key and info is value in a hash.i shown my code below. #!/usr/bin/perl use warnings; use strict; use XML::LibXML::Reader; my $file;open $file, 'formal.xml'); my $reader =... (0 Replies)
Discussion started by: veerubiji
0 Replies

5. Shell Programming and Scripting

Extract text and store in separate files

Hi, I have a file which looks like this: .I 1 some text .A this is the first line .I 2 some text again .B this is the second line .I 3 again some text .C this is the third line I want to have my output like this in separate files: (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

6. Shell Programming and Scripting

How to store files names from a directory to an array

Hi I want to store the file names into an array. I have written like this but I am getting error. declare -A arr_Filenames ls -l *.log | set -A arr_Filenames $(awk '{print $9}') index=0 while (( $index < ${#arr_Filenames })); do Current_Filename=${arr_Filenames} ... (5 Replies)
Discussion started by: dgmm
5 Replies

7. Shell Programming and Scripting

Store the files details in different file using bash

Hi all, this is output of ls command !! there is differen different files permission are there , and my requirement is each file permission is stored in different different file. rwxr-xr-x 1 root root 0 Mar 29 2011 2 -rwxr-xr-x 1 root root 0 Mar 29 2011 20 drwxr-xr-x 2... (3 Replies)
Discussion started by: anishkumarv
3 Replies

8. Shell Programming and Scripting

What amount of store occupy only files in a directory?

Hello I'm trying to do an exercise programming in bash where I have to get only the store of files in a directory but NOT all capacity of the directory. I probe with: du -sh "$directory"*` but I get all the capacity and I probe with ls command but I couldnt. Are there any way to get only files... (2 Replies)
Discussion started by: adiegorpc
2 Replies
Login or Register to Ask a Question