move files not ending in .sh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting move files not ending in .sh
# 1  
Old 04-04-2011
move files not ending in .sh

Hi
I have a list of files under a directory , for eg

Code:
drwxr-xr-x   2 beauser  bea            6 Mar 16 15:43 security.20110316.stress
-rw-r--r--   1 beauser  bea        41063 Mar 16 17:30 config.xml.20110316_1
-rw-r--r--   1 beauser  bea      423930597 Mar 16 23:29 jra_managed1_20110316.jfr
-rwxr-xr-x   1 beauser  bea          431 Mar 18 10:12 startServer.sh
-rwxr-xr-x   1 beauser  bea          562 Mar 18 10:17 stopServer.sh.old

I want to list /move files NOT ending in .sh to be moved to a folder called backup, so startServer.sh should not be moved . However I do not want to move directories, nor do I want to list or move files under subdirectories of current folder. I have been looking into prune and maxdepth but cant get prune to work the way I want and I dont see the maxdepth option in the man pages.
Any help would be appreciated.

Thanks

Last edited by DukeNuke2; 04-04-2011 at 02:22 AM..
# 2  
Old 04-04-2011
Try this - replace echo with actual move when your happy it's working:

Code:
for file in *
do
   [ -f "$file" ] || continue
   case "$file" in
       *.sh)
          # Not to be moved
       ;;
       *)
          echo mv $file ./backup
       ;;
   esac
done

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 04-04-2011
One line of command is enough:

Code:
mv `ls -F | grep -v '.sh$\|/'` path/of/backup


Last edited by vistastar; 04-04-2011 at 02:43 AM..
# 4  
Old 04-04-2011
Quote:
Originally Posted by vistastar
One command is enough:

Code:
rm `ls | grep -v '.sh$'`

That's three commands! And the first one (rm is wrong) Smilie
# 5  
Old 04-04-2011
Quote:
Originally Posted by scottn
That's three commands! And the first one (rm is wrong) Smilie
you posted while I was modifying my post...Smilie. I have edited it.
# 6  
Old 04-04-2011
Code:
$ ruby -rfileutils -e 'Dir["*"].select{|x|!x[/\.sh/] && !test(?d,x)}.each{|y| FileUtils.move(y,"/tmp") }'

# 7  
Old 04-04-2011
Hi pkabali,

A option with find(go to desired folder):
Code:
find . -maxdepth 1 -type f -name "*[!.sh]" -exec sh -c 'exec mv -f "$@" /home/user/backup' X '{}' + # it works only in directory (not subdirectories)

find . -maxdepth 1 -type f -name "*[!.sh]" # This part finds and prints files without sh extension.
 -exec sh -c 'exec mv -f "$@" /home/user/backup' X '{}' + # This part executes the copy of files found previously


Hope it helps.

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies

2. UNIX for Dummies Questions & Answers

General find /grep question: files with lines ending in r

I am trying to find files that have lines in them that end in an r. I have been able to locate files by using the following command: find . -type f -name "*RECORDS"| xargs grep -l r$ However, I now want to find files that don't end in r anywhere. That means that no sentences or lines in... (9 Replies)
Discussion started by: newbie2010
9 Replies

3. Shell Programming and Scripting

Move all files except sys date (today) files in Solaris 10

I want to move all files from one directory to another directory excluding today (sysdate files) on daily basis. file name is in pattern file_2013031801, file_2013031802 etc (2 Replies)
Discussion started by: khattak
2 Replies

4. UNIX for Dummies Questions & Answers

Listing files in a Unix Directory ending with .....

Hi Unix Gurus, I need to list all files in a Unix Directory which either end with a .pdf or .rtf and they should be case insensitive ie .Pdf , .pDF , .RtF etc are also possible. How can i accomplish this with with a ls command ? If not then a find command. (6 Replies)
Discussion started by: pchegoor
6 Replies

5. Shell Programming and Scripting

if statement to check files with different ending but same starting name

I am trying to check if files staring with filename but ending with diffent dates e.g. filename.2011-10-25. The code I am using is below if It works find only if one file is present but returns binary operator expected when there are mulptiple files. Please help me correcting it. I... (5 Replies)
Discussion started by: ningy
5 Replies

6. Homework & Coursework Questions

display certain files ending

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: how to display a listing of all the files ending in txt using one command. 2. Relevant commands, code,... (4 Replies)
Discussion started by: austing5
4 Replies

7. Shell Programming and Scripting

Convert directory of text files to Unix/Linux Line Ending

I need help converting a directory of *.txt with Windows line ending to UTF-8 character encoding and Unix/Linux line ending. (9 Replies)
Discussion started by: chipperuga
9 Replies

8. Shell Programming and Scripting

Recursively move directories along with files/specific files

I would like to transfer all files ending with .log from /tmp and to /tmp/archive (using find ) The directory structure looks like :- /tmp a.log b.log c.log /abcd d.log e.log When I tried the following command , it movies all the log files... (8 Replies)
Discussion started by: frintocf
8 Replies

9. Shell Programming and Scripting

Delete files in a folder with a specific ending

Hi I have files that end with .txt.txt that i want to delete. But I also have files that end with .txt that I want to leave intact. How do I specifically delete files that end with .txt.txt in a folder. thanks (5 Replies)
Discussion started by: kylle345
5 Replies

10. Shell Programming and Scripting

How to check files and move the results to differents files?

Hi, I am a newbie to shell scripting. here is my objective: 1)The shell program should take 2 parameters - ie-> DestinationFolder, WebFolder 2)Destination folder contains few files that has to has be verified and deleted. 3)WebFolder is a folder containing a list of master files 4)It... (1 Reply)
Discussion started by: sandhyagupta
1 Replies
Login or Register to Ask a Question