Sponsored Content
Top Forums Shell Programming and Scripting Moving and renaming multiple files in a directory Post 302759695 by Chubler_XL on Tuesday 22nd of January 2013 07:00:43 PM
Old 01-22-2013
mktemp is not available on all systems, it's not POSIX.

How about this?

Code:
DIR=/transfer/move/sys/mail/20130123
FILES=$(ls $DIR)
if [ ! -z "${FILES}" ] ; then
    for i in ${FILES} ; do
        F=$DIR/MYFILENAME_$(openssl rand -hex 4).dat
        while [ -f $F ]
        do
            F=$DIR/MYFILENAME_$(openssl rand -hex 4).dat
        done
        mv $DIR/$i $F
    done
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

moving and renaming multiple files

Greetings, I know i can use the mv command to move and rename one file. How can I do this with multiple files? example pic01.bmp to pic0001.bmp how can i perform this function on an entire directory of sequential files and keep them in sequence? Hints, suggestions are most welcome:) ... (1 Reply)
Discussion started by: rocinante
1 Replies

2. Shell Programming and Scripting

Moving multiple files and renaming them on the fly

Hi All, Being new to scripting I am facing a new situation. We have an application that generates a file lets say dumpfile for each user under the users home directory when they execute the application. This is quite a huge file and imagine having that for over 40 users on a daily basis. The... (1 Reply)
Discussion started by: daemongk
1 Replies

3. UNIX for Dummies Questions & Answers

Renaming files after their directory name in multiple sub directories

So I am not sure if this should go in the shell forum or in the beginners. It is my first time posting on these forums. I have a directory, main_dir lets say, with multiple sub directories (one_dir through onehundred_dir for example) and in each sub directory there is a test.txt. How would one... (2 Replies)
Discussion started by: robotsbite
2 Replies

4. UNIX for Dummies Questions & Answers

Moving files out of multiple directories and renaming them in numerical order

Hi, I have 500 directories each with multiple data files inside them. The names are sort of random. For example, one directory has files named e_1.dat, e_5.dat, e_8.dat, etc. I need to move the files to a single directory and rename them all in numerical order, from 1.dat to 1000(or some... (1 Reply)
Discussion started by: renthead720
1 Replies

5. Shell Programming and Scripting

Need script for renaming and moving files one by one...

Dears, I need your help! I got a problem and found some workaround solution but I donno how to realize it. I have a number of files (about 300 each day) and I need them to be renamed. All these files has fixed number of letters and name looks like this one:... (7 Replies)
Discussion started by: nypreH
7 Replies

6. Shell Programming and Scripting

Moving and renaming large ammount of files

Hey, I'm kinda new to the shell scripting and I don't wanna mess things up yet :) Looking for a solution to the following: I need to move all the files like "filename.failed.dateandtime" to another directory also renaming them "filename.ready". I can't figure how to do this with multiple files... (4 Replies)
Discussion started by: sg3
4 Replies

7. Shell Programming and Scripting

Complex renaming then moving files

I am a biologist and using an program on a computer cluster that generates a lot of data. The program creates a directory named ExperimentX (where X is a number) that contains files "out.pdb" and "log.txt". I would like to create a script that renames the out.pdb file to out_ExperimentX.pdb (or... (1 Reply)
Discussion started by: yaledocker
1 Replies

8. Shell Programming and Scripting

Renaming multiple files in a directory

Hello, I would like to rename all available files in a directory from Filename to Filename_Normal. I tried to use below script but it is giving some error: #!/bin/sh for i in `ls` do echo Changing $i mv $i $i_Normal done Error received: Usage: mv src target or: mv ... (10 Replies)
Discussion started by: manishdivs
10 Replies

9. UNIX for Dummies Questions & Answers

Moving and renaming files

I have a directory full of directories, say called A B C D E .... In each of these directories there are files called 1.dsp 2.dsp 3.dsp ..... along with others (with different extensions) I need to go through each of these directories and move the dsp file to another folder, but with the name now... (6 Replies)
Discussion started by: claire.a
6 Replies

10. Shell Programming and Scripting

Shell Script for renaming and moving Files - Easy?

Hey guys, ive been working on this for about 2hrs now - without any solution. At first I need to say I dont have skills in linux bash scripting, but I tried to use some codesnippets and manuals from google. What I want to do: I have different folders including 2 different filestypes with... (15 Replies)
Discussion started by: peter1337
15 Replies
BTAG(1) 							    btag Manual 							   BTAG(1)

NAME
btag - A command line based multimedia tagger SYNOPSIS
btag [options] path1 [path2] [path3] ... DESCRIPTION
btag is a TagLib-based command line multimedia tag editor that attempts to automate the process of tagging a lot of files at once. It uses the tags found in the supplied files as well as interactive user input to determine new values for the tags. It can also optionally rename files and directories based on those new values. You can supply paths to files or directories to btag. Directories are recursively traversed and all files found are tagged. Directories are also handled differently in the sense that btag will attempt to keep information about the previously tagged files to provide sane defaults for all other files in the same parent directory. Only files with file extensions supported by TagLib are considered. OPTIONS
-D/--dry-run Don't do anything, just show what would have been done (dry run mode) -d/--dir-rename-format format Use format to rename the directories where the multimedia files were found -i/--input-filter filter Use filter as the input filter -f/--filter filter Use filter as both the input and the output filter -h/--help Display usage information and exit -n/--renaming-filter filter Use filter as the renaming filter -o/--output-filter filter Use filter as the input filter -r/--file-rename-format format Use format to rename the multimedia files -t/--title-locale locale Use locale for proper (although lax) locale-specific title casing INPUT AND OUTPUT FILTERS
btag supports input and output filters that are applied to the text fields (artist, album and song title). Those filters can protect against basic mistakes such as duplicate whitespace. Input filters are used on the tags as they are loaded from the multimedia files. This filtered information is used to provide suggestions to the user when the interactive tagger requests information for those text fields. If an output filter is configured, the user input is then filtered, and if the filtered text does not match the user input, the user is asked for confirmation. In most cases, the input filter should match the output filter (which is why the -f option is handy). You may choose to specify only an input filter, in which case the user input is not filtered. If you don't specify an input filter, though, the default input filter will be used. The currently available filters are: basic Provides basic filtering by removing duplicate or trailing whitespace, is the default input filter and the base for all other filters first_upper The first character in the field is uppercased, while all others are lowercased lower All characters are lowercased title The first character of each word is uppercased (with exceptions), while all others are lowercased upper All characters are uppercased The title capitalization algorithm will follow locale-specific context-insensitive rules depending on the value of the -t parameter. Note that strict title capitalization rules often depend on the context in which the words are used, the precise analysis of which is much beyond the scope of btag. The currently supported title locale specifications are: en English (default) es Spanish RENAMING FORMATS
If a format is specified with the -r option, the tagged multimedia files are renamed accordingly. Likewise, if the -d option is used, the directory in which multimedia files were tagged is renamed according to the specified format. The specified format is converted to a file or directory name using the following substitutions: %artist Artist name %album Album name %year Year of release %track Track number (only replaced by the -r option) %title Song title (only replaced by the -r option) Renaming happens after the tags are written, and it's relative to btag's working directory. For directory renaming, the last known artist, album and year information is used. Only directories that contain files that were tagged by btag are renamed. btag does not prevent you from overwriting existing files using the formats described here. RENAMING FILTERS
Renaming filters are used to ensure that the file and directory names generated using the renaming formats (if specified) are valid (safe) in the context of the current file system. The following renaming filters are currently available: conservative Conservative character replacements are performed, recommended for FAT32 file systems unix Generates file and directory names that should be valid in an Unix environment (default) EXAMPLE
Using title casing with English rules and sensible renaming formats generating FAT32-safe file and directory names: $ btag --file-rename-format '%track. %title' --dir-rename-format '%album (%year)' --filter title --title-locale en --renaming-format conservative /path/to/myalbum Using an input filter only: $ btag --input-filter lower /path/to/myalbum btag 2011-06-04 BTAG(1)
All times are GMT -4. The time now is 05:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy