LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-15-2013, 10:48 PM   #1
Needsashave
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Rep: Reputation: Disabled
What have I done?


Hi guys,
I was trying to rename files en-masse and prefix them all with a double s. Obviously I wasn't supposed to do it this way;

root@hairybusiness:~/Desktop/staticbins# for file in ./*; do mv $file ss&$file ; done
[1] 13509
[2] 13511

What actually happened here, and if i should reverse it, how?

Last edited by Needsashave; 04-15-2013 at 10:49 PM. Reason: added semicolon i missed
 
Old 04-15-2013, 11:38 PM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
I think one of the last files moved has become ss. Not sure how you could fix that with the other files. You could use a data recovery tool for your filesystem but I'm not sure how successfully it would be.

Since commands were executed asynchronously you can't really tell which file was last moved to become ss, but you could have a bet with the last call. You must have seen messages like "command not found.". The one on the last is probably the last file.
 
1 members found this post helpful.
Old 04-15-2013, 11:48 PM   #3
Needsashave
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Ah,
Now that you mention it, ss is there, but all the other files remain at their original name. Thanks, shouldn't be too hard to find the missing one...
Not sure what the numbers in square brackets are though. Inodes?
 
Old 04-16-2013, 12:23 AM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
A few questions:
  1. You're running test scripts as root?
  2. Your script assumes that your file names will never be split by bash. Is that reasonable?
  3. KDE includes a krename program for bulk file renaming. Does your distribution have a similar program?
  4. Don't you need additional options in your ls command to exclude sub-directories and their children?
  5. Have you considered using the find command's -exec action?
  6. What is the point of the "&" in your mv command? The form ss${file} might be a better choice.
 
1 members found this post helpful.
Old 04-16-2013, 01:14 AM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by Needsashave View Post
Ah,
Now that you mention it, ss is there, but all the other files remain at their original name. Thanks, shouldn't be too hard to find the missing one...
Odd that they're still there after you ran mv on them. Perhaps mv didn't decide to overwrite the new file? If it did then perhaps it's the first called file that was renamed.
Quote:
Not sure what the numbers in square brackets are though. Inodes?
They're job numbers. See JOB CONTROL in bash's manual.
 
1 members found this post helpful.
Old 04-16-2013, 02:44 AM   #6
Needsashave
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Ahhhh job numbers. All making more sense now.

1. Running as root because I long since got sick of sudo & not a critical system.
2. Not sure what splitting files names by bash is. Gonna read up on that.
3. Gnome.
4. There are no children directories.
5. Cool. Didn't know find could do this. Looks like the find -execdir option is good.
6. Didn't work with that syntax either. Getting file not found messages because $file includes the ./ path. Fixed it with;
Code:
for file in ./*; do mv $file ss$(basename $file); done
Thanks for your help guys. Steep learning curve.
 
Old 04-16-2013, 08:19 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,396

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
You got the job numbers because '&' backgrounds the preceding cmd.
Never use it as part of a name or cmd , unless that's the functionality you want.

The nice thing about the 'find' cmd for this would have been that it has a '-type f' option, to only process regular files eg not dirs as well.

Useful links
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
1 members found this post helpful.
  


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



LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration