Filed under: Linux, Tips, Ubuntu | Tags: CentOS, CLI, directory size, linux, ubunty
It seems like a simple request…and it mostly is. But if you want to get the size of a folder – including sub-folders – in Linux from the command line, you need to use the du command. The simplest trick (thanks linuxforums.org) to get the total size without listing all the sub-folders is to use the following:
du -h | grep -v '/' | awk '{print $1}'
One of the annoying things about Ubuntu is the fact that you need to be an admin user to shutdown the PC. This makes sense if you are running a server, but not when you have a few PCs scattered throughout the house that you’d just like to shutdown quickly.
So, I found a way to enable this through Apache. Warning: this will allow anyone who browses to your PC to shut it down without prompting. So use carefully.
Basically, what you need to do is remove the need for admin/sudo access when shutting down as the www-data (Apache) user. To do this, you use a specific command called visudo which specially edits a file containing what commands require admin access.
In short, make sure that the last line in that file is the following:
www-data ALL= NOPASSWD: SHUTDOWN_CMDS
and that there is a line further up that says Cmnd_Alias SHUTDOWN_CMDS = /sbin/shutdown, /sbin/reboot, /sbin/halt.
Then, once this is done, you can have a shutdown.php that has the following code:
<?php
echo exec('sudo shutdown -h now');
?>
Q.E.D.
So, after some pretty massive renovations, I now have Cat-5E cable throughout the house. Sweet.
I also have a need to somehow get the feed from my Sky box upstairs to the TV downstairs so the younglings can watch Playhouse Disney. In the past, I’ve done this through ye ol’ UHF backfeed, but the new HD box doesn’t allow that without an RF modulator.
What to do? Oh, well I do have an Xbox softmodded with XBMC downstairs. And I do have a Shuttle running Ubuntu with a Hauppauge PVR-150 TV card beside the Sky box upstairs. How abouts a little VLC streaming?
I’ve added the following line of code to my
/etc/rc.local
file on the Shuttle:
su [A NON-ROOT USER] -c "vlc pvr:// :pvr-device=/dev/video0 :pvr-norm=0 --sout '#standard{access=http,mux=ts,dst=[IP ADDRESS OF SHUTTLE]:8080}' --daemon"
Then, on my XBMC install, I have a file called
Sky.strm
which has this one simple line in it:
http://[IP ADDRESS OF SHUTTLE]:8080
and is sitting under the Playlists folder in the Videos directory of my UserData folder. When I go and select it, after a couple of seconds I get full MPEG-2 streaming across my network!
I can also access the stream from any VLC player on my other machines too.
Super sweet!
EDIT: After upgrading to 10.04, I inexplicably needed to add the line :pvr-channel=2 to make this pick up more than static.
This is a simple trick, but a good ‘un: if you’re wanting to hunt through the bash shell history of commands (i.e. what appears when you press the up key), use the
history
command. To search for a specific phrase, use
history | grep [phrase]
.
For more, better detail, check out this link.
Had to fix a Windows box at the weekend with a failing hard drive. So I bought a new hard drive, slapped it in the box, booted an Ubuntu live CD and followed these instructions to copy the Windows partitions across to the new drive. It now boots off the new disk – no problems.
Sweet!
I’m just discovering the usefulness of smbclient and this link has a great summary of the commands you can fire through this tool from the terminal.
Probably the most common one I need to do is to use the tarmode to copy whole folders down, like so:
tarmode
lcd /tmp #this switches the local directory
recurse
prompt
mget pdf995/ #this recurses and tars the pdf995 remote directory and puts it in /tmp on the client
This one bugged me for ages, and it’s still not something you can completely remove, but if you are using Ubuntu or a Gnome desktop as, say, a media centre, you may not want to have the Gome panel/bar appearing at all.
The current best solution is to use gconf-editor to set the auto_hide_size of the panel you want to change (under /apps/panel/toplevels/[panel name]) to 1. Then make sure the “auto hide” option is checked and voila – pretty much gone.
So, there’s this very well documented bug with all versions of Ubuntu where the network connection is dropped before any set Samba shares are unmounted. This results in annoying “CIFS error 50″ type timeout issues.
It’s unbelievable that this still isn’t fixed in Jaunty, and I’ve never really got the workarounds working. But the most common is to move the unmounting command up the stack of priorities when shutting down or suspending. To do this, as The World shows:
ln -s /etc/init.d/umountnfs.sh /etc/rc0.d/K15umountnfs.sh
ln -s /etc/init.d/umountnfs.sh /etc/rc6.d/K15umountnfs.sh
I’m still working through the kinks on this one, but this post on Ubuntu forums seems to give good instructions for setting up one of the servers in my house as the only one to download update packages for apt, while the others point to it (saving me bandwidth costs).
I’ll post more as I figure it out, but this line is key for the other machines:
echo 'Acquire::http::Proxy "http://hostname:3142";' | sudo tee /etc/apt/apt.conf.d/01proxy

Seems like a silly little thing, but I do a lot of copying and pasting from Visio and other graphical apps into Word and other Office apps. So, I’ve started to write some macros to speed this up. Here’s the one for PowerPoint:
Sub PasteEMF()
ActivePresentation.Slides(ActiveWindow.Selection.SlideRange.SlideIndex).Shapes.PasteSpecial (ppPasteEnhancedMetafile)
End Sub
