LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-23-2009, 03:31 PM   #1
ravedog
Member
 
Registered: Jun 2009
Distribution: Ubuntu, Sabayon
Posts: 38

Rep: Reputation: 0
Smile Simple move script


Hi all!

Im trying to setup a download box for myself and along the way learning about or two about linux.

So i have made a script (cover your eyes, its extremely advanced) that looks like this:

Code:
zenity --info --text="Copy of files initiated, please wait until done"
mv /home/user/downloaded/*DVD* /home/user/downloaded/*dvd* /media/misc1/temp/
zenity --info --text="Copy done!"
However, its quite dumb at the moment and pops a dialog box regardless of if there is files to move or not.

Anyone have an idea on how to make it "look" before trying to copy?

Thanks in advance!

(Thanks for a great forum as well!)

Ravedog

EDIT: Spell check :/

Last edited by ravedog; 06-23-2009 at 03:33 PM.
 
Old 06-23-2009, 03:44 PM   #2
nuwen52
Member
 
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
how about:
Code:
ls /home/user/downloaded/*DVD* >> /dev/null
if [ $? = 0 ]
then
    <do all your stuff> 
else
    <display error>
fi
$? is the return code of whatever the previously executed command was.
 
Old 06-23-2009, 03:46 PM   #3
ravedog
Member
 
Registered: Jun 2009
Distribution: Ubuntu, Sabayon
Posts: 38

Original Poster
Rep: Reputation: 0
Thanks for a quick answer m8! Ill get right on testing it in the morning
 
Old 06-24-2009, 02:39 PM   #4
ravedog
Member
 
Registered: Jun 2009
Distribution: Ubuntu, Sabayon
Posts: 38

Original Poster
Rep: Reputation: 0
Worked like a charm! Thanks!

Follow up question, what is the syntax in the example given above if i like to search for several thing? I.e. *DVD* and *DVDrip* and if any match proceed.

Thanks guys!
 
Old 06-24-2009, 02:46 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If you want to perform an action on any file found, you can use a for loop like this:
Code:
for file in $(ls *DVD* *DVDrip* 2>/dev/null)
do
  echo "$file"
done
this simple example will do an echo of the filename. It will do nothing if no file is found. What exactly do you want to achieve if you find some *DVD* or *DVDrip* file?
 
Old 06-24-2009, 02:53 PM   #6
ravedog
Member
 
Registered: Jun 2009
Distribution: Ubuntu, Sabayon
Posts: 38

Original Poster
Rep: Reputation: 0
Hi colucix!

Thanks for the tip! I want to scan a download folder after several criteria and move them to the correct folder.

Simple put:

If DVD --> Folder a

If 1080 or 720 --> Folder c

If xvid -> Folder b

Cheers!

/R
 
Old 06-24-2009, 03:13 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You can try a case/esac construct:
Code:
for file in /home/user/downloaded/*
do
  case "$file" in
    *DVD*          ) mv "$file" folder_a ;;
    *xvid*         ) mv "$file" folder_b ;;
    *1080* | *720* ) mv "$file" folder_c ;;
    * ) echo "unknown file" ;;
  esac
done
 
Old 06-24-2009, 03:15 PM   #8
ravedog
Member
 
Registered: Jun 2009
Distribution: Ubuntu, Sabayon
Posts: 38

Original Poster
Rep: Reputation: 0
That looks really sweet, gonna try it out in the morning! thanks a bunch man!

Cheers!

/R
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple question for i in `cat move.txt` Noto Programming 13 05-25-2008 06:32 PM
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 05:34 PM
Very simple shell script - move files to different directories beley Programming 7 11-02-2006 05:24 AM
simple question - can you move header and lib files from one box to ano dewcansam Linux - General 3 11-25-2001 12:35 AM
simple question - can you move header and lib files from one box to another without a dewcansam Linux - Newbie 3 11-06-2001 05:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration