Mv directory/sub-dir which contain whitespace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mv directory/sub-dir which contain whitespace
# 1  
Old 08-24-2013
Mv directory/sub-dir which contain whitespace

Hi All,

I need a help to move many directory/sub-directory which contain whitespace.

Kindly check below case sample:

Code:
jarvis:folder 1 briar$ ls -la /tmp/test/*
/tmp/test/folder 1:
total 8
drwxr-xr-x  3 briar  wheel  102 Aug 25 02:49 .
drwxr-xr-x  5 briar  wheel  170 Aug 25 02:46 ..
-rw-r--r--  1 briar  wheel   39 Aug 25 02:49 textfile 1.txt

/tmp/test/folder 2:
total 8
drwxr-xr-x  3 briar  wheel  102 Aug 25 02:50 .
drwxr-xr-x  5 briar  wheel  170 Aug 25 02:46 ..
-rw-r--r--  1 briar  wheel   39 Aug 25 02:49 textfile 2.txt

/tmp/test/folder 3:
total 8
drwxr-xr-x  3 briar  wheel  102 Aug 25 02:51 .
drwxr-xr-x  5 briar  wheel  170 Aug 25 02:46 ..
-rw-r--r--  1 briar  wheel   39 Aug 25 02:49 textfile 3.txt


I have listed all the directory path and save it to file (listfolder.txt)
Code:
jarvis:test briar$ ls -ld -1 /tmp/test/* > /tmp/test/listfolder.txt
jarvis:test briar$ cat /tmp/test/listfolder.txt 
/tmp/test/folder 1
/tmp/test/folder 2
/tmp/test/folder 3

So, my question is: how to move all dir/sub-dir from the list to the specific directory, let say "/tmp/test2" ?

I have try several method, using "for i in xxx", "while read", but didn't work.
Since the directory list have a white space in it, it is always failed when I tried to move using printf/echo and even directly using mv. see below sample.
Code:
jarvis:test briar$ sed 's/^/"/g;s/$/"/g' /tmp/test/listfolder.txt
"/tmp/test/folder 1"
"/tmp/test/folder 2"
"/tmp/test/folder 3"

jarvis:test briar$ sed 's/^/"/g;s/$/"/g' /tmp/test/listfolder.txt | while read x ; do mv "$x" "/tmp/test2"; done
mv: rename "/tmp/test/folder 1" to /tmp/test2/folder 1": No such file or directory
mv: rename "/tmp/test/folder 2" to /tmp/test2/folder 2": No such file or directory
mv: rename "/tmp/test/folder 3" to /tmp/test2/folder 3": No such file or directory


Thanks.
# 2  
Old 08-25-2013
Literal quotes in the shell code are enough
Code:
while read x ; do mv "$x" "/tmp/test2"; done </tmp/test/listfolder.txt

# 3  
Old 08-25-2013
Many thanks, that's all I need.. can't believe I'm forgot about stdin redirection Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Find directory immediately after the pattern dir name

Hi, From below directories path I need the directory which comes immediately after the "DataPath" /var/errors/LogDefaultPath/DataPath/Data01/Data02 (Directory name "Data01" is the result from this path) /var/errors/LogDefaultPath/DataPath/Log01/Log0202 (Directory name "Log01" is the... (4 Replies)
Discussion started by: Yuvaan12
4 Replies

3. Shell Programming and Scripting

List no. of files in a directory/sub dir's and also an consolidated report as required

Need help on below query asap. Thanks. The below is the directory structure: /home/suren under /suren the following are the directories /bin /log /error /bin contains the following files abc.txt bcd.ksh cde.sh wer.ksh ghi (file with out any extension) /log contains the following... (1 Reply)
Discussion started by: sureng
1 Replies

4. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

5. Shell Programming and Scripting

Find which dir is big size in a directory

Hi all, Could you please tellme the commadn which sorts the list of directories in a parent dir by their size. Thanks. (2 Replies)
Discussion started by: firestar
2 Replies

6. Shell Programming and Scripting

How to match (whitespace digits whitespace) sequence?

Hi Following is an example line. echo "192.22.22.22 \"33dffwef\" 200 300 dsdsd" | sed "s:\(\ *\ \):\1:" I want it's output to be 200 However this is not the case. Can you tell me how to do it? I don't want to use AWK for this. Secondly, how can i fetch just 300? Should I use "\2"... (3 Replies)
Discussion started by: shahanali
3 Replies

7. UNIX for Dummies Questions & Answers

Assigning the relative directory name to a variable called $DIR.

Hi All, I've been trying to write a KSH script that acts on the name of the relative directory that this script is called from. In other words, if I am executing this script from a directory called: /hello/hithere/directory How would I assign DIR= to be "directory" and... (2 Replies)
Discussion started by: chatguy
2 Replies

8. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

9. Shell Programming and Scripting

Checking the directory and concatenate the data of all the log files in that dir

Hi Gurus, I am new to unix and need your help to make a shell script. I have a requirement, would appreciate if you could please help me on it: Requirement: ------------- I will pass 2 parameters in shell script 1). Directory name say errors 2). file extension say .log First of all this... (4 Replies)
Discussion started by: anshulinpc
4 Replies

10. Shell Programming and Scripting

a script to clone a dir tree, & overwrite the dir struct elsewhere?

hi all, i'm looking for a bash or tcsh script that will clone an empty dir tree 'over' another tree ... specifically, i'd like to: (1) specify a src directory (2) list the directory tree/hiearchy beneath that src dir, w/o files -- just the dirs (3) clone that same, empty dir hierarchy to... (2 Replies)
Discussion started by: OpenMacNews
2 Replies
Login or Register to Ask a Question