Help shell script to list filename file_path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help shell script to list filename file_path
# 1  
Old 10-04-2013
Wrench Help shell script to list filename file_path

HI
owner date and time and size of file in a row
shell script to list filename file_path i have tried the below code

Code:
present_dir=`pwd`
dir=`dirname $0`
list=`ls -lrt | awk {'print $9,$3,$6,$7,$8'}` 
size=`du -h`
path=`cd  $dir;pwd;`
printf  "$list" 
printf "$path"
printf " $size"


but im not getting the path for every file and it is not displaying in one rowSmilie
my output should be like:
Code:
filename filepath owner date and time size

it has to list in this way

Last edited by abiram; 10-04-2013 at 07:08 AM.. Reason: Added missing CODE tags
# 2  
Old 10-04-2013
Code:
one=foo
two=bar
three=baz
printf "%s %s %s\n" "$one" "$two" "$three"

# 3  
Old 10-04-2013
You only get the path once because you're only outputting it once. Your $list has multiple lines in it, but they're not joined to the path output (or the size, for that matter).

One approach could be to just use a for loop, similar to:
Code:
for i in *
do
   filesize=$(du -h $i)
   fileinfo=$(ls -l $i | awk '{printf $3,$6,$7,$8}')

   printf "%s %s %s %s\n" $i $filepath $fileinfo $filesize
done

EDIT: Forgot to set $filepath, but you should get the idea...

Last edited by CarloM; 10-04-2013 at 07:47 AM.. Reason: typo
# 4  
Old 10-04-2013
You can try this also

Code:
ls -lrt -h | awk -v a=$PWD 'BEGIN{print "filename\tfilepath\towner\tdate\ttime\tsize"}{print $9,a,$3,$7"-"$6,$8,$5}' OFS=\\t >filelog.dat

if you need full date and time use this

Code:
ls ---full-time -h


Last edited by Akshay Hegde; 10-04-2013 at 07:54 AM..
# 5  
Old 10-04-2013
You may want to try (given statis available on your system):
Code:
stat -c"%n   $PWD    %U      %y      %s" *

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetch the latest filename shell script

Hi I want to fetch the latest file form the list example example= filename RATE_STATE_SETUPS.20151222.ccyymmdd.hhmmss.txt File pick which have latest ccyymmdd.hhmmss list of file in directory are RATE_STATE_SETUPS.20151222.20151222.170101.txt... (5 Replies)
Discussion started by: MOHANP12
5 Replies

2. Shell Programming and Scripting

How to sort the timestamp in the filename in shell script?

originally the shellscript #ln_file_name=`echo $ld_interface_date"_"${8}".csv"` #ln_file_name=`echo 201202011527_HL_HLTM1_B04A.csv` ln_file_name="*"`echo ${7}".csv"` get_file_list_1=$log_path"tm1_file_list.gfl1" cd ${source_path} echo "Try to find any file exist in the... (10 Replies)
Discussion started by: feilhk
10 Replies

3. Shell Programming and Scripting

Shell script to get one to one map and rename the filename

I have 2 files sorted by numerically. I need help with shell script to read these 2 files and do a 1:1 mapping and rename the filenames with the mapped case#; For example: cat case.txt 10_80 10_90 cat files.txt A BCD_x 1.pdf A BCD_x 2.pdf ls pdf_dir A BCD_x 1.pdf A BCD_x 2.pdf ... (2 Replies)
Discussion started by: iaav
2 Replies

4. Shell Programming and Scripting

Shell script if [[ -L <filename> ]]

Hi Please describe about following condition if ] in shell script. Also please provide the link related all the flags which are applicable for if condition in Shell (4 Replies)
Discussion started by: munna_dude
4 Replies

5. Shell Programming and Scripting

Which shell script will call if i execute sh (without filename)?

Hi Friends, The below shell script is written by third party to create B2k_session_id.iam trying to execute this script.When i execute below script it is calling some other scripts.How to find which scripts is calling? . `execom commfunc.com` echo " $PRESENTATION_MODE " if then echo... (1 Reply)
Discussion started by: vadlamudy
1 Replies

6. Shell Programming and Scripting

Script to List, Modify, replace filename for an upload?

Hello, here is my problem: I have ma program in a first directory dir1: ls path1/rep1/ file1.f90 file1.f90~ file1.o file2.f90 .... etc... I have modified folder in an other directory: ls path2/rep2/ file1_modified.f90 file2_modified.f90 .... etc... All files from first... (8 Replies)
Discussion started by: shadok
8 Replies

7. Shell Programming and Scripting

Send filename as variable in a shell script

I am having some trouble with a shell script I am writing. In the program I pass the path of where certain file names exist. I then want to loop through each file name and pass it as a DATA variable when calling sqlldr for a control file. This is what I have: ls $FILEPATH/${FILENAME}*.csv ... (4 Replies)
Discussion started by: neva
4 Replies

8. Shell Programming and Scripting

Shell script to use the last modified filename in a variable

Forgive me if this is a trivial question, but I haven't been able to find the answer to this. Basically I've got a list of files in a particular directory that have the general form t_*.dat. (I have other files in the same directory as well). Essentially what I want to do is obtain the name... (1 Reply)
Discussion started by: lost.identity
1 Replies

9. Shell Programming and Scripting

read a part of filename from the list in the script

how can i read a part of filename from the list in the script? all file in directory...will start with "CDBACKUPFILE" then the name is stored in list.txt such as JOHN,MARRY,PETER. After this, is seq number. CDBACKUPFILEJOHN00001 CDBACKUPFILEMARRY00004 CDBACKUPFILEPETER00003 I will use:... (3 Replies)
Discussion started by: happyv
3 Replies

10. Shell Programming and Scripting

How to send filename as variable in a shell script

Can we can pass the filename as variable in the shell script. Sending the filename as a parameter file, the shell script takes the filename, needs to replace the string containing the filename with the variable in the shell script. EX: test1.sh is the shell script and takes file1.csv as... (6 Replies)
Discussion started by: gthokala9
6 Replies
Login or Register to Ask a Question