Sponsored Content
Top Forums Shell Programming and Scripting changing filenames in a directory to a number within a loop Post 302150299 by visitorQ on Tuesday 11th of December 2007 12:44:54 AM
Old 12-11-2007
i tried yours, reborg, and it kinda messed me up a little.

Code:
kumi@throne:atlas/images/photos % sudo chmod a+x gallery
kumi@throne:atlas/images/photos % ls
10.jpg  12.jpg  14.jpg  16.jpg  18.jpg  1.jpg   21.jpg  23.jpg  25.jpg  27.jpg  29.jpg  30.jpg  32.jpg  34.jpg  36.jpg  4.jpg  6.jpg  8.jpg  gallery*
11.jpg  13.jpg  15.jpg  17.jpg  19.jpg  20.jpg  22.jpg  24.jpg  26.jpg  28.jpg  2.jpg   31.jpg  33.jpg  35.jpg  3.jpg   5.jpg  7.jpg  9.jpg
kumi@throne:atlas/images/photos % ./gallery 
mv: overwrite `1.jpg', overriding mode 0644? y
mv: cannot move `10.jpg' to `1.jpg': Permission denied
mv: overwrite `2.jpg', overriding mode 0644? 
kumi@throne:atlas/images/photos % sudo ./gallery 
kumi@throne:atlas/images/photos % ls
10.jpg  12.jpg  14.jpg  16.jpg  18.jpg  20.jpg  22.jpg  24.jpg  26.jpg  28.jpg  30.jpg  32.jpg  34.jpg  36.jpg
11.jpg  13.jpg  15.jpg  17.jpg  19.jpg  21.jpg  23.jpg  25.jpg  27.jpg  29.jpg  31.jpg  33.jpg  35.jpg  gallery*

as you can see, i lost 10 photos. why?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Appending text to a number of similar filenames

Hi, I was wondering if there was a way to append something to filenames based on a wildcard. For example, if I have the following files in a directory: blah1 blah2 blah3 blah4 blah5 I want to rename these all to: blah1.txt blah2.txt blah3.txt blah4.txt blah5.txt Is there a... (4 Replies)
Discussion started by: Djaunl
4 Replies

2. UNIX for Dummies Questions & Answers

extracting and using date from filenames in a loop

HIya, Having a dumb day whilst writing an archive process in Shell want to extract from the filename the date and archive into tar files based on this, I don't want to use mtime as it may not be the actual file date. The files are -rw-rw---- 1 user admin 100 Aug 29 11:10... (2 Replies)
Discussion started by: badg3r
2 Replies

3. Shell Programming and Scripting

Help with how to account for changing filenames

The files below are essentially “lookup files” used in a series of scripts that run through the look up files and grab the correct Group Name and File Type and then unless I have the file name specified will replace the variable with the corresponding group name when processing the files before... (1 Reply)
Discussion started by: defiant82
1 Replies

4. Shell Programming and Scripting

loop through numbered filenames

Hi I'm very new to this script thing, so please be gentle. I am trying to get a command - the mach2qtl command in the code below - to loop through a set of files. Each command should take the same two .dat and .ped files, but the .mlinfo and .mlprob files with filenames including 'chrom1' ... (7 Replies)
Discussion started by: polly_falconer
7 Replies

5. Shell Programming and Scripting

Whitespace in filenames in for loop in bash script

I'm trying to search all .odt files in a directory for a string in the text of the file. I've found a bash script that works, except that it can't handle whitespace in the filenames. #!/bin/bash if ; then echo "Usage: searchodt searchterm" exit 1 fi for file in $(ls *.odt); do ... (4 Replies)
Discussion started by: triplemaya
4 Replies

6. Shell Programming and Scripting

changing number in bash (number is in form of string)

I have a txt file as database. when i run my program what it does is it ask me for 3 name and stored in the file as name1:name2:name3:1 when u enter 3 name it add those in file as above format and add 1 at the end. I what i want is if i enter same names again it changes that 1 to 2 and so... (3 Replies)
Discussion started by: Learnerabc
3 Replies

7. UNIX and Linux Applications

Firefox changing hidden filenames

Is firefox changing the filename of this hidden file for anyone else? I tried in firefox 3, 4, and 6. They all got changed when I tried when I downloaded the file. Firefox removed the leading dot that makes the file be hidden. MEGAUPLOAD - The leading online storage and file delivery service (2 Replies)
Discussion started by: cokedude
2 Replies

8. Shell Programming and Scripting

Generate filenames in a loop

Hi all, I want to generate output files in a loop, run the same command on the same input file 1000 times and output in files with a new name each time, maybe a number appended to it. The output will be different each time as I`m sampling randomly from the input file. I want to do the... (3 Replies)
Discussion started by: newbie83
3 Replies

9. UNIX for Dummies Questions & Answers

[Solved] Writing a loop to changing the names of files in a directory

Hi, I would like to write a loop to change the names of files in a directory. The files are called data1.txt through data1000.txt. I'd like to change their names to a1.txt through a1000.txt. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

10. Shell Programming and Scripting

For/While Loop to Increment Filenames in a Script

Daily stupid question. I want to increment the file name everytime the script is run. So for example if the filename is manager.log and I run the script, I want the next sequence to be manager.log1. So to be clear I only want it to increment when the script is executed. So ./script... (10 Replies)
Discussion started by: metallica1973
10 Replies
break(1)                                                           User Commands                                                          break(1)

NAME
break, continue - shell built-in functions to escape from or advance within a controlling while, for, foreach, or until loop SYNOPSIS
sh break [n] continue [n] csh break continue ksh *break [n] *continue [n] DESCRIPTION
sh The break utility exits from the enclosing for or while loop, if any. If n is specified, break n levels. The continue utility resumes the next iteration of the enclosing for or while loop. If n is specified, resume at the n-th enclosing loop. csh The break utility resumes execution after the end of the nearest enclosing foreach or while loop. The remaining commands on the current line are executed. This allows multilevel breaks to be written as a list of break commands, all on one line. The continue utility continues execution of the next iteration of the nearest enclosing while or foreach loop. ksh The break utility exits from the enclosed for, while, until, or select loop, if any. If n is specified, then break n levels. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be exited. The continue utility resumes the next iteration of the enclosed for, while, until, or select loop. If n is specified then resume at the n- th enclosed loop. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be used. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words that follow a command preceded by ** that are in the format of a variable assignment are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign, and also that word splitting and file name genera- tion are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), exit(1), ksh(1), sh( 1), attributes(5) SunOS 5.10 17 Jul 2002 break(1)
All times are GMT -4. The time now is 09:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy