LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 12-20-2016, 10:43 AM   #1
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Rep: Reputation: Disabled
Change folder permissions


I created a variable:

current_folder = mkdir $(date "+%Y%m%d")

Then tried to change to folder permissions:

chmod 777 /export/home/eric/$current_folder

and got an error in a script. What am I doing wrong?
 
Old 12-20-2016, 10:52 AM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Use code tags, what error?
Hint this:
Code:
current_folder = mkdir $(date "+%Y%m%d")
Is completely the wrong syntax.

Last edited by Keith Hedger; 12-20-2016 at 10:54 AM.
 
Old 12-20-2016, 10:57 AM   #3
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Well, I'm using a 3rd party application to run the script so it's kinda generic. When running these commands manually at the command prompt I get this error:

-bash: current_folder: command not found

I thought I was defining the variable right
 
Old 12-20-2016, 11:01 AM   #4
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
No, you cant assign the o/p of mkdir to a variable like that, also no spaces around the '=' sign.
Try
Code:
current_folder=$(date "+%Y%m%d")
mkdir "$current_folder"
This assigns the output of the date command to the variable then passes the contents to the mkdir command creating the folder.
 
1 members found this post helpful.
Old 12-20-2016, 11:02 AM   #5
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
the mkidr command will also fail with an error if the folder already exists so you will need to either check first or handle the error or your script will fall over.
 
1 members found this post helpful.
Old 12-20-2016, 12:11 PM   #6
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Thank you Keith...problem solved!!!

Also how do I change the folder permissions to 777?

Last edited by trickydba; 12-20-2016 at 12:14 PM.
 
Old 12-20-2016, 12:24 PM   #7
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I figured it out:
chmod 777 /export/home/eric/${current_folder}
 
Old 12-20-2016, 12:52 PM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Quote:
Originally Posted by trickydba View Post
I figured it out:
chmod 777 /export/home/eric/${current_folder}
Except those permissions are almost certainly incorrect. My guess is that you mean either 1777 or 755 or 750, depending on who is supposed to be able to read and write the folder. Who is supposed to be able to read the folder? Who is supposed to be able to write to the folder?
 
1 members found this post helpful.
Old 12-20-2016, 01:45 PM   #9
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@Turbocapitalist............Im the only one that's supposed to write and read.
 
Old 12-20-2016, 01:51 PM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
If you are the only one then you'll want 750 or 700. Check the manual page for chmod and take a quick look at this page:

https://www.digitalocean.com/communi...ux-permissions

Between the two they should give an idea about how to read (and write) the permissions and get them to do what you intend.
 
Old 12-20-2016, 01:56 PM   #11
derekawilson72
LQ Newbie
 
Registered: Jul 2014
Location: New York City
Distribution: CENTOS 6.8
Posts: 4

Rep: Reputation: Disabled
You could also take care of it with one liner as follows:

mkdir --mode=777 $(date "+%Y%m%d")
 
2 members found this post helpful.
Old 12-20-2016, 02:40 PM   #12
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
didn't know you could set the mode at the same time you create the folder with mkdir, you learn something new every day!
 
  


Reply



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
change folder permissions hoinongdan Linux - Server 1 10-02-2015 08:19 AM
Change folder permissions kais1 Linux - Newbie 7 03-22-2013 10:21 AM
how to change folder permissions in fc-6 chryslercirrus99 Fedora 3 06-07-2007 06:32 PM
[SOLVED] How can you change permissions on a folder for other users? StefanP Linux - Newbie 2 04-25-2007 01:46 PM
Change folder permissions eggoz Linux - Newbie 2 03-17-2003 01:35 AM

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

All times are GMT -5. The time now is 09:59 PM.

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
Open Source Consulting | Domain Registration