Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ive just started using linux, and Im trying both Ubuntu and CentOS. So far so good, but I am having a problem renaming files. I've tried the following:
no! I work in an office where we all user Vista, but our servers run linux. The management saw fit to fire 3/4's of the staff on Monday and now they are looking to do some new things. I've sort of been stuck with figuring out how to make it all work, but I cant get these files renamed. Its driving me nutz!!
no! I work in an office where we all user Vista, but our servers run linux. The management saw fit to fire 3/4's of the staff on Monday and now they are looking to do some new things. I've sort of been stuck with figuring out how to make it all work, but I cant get these files renamed. Its driving me nutz!!
Regarding your issue, if I correctly understand you're trying to rename the file .new-account in every user's home to .new-user, right? Keep it simple and use a loop over the files, e.g.
Code:
while read name
do
dir=$(dirname "$name")
echo mv "$name" "$dir/.new-user"
done < <(ls /home/*/.new-account)
I've put an echo in front of the mv command for testing purposes: this will simply echo the command without actually execute it. When you're satisfied with the result, strip out the echo and the trick is done.
find -name .new-account | while read name; do dir=$(dirname "$name") echo mv "$name" "$dir/.new-user" done; < < (ls /home/*/.new-account)
but I get the following error:
-bash: syntax error near unexpected token `<'
I am going to start learning linux properly, and have bookmarked that link you provided. But for now I just need to get these files renamed! Have I written the expression incorrectly above?
Don't use find, don't put a semi-colon after the done statement... just simply try the code I suggested as is. You will see it works!
The syntax
Code:
done < <(ls blablabla)
just passes the output of the ls command to the loop, one line (that is one file name) at a time. It is called process substitution. There are other ways to pass input to a loop, but this has some advantages over the others.
no! I work in an office where we all user Vista, but our servers run linux. The management saw fit to fire 3/4's of the staff on Monday and now they are looking to do some new things. I've sort of been stuck with figuring out how to make it all work, but I cant get these files renamed. Its driving me nutz!!
Sorry, we see a lot of homework questions here and try to help students without actually doing their homework for them.
Just to help you out a little more, the command 'mv' is what you were looking for (and why the script given works), no such thing as 'rename'.
Personally, if I were you I would let the servers flounder until the management realizes they shouldn't have fired the people needed to keep them going.
But welcome to LQ and Linux. Any additional questions, we'll be glad to help.
You might be thinking about the xargs command, which is designed to execute commands that are built-up: in part from whatever appears on the xargs command-line, and in part from whatever it reads from standard-input.
In this case, you might wish to use the for construct of shell-scripting:
Code:
forfnin *.txt; do echo $fn; done;
The block of statements will be repeated for each file in the current (or specified...) directory whose filename matches the pattern *.txt.
The arbitrary symbol ("fn" in this example), which is listed without the "$" the first time, becomes a substitution parameter (with the "$") in the command(s) which lie between do and done.
The placement of semicolons (and the word "do") in the foregoing example is "niggling, arbitrary, but very important." Otherwise it just won't work.
As is so often the case in Linux, "there's more than one way to do it." Not only do you have "shell scripts," but you also have several full-featured programming languages (Perl, PHP, Ruby...) all of which can easily be used to build a command. (That's what the "shebang" at the start of a command-file ... #! ... is all about.)
In this respect, Unix/Linux is so far ahead of Microsoft Win-doze that it takes quite a bit of getting used to. (And it makes Win-doze almost impossible for a Linux maven to "put up with anymore ..." )
Sorry, we see a lot of homework questions here and try to help students without actually doing their homework for them.
Well, you already asked the OP about homework and he replied this is not homework at all. Just a linux newbie question. Giving suggestion about a good reading and a working piece of code, serves to encourage someone to learn. Hopefully.
Thanks so much for all your help guys. This has been a surprisingly welcoming forum for a newbie like myself. I have been sort of timid in approaching linux, but I am seeing its benefits already.
As far as the renaming thing goes, I have a much better idea about it now. Problem is, after I got it done, I then realised that the ".new-account" file isnt in all the directories that I need it to be in! Is there a way I could create a file named .new-account in each directory in /home/*/public_html? I could then run the previous command to change them all to .new-user, and my problems would soon be over.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.