Move several files into specific directories with a loop


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Move several files into specific directories with a loop
# 15  
Old 03-04-2020
Might be wise not to rely on the directories' suffixes correspond to their "sequential number" which equals the files' "sequential numbers". And, check if a corresponding file exists at all to avoid failure if absent:
Code:
for DN in 0[1-4]*
  do    TMP="*[!0-9]${DN/%_*}.jpg"
        [ -f $TMP ] && echo mv $TMP $DN
  done
mv 1244081312562_02.jpg 02_webasset_200
mv 1244081312562_03.jpg 03_webasset_300
mv 1244081312562_04.jpg 04_webasset_400


as opposed to

Code:
mv *[!0-9]01.jpg 01_webasset_100
mv 1244081312562_02.jpg 02_webasset_200
mv 1244081312562_03.jpg 03_webasset_300
mv 1244081312562_04.jpg 04_webasset_400

without the precautions.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need BASH Script Help to Move Files While Creating Directories

I've got this script to loop through all folders and move files that are more than 2 years old. I'm using the install command because it creates the necessary directories on the destination path and then I remove the source. I'd like to change the script to use the mv command since it is much... (4 Replies)
Discussion started by: consultant
4 Replies

2. UNIX for Dummies Questions & Answers

Move multipe files to corresponding directories

Hi, In a parent directory there are several files in the form IDENTIFIER1x IDENTIFIER1.yyy IDENTIFIER1_Z, etc IDENTIFIER2x IDENTIFIER2.yyy IDENTIFIER2_Z, etc IDENTIFIER3x IDENTIFIER3.yyy, IDENTIFIER3_Z, etcIn the same parent directory there are corresponding directories named... (7 Replies)
Discussion started by: spirospap
7 Replies

3. 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

4. OS X (Apple)

Batch file to move video files and retain sub-directories

I have just purchased my first ever Apple computer - and am therefore new to UNIX also. I would like to create a simple "batch file" (apologies if this is the wrong terminology) to do the following: When I plug my camera into the MAC it automatically downloads photos and videos into a new... (1 Reply)
Discussion started by: mm0mss
1 Replies

5. Shell Programming and Scripting

Loop to move files in different directories

Hi, I have various log files in different paths. e.g. a/b/c/d/e/server.log a/b/c/d/f/server.log a/b/c/d/g/server.log a/b/c/h/e/server.log a/b/c/h/f/server.log a/b/c/h/g/server.log a/b/c/i/e/server.log a/b/c/i/e/server.log a/b/c/i/e/server.log and above these have an archive folder... (6 Replies)
Discussion started by: acc01
6 Replies

6. Shell Programming and Scripting

Help with command to Move files by X number to seperate directories

Hello, I need help finding a script that will allow me to move files from one directory to another directory 10k files at a time. I have a directory that has 100 K files in it. I need to have those 100k files broken apart to separate directories each with 10k files in them. Here is the... (8 Replies)
Discussion started by: Geo_Bean
8 Replies

7. Shell Programming and Scripting

want to move files in a dir into different directories based on the filename

I want to move the files in a dir to different dirs based on their file names. Ex: i have 4 different files with name - CTS_NONE_10476031_MRL_PFT20081215a.txt CTS_NONE_10633009_MRL_PFT20091020a.txt CTS_NONE_10345673_MRL_PFT20081215a.txt CTS_NONE_10872456_MRL_PFT20091020a.txt and the 1st... (4 Replies)
Discussion started by: Sriranga
4 Replies

8. UNIX for Dummies Questions & Answers

want to move files in a dir into different directories based on the filename

I want to move the files in a dir to different dirs based on their file names. Ex: i have 4 different files with name - CTS_NONE_10476031_MRL_PFT20081215a.txt CTS_NONE_10633009_MRL_PFT20091020a.txt CTS_NONE_10345673_MRL_PFT20081215a.txt CTS_NONE_10872456_MRL_PFT20091020a.txt and the 1st... (2 Replies)
Discussion started by: Sriranga
2 Replies

9. Shell Programming and Scripting

grep'ing for specific directories, and using the output to move files

Hello, this is probably another really simple tasks for most of you gurus, however I am trying to make a script which takes an input, greps a specific file for that input, prints back to screen the results (which are directory names) and then be able to use the directory names to move files.... (1 Reply)
Discussion started by: JayC89
1 Replies
Login or Register to Ask a Question
uuaids(8c)																uuaids(8c)

Name
       uucompact, uumkspool, uurespool, uupoll - uucp utilities

Syntax
       uucompact -ssystem
       uumkspool system ...
       uurespool [ -t# ]
       uupoll system ...

Description
       All of the commands are located in

       The  command  compacts  uucp  system spool directories and associated subdirectories. If system is ALL, then all existing uucp system spool
       directories are compacted.  Otherwise, only the specified system spool directory is compacted.  If no system is	specified,  is	compacted.
       If  is stopped before it is finished, it can be restarted without reprocessing directories.  The command continues processing where it left
       off during it's previous instantiation.

       The command makes a per system spool directory and associated subdirectories for each of the specified systems.	For example, if system	is
       mk3 and if the local system name is penny, the following directories are created:
	       /usr/spool/uucp/sys/mk3
	       /usr/spool/uucp/sys/mk3/C.
	       /usr/spool/uucp/sys/mk3/X.
	       /usr/spool/uucp/sys/mk3/D.
	       /usr/spool/uucp/sys/mk3/D.penny
	       /usr/spool/uucp/sys/mk3/D.penny
       The  command  moves files from old spool directories to	new spool directories.	Because the structure of the spool directories has changed
       from older versions of it is necessary to respool old spooled files to new spool directories in at least two instances:

       o    When installing the current version of

       o    When creating a new system spool directory for each system.

       In the latter case, it is necessary to move files from to the new spool directories.  To ease this task, moves files that have been spooled
       in  one	of 4 formats and respools them under the new spooling structure.  The format is specified by the -t# option, where the number sign
       (#) can be any one of the following:

       o   Original spool - All files are in

       o   Split spool - Contains the subdirectories

       o   Modified split spool -  Contains all subdirectories listed in split spool, and

       o   Used when a new system directory has been created and spool files must be moved from the DEFAULT directory to the new system directory.

       The command forces a connect attempt to the named systems even if recent attempts have failed, but not if the file prohibits the call.  For
       example, the file will prohibit the call if it is the wrong time of day.  Thus, the should be monitored for messages about the connection.

Files
       Spool directory

       Logfile

See Also
       mail(1), uucp(1c), uux(1c)

																	uuaids(8c)