moving files with spaces in filename from one directory to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting moving files with spaces in filename from one directory to another
# 1  
Old 04-26-2009
moving files with spaces in filename from one directory to another

Hello,

When I run following script

#!/bin/bash

cd ~/directory1

mv `ls -trF | grep -v / | tail -10 ` ~/directory2

works fine with filenames not having any space but runs into issues with filenames that have spaces tried with $file variable still doesnot work. Can someone help me
# 2  
Old 04-27-2009
try putting your filename within quotes.. like "my file".
# 3  
Old 04-27-2009
Quote:
Originally Posted by divzz
try putting your filename within quotes.. like "my file".
I m sorry didnt read the question properly n jumped to reply..
# 4  
Old 04-27-2009
Try some thing lik this

find . -type f -exec mv {} ./DIR_NAME \;

Check for more option flags of find for ur needs.
# 5  
Old 04-27-2009
in script include $file in quotes as "$file"

and while passing the path to script pass in quotes as
"/root/directory first"

this will work fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename all files (filename with spaces) to different extension

Hi, I have files with filenames as below. SGM Daily Sales Email-en-us-05312012.xlwa I want to rename it in .xls. I am writing a script to change this, as there can be multiple files in subfolders. I have the following script. #!/bin/ksh for oldfile in $(find... (1 Reply)
Discussion started by: mac4rfree
1 Replies

2. UNIX for Dummies Questions & Answers

Copying files with spaces in the filename in a for loop

Hi all, I've been tangoing with this one for a couple of days now and I'm still not making any progress. Basically I'm trying to match three numbers in a string from a text file with matching numbers in a jpeg, and then copying the results to another folder. Data looks like this: Model:... (4 Replies)
Discussion started by: faceonline
4 Replies

3. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

4. UNIX for Dummies Questions & Answers

finding and moving files based on the last three numerical characters in the filename

Hi, I have a series of files (upwards of 500) the filename format is as follows CC10-1234P1999.WGS84.p190, all in one directory. Now the last three numeric characters, in this case 999, can be anything from 001 to 999. I need to move some of them to a seperate directory, the ones I need to... (5 Replies)
Discussion started by: roche.j.mike
5 Replies

5. Shell Programming and Scripting

Moving files that contain spaces...

I have a script that I've written and it's been running fine until someone dropped a file in the source directory that had spaces in it. The script breaks the file name into separate mv commands. I've tried putting " around the $FILE but that didn't help. Anyone who can help me would be greatly... (8 Replies)
Discussion started by: Sanglant
8 Replies

6. Shell Programming and Scripting

List files with spaces in filename

I have a text file containing files in a directory structure i.e. /project/hr/raw/jcpdatav/datav_aug03 /project/hr/raw/jcpdatav/comb8121sep02n /project/hr/raw/jcpdatav/datav_feb04_ons /project/hr/raw/jcpdatav/corpsick_jun06 /project/hr/raw/jcpdatav/jcpjoiners200507... (3 Replies)
Discussion started by: mr_crosby
3 Replies

7. Shell Programming and Scripting

copying files with spaces in the filename

Hi I am having difficulty copying files from one dir to another due to a space in the names of the file with an extension .rtf There are a group of files and the command am using is cp `ls -rt /wlblive/home/whiops/ops/RTFs/*.rtf|head -20` /wlblive/home/jamshed Since the files are... (3 Replies)
Discussion started by: jamshedj
3 Replies

8. Shell Programming and Scripting

Creating date directory and moving files into that directory

I have list of files named file_username_051208_025233.log. Here 051208 is the date and 025233 is the time.I have to run thousands of files daily.I want to put all the files depending on the date of running into a date directory.Suppose if we run files today they should put into 05:Dec:08... (3 Replies)
Discussion started by: ravi030
3 Replies

9. UNIX for Dummies Questions & Answers

Moving files by splitting the path embedded in the filename

Hello All. I am having a directory /tmp/rahul which contains many files in the format @#home@#rahul@#programs@#script.pl where /home/rahul/programs is the directory where the script.pl file is to be placed. I have many files in this format. What i want is a script which read these... (7 Replies)
Discussion started by: rahulrathod
7 Replies

10. UNIX for Dummies Questions & Answers

moving files from a unix directory to a windows directory

Any body any ideas i'm failry new to this so any help would be appreciated. Cheers Steve (2 Replies)
Discussion started by: gleads
2 Replies
Login or Register to Ask a Question