Absolutely Tech

[HowTo] Suspend Ubuntu from terminal or keyboard shortcuts

When learning to make bash scripts, at one point or other you’d like to know how to suspend your computer from terminal. Well, there are quite some methods available for Ubuntu. You can choose whatever suits your needs. I prefer method 3 (look below).

Method 1:

sudo sh /etc/acpi/sleep.sh force

Method 2:

sudo pm-suspend

This command might not be available in older versions of Ubuntu. It works perfectly fine on Lucid and Maverick.

Method 3:

This command does not require sudo so it might come in handy. For example, you can map it to a keyboard shortcut for easy access.

dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

One thing to notice here is none of the commands I mentioned here will ask your password on resuming. For that you’ll have to lock your computer before suspending. You’ll have to use gnome-screensaver-command --lock before suspending to lock the computer

Create a suspend script:

Open a new file in gedit:

sudo gedit /usr/bin/suspend-comp

Copy and paste the following code and save it:

#!/bin/sh 
sleep $1;
dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

If you want the script to ask for a password on resuming, copy-paste this code instead:

#!/bin/sh 
sleep $1;
gnome-screensaver-command --lock
dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

Add the executable bit:

sudo chmod +x /usr/bin/suspend-comp

Now suspend-comp time-in-seconds can be used in terminal. For example, if I want to have my computer suspended after 20 seconds I can simply type:

suspend-comp 20

Mapping it to keyboard shortcut for easy access:

Go to System->Preferences->Keyboard Shortcuts. Click Add. Type Suspend for Name and suspend-comp 0 in Command field. Click Apply.

Now scroll to the bottom of the list to find Suspend. Click on ‘Disabled’ on the right to ‘Suspend’. Now press any key combination to map the command to it. I used Ctrl+Alt+Shift+s.

Now simply pressing Ctrl+Alt+Shift+s will suspend your computer.

Cheers!

[HOWTO] 5 methods to find out your linux distribution name and version through command line

There are lots of commands to find out your ditribution name and distribution version. Some work on some distros, some work on others. Here are some of the methods:

  • lsb_release -a

  • cat /etc/*release

  • cat /etc/issue

  • cat /proc/version

  • uname -a

One of these methods will surely tell you your linux distribution name and current version.

Cheers!

[HOWTO] Download youtube video from command-line

Linux is awesome and so is the terminal. Things become a lot more easy if you can just type in few commands and get your work done. Downloading youtube video has always been messy with GUI downloaders, browser extensions and web services which claim to give you the download link to that video. Now, you can download it from the terminal using youtube-dl in ubuntu. You can also download and install it in other flavors of linux. The script is written in python.

Install youtube-dl from the official repository in Ubuntu:

sudo apt-get install youtube-dl

To download a video execute the following:

youtube-dl <url>

Example screenshot:

Read the rest of this entry »