Fix file (644) and directory (775) permissions in Linux easily

A few weeks back I was sorting out the drives on my Linux server and as some of the directories were created through various configurations of Samba by Windows clients the permissions were a bit odd. Some archive files were executable, some directories were rw only for the owner. You get the idea, it was a mess. How do I fix them quickly?

I’d like all the files to be 0644 and directories should be 0775 please. Oh, and I’d like all that done with the minimum of fuss through a Bash shell, with or without a cherry on top.

Luckily I’m not the first person to ask this as user stress_junkie in this thread had an answer:

For directories only do this.

find . -type d -exec chmod 775 {} \;

For files only do this.

find . -type f -exec chmod 644 {} \;

There’s also this useful chunk of code to avoid hitting . and .. but I didn’t care about that in my case so the above code worked perfectly:

find . -type d -name \* -exec chmod 775 {} \;

And finally, user Gethyn pointed out that this command will add execute permissions to directories.

chmod -R +X

I have a feeling I’ll be coming back to this post in the future, just like I’ve had to check my directory comparison post a couple of times recently.

Do more with your old MacBook

Have you got an old MacBook that Apple doesn’t support any more? Can’t install the latest and greatest version of Mac OS X on it because the CPU is too old? You’re probably seeing a warning from Chrome that Google has discontinued support for Mac OS X 10.5.3 or whatever is on that ancient beast? It’s the same with Firefox.

Flash isn’t updated either and when you go to Youtube to watch a video Chrome shows you an ugly warning that it’s outdated. Frustrating isn’t it?

What’s more, you’re probably leaving yourself open to exploits by nasties on the Internet. Problems and bugs are found in Flash all the time. Browsers and operating systems are the same too but if that software isn’t actively updated then you’re out of luck. I discovered Opera browser is still built for these old machines and it’s fast but Flash was still a problem and I needed a better solution.

As unlikely as it may seem on an Apple computer, it’s Linux that came to the rescue!

I didn’t think I could put Linux on the MacBook as there was no Bootcamp to dual boot the machine. Thanks to I found the MacBook help pages for Ubuntu which pointed me towards rEFIt, a “boot menu and maintenance toolkit for EFI-based machines like the Intel Macs.” Even on an old MacBook 4,1 I could install Linux!

Installing rEFIt was simple enough, just run the package installer when I mounted the .dmg file. However the boot menu didn’t appear, even after several reboots until I pressed down ALT while rebooting.

Partitioning was a problem. I used the command line diskutil tool as suggested here but ran into problems because it couldn’t do a live resize. It would report that it ran out of space or there were too many deep links. Luckily the Ubuntu install CD comes with Gparted and after booting into the live CD I ran that and freed up 40GB of space for my new Linux install. A couple of reboots later to verify everything was working and then on to Linux!

Thankfully I didn’t run into the problems a recent Ars reviewer of Ubuntu Linux 12.10 came across. Linux installs are getting simpler and simpler. I told it to install alongside Mac OS X and let it set up partitions.

The WIFI adaptor in the Macbook requires a proprietary driver and after hooking the laptop up to an ethernet cable I started updating packages. While doing that I looked in the System settings and discovered that Ubuntu had installed the right driver without my prompting! I’m not sure when that happened but WIFI has been rock solid since.

Time to install Opera, the restricted packages (mp3 and dvd playback, etc), Java for Minecraft and finally Minecraft. Getting a Minecraft icon for Unity was a pain and I can’t find the script I used now but some quick Google-fu will find it.

Linux on the MacBook is nice and fast, even with Unity on there. I may replace that with a lighter window manager if it becomes a problem but it’s much improved on older releases. If you have an old MacBook and you don’t need some proprietary software that isn’t available for Linux then you should definitely put Linux on there. You’ll have the security of using updated software and a nice new desktop and apps to play around with!

Bash: compare two directories

In Unix based systems like Linux and Mac OS X there are a number of ways of comparing two directories. The simplest way is to use diff:

diff –brief -rb directory_1 directory_2

This command compares each file and reports if they differ. You can find the meanings of the options in man diff.

Diff is fine if you’re on a fast drive, if there aren’t many files or the files aren’t big. The command compares the contents of each file so it can take quite some time on a slow external drive.

If you just want to know which files are in one directory and not in the other directory it’s overkill. This little bit of Bash scripting does that however:

diff <(cd dir1 && find | sort) <(cd dir2 && find | sort)

It still uses diff, but compares the file listing of each directory instead of the files. It’s much faster and perfect for figuring out what files are out of place on my 2 relatively slow USB drives. (source)

Where does Nautilus store it’s folder share info?

Using a GUI is nice and all but sometimes I want to know where configuration data is stored.

The Gnome file manager, Nautilus, allows Linux users to share folders on a Windows network. Users of other operating systems will find this hard to believe but before this it was difficult to do as you needed to be an administrator and edit a configuration file called /etc/samba/smb.conf (Users of other desktop managers use similar tools).

This was convenient but I wanted to know where Nautilus puts this configuration data. I searched my home directory, I looked in /etc/samba/ (just in case) and eventually found this page:

I located the config files.

It appears as though /var/lib/samba/usershares holds a text file for each share that has been created.

The usershares directory is owned by root:sambashare and the files inside are owned by the user sharing the folder, so I guess it’s a compromise between a system process (Samba) and users wanting to configure it.

Editing those files is simple, and I guess I could use “net usershare” too. I had to restart Samba too which probably wouldn’t be needed if I had use the “net” command.

Mount drives in Linux

I was one of the lucky few to receive a 50GB upgrade from, (or where they now live, marketing fail?) when I installed their Android app. I don’t have a use for that much storage on my phone but on my desktop machines? Oh yes!

This forum post describes in detail how to mount a Box drive on a Debian/Ubuntu machine although the instructions will mostly apply to other systems too as long as they have the davfs2 package.

There is a gotcha. Instead of using you can use which is a good gotcha. Also, I’m not the only person to notice that the mount point has a lot less storage than I thought it would have. It should be 50GB total but this is what I see from df -h: 26G 13G 13G 50% /mnt/

It’s enough for my needs. I’m going to copy snapshots of my local email there every night.

PS. Are you a Windows user? Sync any folder with Google Drive using the instructions here (but it uses “hardlinks” which have limitations, read the comments for more).
Actually, forget what it says in that post. Copy your files to your Google Drive and then place a symlink on your local drive to the copied files or folders using mklink. Make sure you run cmd.exe as an Administrator. I found this worked perfectly to sync the Pictures folder after I had copied it to my Google Drive:

cd c:\Users\USERNAME\
mklink /d Pictures “c:\Users\USERNAME\Google Drive\Pictures”

Any files copied into the Pictures folder are copied to the Google Drive now!

Scroll like you mean it in Windows

One of the most annoying aspects of Windows after using Linux on the desktop for 10+ years was how the mouse wheel scrolled windows.

On Linux desktops I could hover over a window and scroll it without focusing. It was really useful when I had a browser window with instructions behind a terminal or just comparing the contents of two windows. The same happened when scrolling panes in file managers. I could scroll directories when hovered over that side of the window and files when over on the other..

So, imagine my frustration when I realised I had to click the side of the Explorer window I wanted to scroll in Windows? It was doubly annoying if I had selected files as I’d have to click an empty area or CTRL click an already selected file to select that side of the window.

Well, there’s a simple solution. Alex Leonard found and blogged about Wizmouse. It simply does what I expect, it scrolls the window under my pointer, whether it’s focused or not.


Install Ubuntu on your Android Phone

With this app you can install Ubuntu on your Android phone. It has to be rooted obviously and it’s definitely not this.

It looks like this installs Ubuntu in the same way as in the video above. It’s an app that runs in the background and you use a VNC client to connect to it. You could of course use VNC on a local desktop machine to connect to it too making it more useful but I think this is more a curiosity for those who like to tinker with their phones …

Pity he couldn’t get WordPress running on that Ubuntu install. That would have been fun to see!

Howto: Install XFCE in Ubuntu 11.10

You realise how spoiled you are by the ease at which software can be installed in Linux only when you’ve done the same in Mac OS X or Windows. apt-get or aptitude will install a wide variety of software and in the case of aptitude will remove the software and all it’s dependencies afterwards.

Yeah, I’m saying goodbye to Unity and embracing XFCE (for the moment at least. Choice is good!)

# aptitude install xfce4 xfce4-goodies
The following NEW packages will be installed:
desktop-base{a} exo-utils{a} gtk2-engines-xfce{a} hddtemp{a} libexo-1-0{a} libexo-common{a} libexo-helpers{a} libgarcon-1-0{a} libgarcon-common{a} libkeybinder0{a} libtagc0{a} libthunar-vfs-1-2{a}
libthunar-vfs-1-common{a} libthunarx-2-0{a} libtumbler-1-0{a} libxfce4ui-1-0{a} libxfce4util-bin{a} libxfce4util-common{a} libxfce4util4{a} libxfcegui4-4{a} libxfconf-0-2{a} lm-sensors{a} mousepad{a}
orage{a} ristretto{a} squeeze{a} tango-icon-theme{a} thunar{a} thunar-archive-plugin{a} thunar-data{a} thunar-media-tags-plugin{a} thunar-volman{a} tumbler{a} tumbler-common{a} xfburn{a}
xfce-keyboard-shortcuts{a} xfce4 xfce4-appfinder{a} xfce4-artwork{a} xfce4-battery-plugin{a} xfce4-clipman{a} xfce4-clipman-plugin{a} xfce4-cpufreq-plugin{a} xfce4-cpugraph-plugin{a}
xfce4-datetime-plugin{a} xfce4-dict{a} xfce4-diskperf-plugin{a} xfce4-fsguard-plugin{a} xfce4-genmon-plugin{a} xfce4-goodies xfce4-mailwatch-plugin{a} xfce4-mixer{a} xfce4-mount-plugin{a}
xfce4-netload-plugin{a} xfce4-notes{a} xfce4-notes-plugin{a} xfce4-panel{a} xfce4-places-plugin{a} xfce4-power-manager{a} xfce4-power-manager-data{a} xfce4-quicklauncher-plugin{a} xfce4-screenshooter{a}
xfce4-sensors-plugin{a} xfce4-session{a} xfce4-settings{a} xfce4-smartbookmark-plugin{a} xfce4-systemload-plugin{a} xfce4-taskmanager{a} xfce4-terminal{a} xfce4-timer-plugin{a} xfce4-utils{a}
xfce4-verve-plugin{a} xfce4-volumed{a} xfce4-wavelan-plugin{a} xfce4-weather-plugin{a} xfce4-xkb-plugin{a} xfconf{a} xfdesktop4{a} xfdesktop4-data{a} xfwm4{a} xfwm4-themes{a} xscreensaver{a}
0 packages upgraded, 82 newly installed, 0 to remove and 0 not upgraded.
Need to get 40.9 MB of archives. After unpacking 144 MB will be used.
Do you want to continue? [Y/n/?] y

Once installed, logout and select XFCE from the login menu.

XFCE has it’s own quirks and gotchas but it feels lighter and more responsive than Unity. The most difficult part was making the top menu bar autohide. I had to remove the “running programmes” list to get at the panel preferences. Only later did I notice the “Panel” item when you right click some of the menu widgets. The full screen mode in Gnome Terminal gets me back the extra 2-3 lines of terminal I missed. So winning all around as a certain actor once said …

Installing Gnome 3.2 is just as easy and looks gorgeous!

aptitude install gnome-shell

Open large files in Vim with care

If you want to load a large file in Vim you should disable the swap file to speed things up. It’s simple to do as well:

Vim -n file.txt

If a file is over 4096K or so and I have enough system RAM (not usually a problem) I’ll do it this way as it avoids Vim creating a potentially huge .swp file.

Ubuntu: ALT TAB between browser windows?

I’m still using Ubuntu’s Unity desktop, which is saying a lot as I switched back to Gnome within a week or so of the previous release of Ubuntu.

One of the remaining bugbears I had with Unity was the window or task switcher. It was impossible to switch between Chrome browser windows. I had to click on the Chrome icon in the Unity sidebar and select the window I wanted. It felt like Ubuntu had tried to emulate what Windows 7 did with their taskbar, but Windows did it better because the window previews are close to the taskbar.

I’m not the only one to have this problem. You can either change window switcher in CCSM (oh oh, watch out when using CCSM!) or use ALT-`. That character is the tick character which normally sits above the TAB key on UK/English/US keyboards but may be elsewhere on other locales. I now need to get used to it like I did with Mac OS X.