The UNIX and Linux Forums  


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
Need to write a script in UNIX to find a file if another file exists mmdawg Shell Programming and Scripting 1 05-04-2008 11:40 PM
Chek if a file exists in Ubuntu and Cent OS using shell script m_kk Shell Programming and Scripting 2 03-26-2008 10:32 AM
Check File Exists and compare to previous day file script rbknisely Shell Programming and Scripting 3 02-07-2008 11:53 AM
unix script to check whether particular file exists and to find its size Balachandar Shell Programming and Scripting 9 02-05-2008 03:56 AM
shell script : text manipulation (easy quesiton) champion Shell Programming and Scripting 3 07-01-2002 04:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-10-2009
graysky graysky is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 13
Thumbs down bash script quesiton - if any file exists then ...

I'd like a bash script to simply check to see if any file/files are present in a source directory, and if so move it/them to a target directory.

I have this but it doesn't work:


Code:
#!/bin/bash
 
 if [ -e /source/* ]
then
  mv /source/* /target
fi

What is the right syntax? Thanks!
  #2 (permalink)  
Old 02-10-2009
arunsoman80 arunsoman80 is offline
Registered User
  
 

Join Date: Jul 2008
Location: New York
Posts: 45
Try this, not the ideal way to do this but does server the purpose:

Quote:
if [[ `ls /source/* | wc -l` -gt 0 ]]; then
mv /source/* /target
fi
  #3 (permalink)  
Old 02-10-2009
hare_krishna hare_krishna is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 2
You can try

#!/bin/bash

while ( `ls -1 /source/*|head -1` )
do
file=`ls -1 /source/*|head -1`
mv /source/$file /target
done
  #4 (permalink)  
Old 02-10-2009
ddreggors ddreggors is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 91
or...


Code:
for F in /source/*
do
    mv $F /target/
done

  #5 (permalink)  
Old 02-11-2009
graysky graysky is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 13
Cool, thanks for all the replies, all!
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 11:30 PM.


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