LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   rename photos hidden (https://www.linuxquestions.org/questions/linux-software-2/rename-photos-hidden-4175447295/)

Pedroski 01-26-2013 06:27 AM

rename photos hidden
 
Ermmm, how shall I put this? My girlfriend is in Germany. She sent me some photos of herself, lightly clad. I'd like to batch rename them with . in front so they are not generally visible for anyone using this computer.

Some bash command like rename /pics/.babypics/*.jpg .*.jpg

How can I do this?

catkin 01-26-2013 07:06 AM

Something like
Code:

cd  /pics/.babypics || exit 1
for f in *.jpg
do
    echo mv "$f" ".$f"
done

When you are confident it is generating the mv commands you want, remove the echo.

EDIT: but it would be better to use permissions rather than -- or as well as -- obscurity. The same loop with chmod 600 "$f" would do it.

Pedroski 01-26-2013 07:24 AM

Hey thanks! It's just sometimes, not very often other people use my laptop. I'd rather they didn't see her pics by accident, even though they are not exactly pornos! Using Ubuntu, with this thing called dash, I nearly showed them to a whole classroom full of students recently! Dash keeps a record of recently used files and puts a thumbnail up! Luckily, the overhead projector had gone to sleep!! But it won't show them if they are hidden!

catkin 01-27-2013 02:23 AM

Ah, OK. Then making them hidden is good enough for your needs.

Threads can be marked SOLVED via the Thread Tools menu.

Pedroski 01-28-2013 10:59 PM

Having trouble with that, do you know what's wrong? Ihad to ctrl c to stop the terminal, it just sat there!
pedro@pedro-bedro:~/MyStuff/.bilder$ dir
14 20130126087.jpg 20130126093.jpg 20130126098.jpg
15 20130126090.jpg 20130126097.jpg 20130126099.jpg
pedro@pedro-bedro:~/MyStuff/.bilder$ for f in *.jpg do echo mv "$f" ".$f" done> ^C
pedro@pedro-bedro:~/MyStuff/.bilder$ ./for f in *.jpg do echo mv "$f" ".$f" done
bash: ./for: No such file or directory
pedro@pedro-bedro:~/MyStuff/.bilder$ ./ for f in *.jpg do echo mv "$f" ".$f" done
bash: ./: Is a directory
pedro@pedro-bedro:~/MyStuff/.bilder$ for f in *.jpg do echo mv "$f" ".$f" done> ^C
pedro@pedro-bedro:~/MyStuff/.bilder$

chrism01 01-29-2013 01:50 AM

That's probably because cmds in bash are newline separated. If you put them all on one line, you need some sort of separator.
Try it on multiple lines are per the example in a shell script.

Alternately (just for fun) you can enter one line, then hit enter and you'll get an editor continuation symbol thus '>' eg
Code:

# This written one line at a time, then <enter>
for f in *.jpg
> do
> stuf
> done

# this is what the result looks like if you recall it (ie up-arrow). note the auto-inserted ';'s
for f in *.jpg; do stuf; done


Pedroski 01-29-2013 02:03 AM

Aha, so if I hit enter, instead of bash doing the command it will take the next command?

How can I enter the script then run it on the command line?? Write it with gedit, put it in the directory, then run it? Or can this be done fromthecommand line? Just for future reference!

Ha, worked like a dream, just needed the ;

Thanks!
pedro@pedro-bedro:~/MyStuff/.bilder$ for f in *.jpg; do echo mv "$f" ".$f"; done
mv 20130126087.jpg .20130126087.jpg
mv 20130126090.jpg .20130126090.jpg
mv 20130126093.jpg .20130126093.jpg
mv 20130126097.jpg .20130126097.jpg
mv 20130126098.jpg .20130126098.jpg
mv 20130126099.jpg .20130126099.jpg
pedro@pedro-bedro:~/MyStuff/.bilder$

Pedroski 01-29-2013 03:07 AM

I spoke too soon: nothing happened! When I looked in the folder /home/pedro/MyStuff/.bilder,the photos are there, names unchanged!

Something is not working!!

pedro@pedro-bedro:~/MyStuff/.bilder$ for f in *.jpg; do echo mv "$f" ".$f"; done;
mv 20130126087.jpg .20130126087.jpg
mv 20130126090.jpg .20130126090.jpg
mv 20130126093.jpg .20130126093.jpg
mv 20130126097.jpg .20130126097.jpg
mv 20130126098.jpg .20130126098.jpg
mv 20130126099.jpg .20130126099.jpg
pedro@pedro-bedro:~/MyStuff/.bilder$ dir
14 20130126087.jpg 20130126093.jpg 20130126098.jpg
15 20130126090.jpg 20130126097.jpg 20130126099.jpg
pedro@pedro-bedro:~/MyStuff/.bilder$

H_TeXMeX_H 01-29-2013 03:46 AM

Quote:

Originally Posted by Pedroski (Post 4879670)
I spoke too soon: nothing happened! When I looked in the folder /home/pedro/MyStuff/.bilder,the photos are there, names unchanged!

Something is not working!!

pedro@pedro-bedro:~/MyStuff/.bilder$ for f in *.jpg; do echo mv "$f" ".$f"; done;
mv 20130126087.jpg .20130126087.jpg
mv 20130126090.jpg .20130126090.jpg
mv 20130126093.jpg .20130126093.jpg
mv 20130126097.jpg .20130126097.jpg
mv 20130126098.jpg .20130126098.jpg
mv 20130126099.jpg .20130126099.jpg
pedro@pedro-bedro:~/MyStuff/.bilder$ dir
14 20130126087.jpg 20130126093.jpg 20130126098.jpg
15 20130126090.jpg 20130126097.jpg 20130126099.jpg
pedro@pedro-bedro:~/MyStuff/.bilder$

The right command should be:

Code:

for f in *.jpg; do mv "$f" ".$f"; done

Pedroski 01-29-2013 04:08 AM

Yeah thanks. After I read the thead again, I figured I should blip 'echo', and then it worked ok. Sorry, computers are not my thing!


All times are GMT -5. The time now is 10:22 PM.