I have a directory users which is full of folders named for each user. Within those folders, there is a file called userinfo.csv which I would like to pull out of the folder and into the users. Since every file in the user folder is called userInfo, I want to rename it to include the username which is in the folder. I tried the following but it doesn't work because the username in $dir is the full directory. I'm not that attached to renaming it to the username, I just need to rename it something so that when it moves into users I won't be left with just one file and a bunch of errors.
How can I improve this?
# for every subdirectory, copy userinfo.csv to /users and rename to avoid confusion/errors
for dir in /path/to/users/*/; do
(
cd "$dir" && cp userinfo.csv _$("dir").csv && cp _$("dir").csv /path/to/users/
)
done
userinfo.csvfile identical relative to each user? Is it always/path/to/users/*/userinfo.csvor it can be at any depth under the/path/to/users/folder?$("dir")does?/path/to/users/*/userinfo.csvand @choroba I now realize that $("dir") is the full directory so of course renaming it as such wouldn't have worked.