cancel
Showing results for 
Search instead for 
Did you mean: 

shell scrpt help

 
Highlighted
Super Advisor

shell scrpt help

$pwd
$/home/rajesh
$cd data1

$pwd

$/home/rajesh/data1
$ls
fa00 fa02 fa03 fa04 fa05 fa06 fa07 fa08 fa09 fa10 fa11 fa12 fa13 fa15 fa16
fa17 fa18 nas file2 fa18 fa19 fa20 fa21 fa22 fa23 fa24 fa25 fa26 fa27 fa28 fa29

fa 30 fa31 fa32 fa33 fa34 fa35 fa36

 
$

 

we need to write one script for mv command.

 

we need to move all file files and folser under the /home/rajesh/data1 , except nas and file2 folders

 

how to write the script.

 

please help me

 

 

4 REPLIES 4
Highlighted
Acclaimed Contributor

Re: shell script help

Where are you moving it to?  The same filesystem?

If the same, then move all files and then move nas and file2 back.  If doing a copy, this would be too expensive.

 

In a real shell you can also do:

mv !(nas|file2) target/

 

First, try an echo to make sure it does what you want.

Highlighted
Super Advisor

Re: shell script help

hi dennis,

 

thnaks for providing the details.

 

but now user request to delete the all files expect nas&file2.

 

pls help me

Highlighted
Honored Contributor

Re: shell script help

Something like this should work:

 

# cat mv-files.sh

#!/usr/bin/sh

cd /home/rajesh/data1

DATAFILES=$(ls -1 |grep -v -e nas -e file2)

mv ${DATAFILES} /new/dir

Highlighted
Acclaimed Contributor

Re: shell script help

>now user request to delete the all files except nas & file2.

 

Just replace "mv" by "rm -rf".  Check it with echo first.