LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-26-2013, 06:27 AM   #1
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 14.04
Posts: 1,340

Rep: Reputation: 42
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?
 
Old 01-26-2013, 07:06 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,539
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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.

Last edited by catkin; 01-26-2013 at 07:10 AM.
 
Old 01-26-2013, 07:24 AM   #3
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 14.04
Posts: 1,340

Original Poster
Rep: Reputation: 42
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!
 
Old 01-27-2013, 02:23 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,539
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Ah, OK. Then making them hidden is good enough for your needs.

Threads can be marked SOLVED via the Thread Tools menu.

Last edited by catkin; 01-27-2013 at 02:25 AM. Reason: Speeling
 
Old 01-28-2013, 10:59 PM   #5
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 14.04
Posts: 1,340

Original Poster
Rep: Reputation: 42
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$
 
Old 01-29-2013, 01:50 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
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
 
Old 01-29-2013, 02:03 AM   #7
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 14.04
Posts: 1,340

Original Poster
Rep: Reputation: 42
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$

Last edited by Pedroski; 01-29-2013 at 03:04 AM.
 
Old 01-29-2013, 03:07 AM   #8
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 14.04
Posts: 1,340

Original Poster
Rep: Reputation: 42
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$
 
Old 01-29-2013, 03:46 AM   #9
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
Quote:
Originally Posted by Pedroski View Post
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
 
Old 01-29-2013, 04:08 AM   #10
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 14.04
Posts: 1,340

Original Poster
Rep: Reputation: 42
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] rename HIDDEN files recursively mrmnemo Linux - Software 26 09-17-2012 05:20 AM
Bash script to rename photos in directory & all subdirectories shy_guest Linux - Software 7 09-02-2009 01:40 PM
Bash script to rename photos in directory & all subdirectories shy_guest Linux - Software 2 09-02-2009 05:53 AM
Bash script to rename photos in directory & all subdirectories shy_guest Linux - Software 1 09-02-2009 05:28 AM


All times are GMT -5. The time now is 03:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration