The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find the file size in unix lmraochodisetti UNIX for Advanced & Expert Users 5 12-16-2008 08:51 AM
How to find size of a file kittusri9 Shell Programming and Scripting 4 04-28-2008 08:01 AM
Find file size and date gsusarla UNIX for Advanced & Expert Users 10 04-08-2008 05:33 PM
command to find out total size of a specific file size (spread over the server) abhinov SUN Solaris 3 08-08-2007 06:48 AM
find the file by size rooh UNIX for Dummies Questions & Answers 1 08-16-2001 07:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-06-2007
hgriva1 hgriva1 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 3
find file size

My Question is
-----------------
Assume you've a directory (i.e /home/test/) which contains n number of files,
rename all the files which has byte count more than zero (0) with .bak extension.
Write shell script to achieve this output,
execute the same without using". / " in front of program name.


Could someone help me?
  #2 (permalink)  
Old 11-06-2007
s4g3's Avatar
s4g3 s4g3 is offline
Registered User
  
 

Join Date: Nov 2007
Location: India
Posts: 43
Seems more like a homework to me :-)
Why dont u do a little googling and find it out - its really easy

this will help u in increasing your knowledge

~Sage
  #3 (permalink)  
Old 11-06-2007
hgriva1 hgriva1 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 3
i could not find it
  #4 (permalink)  
Old 11-06-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
The work can be done with the commands : ls for test basename mv
  #5 (permalink)  
Old 11-06-2007
s4g3's Avatar
s4g3 s4g3 is offline
Registered User
  
 

Join Date: Nov 2007
Location: India
Posts: 43
Here is a very simple version of the script

for i in `ls -l /home/test/*`
do
if [ -s $i ]
then
mv $i $i.bak
else
continue
fi
done


~Sage
  #6 (permalink)  
Old 11-07-2007
hgriva1 hgriva1 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 3
Error while running the script

hi,
When i run the code given by you it renames all files irrespective of .bak extension like

before:
student.txt

after code is run
--------------------
student.txt.bak

this is same for all other files including .bak file
i.e if a file exists with name tst.bak
after the code is run it is made as tst.bak.bak.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate 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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0