2

Today I used sudo chmod +x * -R in my $HOME folder, actually I didn't want to use it in $HOME folder, it was an accident. Afterthat I tried to use sudo chmod -x * to fix it. But now, I couldn't open any file in $HOME folder with user permission. I can use root permission to open them. I used ll to check that all files are owned by the user, but why can't I open them? Please help me.

my bash history(in ~/.bash_history):

sudo chmod +x * -R
ll
chmod -x -R *
ll
sudo chmod +x * -R
ll
sudo chmod +w * -R
ll
cd ~/Desktop/
sudo cd ~/Desktop/
sudo chmod -x * 
ll
df -h
ll
cd ~/Desktop/
sudo cd ~/Desktop/
sudo cd /home/nix/Desktop/
sudo chmod -x * -R
ll
cd ~/Desktop/
su
gnome-open 1.png &
sudo gnome-open 1.png &
sudo gnome-open 1.png 
cd 
cd cd skypeFiles/
sudo cd skypeFiles/
ls -a
cd .config/
ls
cd ..
cd .local/
ls
cd share/
ls
cd applications/
ll
chmod +x *
ll
cd ..
chmod +x * -R
su
sudo chown nix:nix -R nix/
ll

At first I tried to chmod -x * to fix it, nothing works. And then I found that I can use sudo gnome-open to open files(while only gnome-open didn't work), I guessed maybe there was something worng with my .desktop files. After I entered .local/share/applications, there was only "mimeapps.list*" here, so maybe I was wrong.

nix@***:~$ ls -la
total 324
drwxr-xr-x 53 nix  nix   4096 Jan  1 14:01 .
drwxr-xr-x  3 root root  4096 Dec 29 21:40 ..
drwx------  3 nix  nix   4096 Dec 29 18:22 .adobe
drwx------  2 nix  nix   4096 Dec 31 21:40 .aptitude
-rw-------  1 nix  nix   9131 Jan  1 14:28 .bash_history
-rw-r--r--  1 nix  nix    220 Apr  9  2014 .bash_logout
-rw-r--r--  1 nix  nix   3870 Dec 29 20:51 .bashrc
-rw-r--r--  1 nix  nix   3870 Dec 29 20:51 .bashrc~

Considering for my privacy, I deleted some result of the command ls -la, for it didn't really matter in this problem.

Jadim
  • 123
  • 5

2 Answers2

4

by running

sudo chmod -x * -R

you just removed execution rights to everything under your current directory, including subdirectories. This should not prevent to open files in the current directory for editing or reading, but this prevents you to open subdirectories and the files inside. You do not have to fiddle with "root" user. Just run the following :

find . -type d

and you should get an error

find: 'xxxxx': Permission denied

for all subdirectories xxxxx in your current directory which name doesn't starts with a "." (dot). To fix, run

find . -type d -exec chmod +x {} +

and your subdirectories access will be restored. You'll then have to set proper execution rights on any formerly executable file in your subdirectories tree. Only you can find which files need it.

muru
  • 193,181
  • 53
  • 473
  • 722
r.g
  • 56
  • 2
  • Thanks. Did you mean `find . -type d -exec chmod +x {}`? – Jadim Jan 01 '15 at 08:02
  • yes, I've edited the original message – r.g Jan 01 '15 at 08:03
  • It works, Thank you! Everything was like what you said. I indeed lost the permission of the subdirectories though I still can access the parent directories. Now I can open any file in the $HOME folder. – Jadim Jan 01 '15 at 08:16
  • I still have a little question, what does `\;` here mean in the last command? – Jadim Jan 01 '15 at 08:26
  • @Nix from `man find` "The semicolon is protected by the use of a backslash from interpretation it as shell script punctuation, though single quotes could have been used in that case also like `';'`". see also [What is the difference between using '+' and '\;' in -exec command?](http://askubuntu.com/q/558817/283843) – αғsнιη Jan 01 '15 at 10:49
-1

Open your terminal and change to root user (else sudo would do)

First take a backup of current home directory of yours.

Then paste as

sudo chown -R youusername:yourusername /home/yourusername

That will again makes you true owner of your home.

Replace yourusername with your username.

let me know if any issues.

Raja G
  • 100,643
  • 105
  • 254
  • 328