How to move all files in a directory and subdirectory?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to move all files in a directory and subdirectory?
# 1  
Old 07-01-2011
How to move all files in a directory and subdirectory?

I'm trying to organize my MB Pro by moving all my jpeg files to a single folder from the desktop. There are some on the desktop that are not in any folder. I was at the command line and typed
Code:
mv *.jpg "Jpeg files"

but it only moved the files that were on the desktop, not any of the ones that were in any subdirectories. I'm forgetting something here -- can someone tell me how to get all the jpeg files (or any other files of a type, for that matter) -- no matter which subdirectory they're in -- and move them to the designated folder I want?

Last edited by Franklin52; 07-04-2011 at 04:04 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-01-2011
Code:
ls -R *.jpg | while read f
do
echo mv "$f" "/Jpeg_files/${f##*/}"
done

If output fit with your needs, remove the "echo"
# 3  
Old 07-01-2011
Can you tell me what 'echo' does in the script? I'm not clear on it.
# 4  
Old 07-04-2011
echo just display the command : nothing will be done, it will just show the commands that are built.
If it builds the command as you expected, remove the echo so that it will run the move command for real.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to move gz files from one source directory to destination directory?

Hi All, Daily i am doing the house keeping in one of my server and manually moving the files which were older than 90 days and moving to destination folder. using the find command . Could you please assist me how to put the automation using the shell script . ... (11 Replies)
Discussion started by: venkat918
11 Replies

2. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

3. Shell Programming and Scripting

How to move to the last subdirectory one by one?

Hi, How can i traverse to the last subfolder in all the directories. eg: i have the below folders structure f1/sf1/r1 f2/sf2/r2 f3/sf3/r3/r4 i need to move to the last directory in each directory. Can anyone tell me a solution for this? I saw an example that does that. find . -type... (2 Replies)
Discussion started by: Little
2 Replies

4. Shell Programming and Scripting

Remove all files except the subdirectory(without pattern) in a directory

I used rm * and it deleted the files in the directory but gives and error message for unsuccessful subdirectory deletion. "rm: cannot remove 'DirectoryName': Is a directory" I dont want to explicitly get the above error. What are the modifications I have to do in the rm command? (3 Replies)
Discussion started by: duplicate
3 Replies

5. Shell Programming and Scripting

Globbling files in the direct subdirectory of the current directory

I want to list files that end with .c in the direct subdirectory of the current directory. I have tried the following command: find ./ -mindepth 2 -maxdepth 2 -name "*.c" Is that right? Or is there any easier way to handle that problem? Another problem is that I want to grep in a file to find... (5 Replies)
Discussion started by: Ray Sun
5 Replies

6. Shell Programming and Scripting

Changing ownership of a directory, subdirectory and files as same as in another server

accidentally i have changed ownership of a directory,subdirectory and files wil below command. I want to the change ownership back as same as in same directory on another server. How can i do it? chown -R user:group /u01 is there any simple script? it is really an urgent need.. (2 Replies)
Discussion started by: johnveslin
2 Replies

7. Solaris

Display the number of files in a directory and recursively in each subdirectory

Display the number of files in a directory and recursively in each subdirectory To look something like below, for example /var 35 /var/tmp 56 /var/adm 46Any ideas how can we do this? Got a sun cluser global mount point which takes ages to mount everytime, need to understand... (5 Replies)
Discussion started by: jakerock
5 Replies

8. Solaris

Display the number of files in a directory and recursively in each subdirectory

Display the number of files in a directory and recursively in each subdirectory To look something like below, for example /var 35 /var/tmp 56 /var/adm 46 Any ideas how can we do this? :wall: (1 Reply)
Discussion started by: jakerock
1 Replies

9. Shell Programming and Scripting

Move all files not in a directory into a subdirectory named for each given file

Hi Everyone! Looking for some help with a script that will take all files in any given root folder (which are not already in a folder) and put them into separate folders with the name of each given file. Any ideas? Thank you! (1 Reply)
Discussion started by: DanTheMan
1 Replies

10. Shell Programming and Scripting

Find files in directory and its subdirectory

I am writing a script which reads a file line by line and then assigns it to a variable like this 1090373422_4028715212.jpg. I have images with file name of this format in some other directory. In my script I want to assign variable with this file name and then find this filename in some other... (11 Replies)
Discussion started by: jyotib
11 Replies
Login or Register to Ask a Question