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.
You user directories have a '$' at the start of the directory name, or these are variable which hold the names of the users?
Also, it is typical to have a directory called /home which contains a sub-directory for each user on the system. If the user already exists, /home/<username> should already exist. You want to create a sub-directory inside this called "home" (e.g. /home/bob/home)? That seems perverse.
You should make sure that you set the owner of the directories you create so that they are owned by the users which you are creating them for. Unless you do this, the users will likely not be able to use the directories you make.
Here's an example with what I think makes a more sane description of the problem:
Problem: I have three users on my system, "bob", "connie" and "stang". Their home directories are in the usual place (i.e. /home/bob /home/connie and /home/stang).
In each of their home directories, I want to make a sub-directory called "documents", and another called "music". How can I do this so they can use these directories?
Answer. Log in as root and do this (# is the root prompt here):
Code:
# for user in bob connie stang; do
mkdir /home/$user/{music,documents}
chown $user /home/$user/{music,documents}
done
Note that when you create user accounts, you can use the useradd tool with the -m option to copy a "skeleton" user directory for them. See the useradd manual page for more details (search for "skel").
Thanks for the reply, the user thing was a bad example on my part, (I thought it would have been easier to understand).
The reality is I have a bunch of folders (one for each of our customers)
customers/customerA
customers/customerB
In each customer folder there are sub directories labeled "Documentation 2002/captures" "Documentation 2003/captures" etc etc.
In the past everyone creates a new folder for each year for each customer.
What I'm trying to figure it out is how to create the following structure in each customer folder
[mherring@mystical play]$ touch "the file"
[mherring@mystical play]$ ls
garb the file words
[mherring@mystical play]$ for fil in $(ls); do echo $fil;done
garb
the
file
words
[mherring@mystical play]$ for fil in $(ls|sed 's/ /_/'); do echo $fil;done
garb
the_file
words
You can use a loop like this to rename anything that has a space in it, but if you are dealing with directories having the same name as users, that's not going to be a good thing.
In your code, you can simply use SED again to change (from my example) "the_file" back to "the file".
The one thing that jumps out at me is that a pipe (|) requires that the two statements are designed to produce / receive data. For example: "mkdir $fil" does not produce an output that can be piped to anything.
How about:
mkdir $(echo $fil|sed 's/_/ /')
When building something like this, always test the pieces as you go.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.