Chủ Nhật, 23 tháng 2, 2014

How to correctly set the CPU frequency in Ubuntu

(NOTE: this article applies to Ubuntu 10.4 – 12.10, for any other system your mileage may vary)
This seems to be a very common problem: under Ubuntu (and many other dists), Linux runs at some fixed speed (usually max or min for the CPU) and you cannot change it. Here is how to fix it:

Lets start with some basics…

1. Install cpufreq utils
sudo apt-get install cpufrequtils
2. Uninstall cpufreqd, since it doesn’t work well with some other software
sudo apt-get remove cpufreqd
3. If you want a graphical tool, try this
sudo apt-get install indicator-cpufreq
At this point it is probably safest to restart your machine. Now, you should be able to set the CPU frequency in the UI (well, after restarting your computer or manually starting indicator-cpufreq). Or from the command line like this:
4. Set current frequency
# This first command locks the frequency to an specific value. 
sudo cpufreq-set -f 1600000     # 1.6 GHz for ever!
You can also choose a “governor”, which is an algorithm that automatically changes the CPU frequency for you:
4.B Set current governor
# This command on the other hand uses a power profile.
# ('powersave', 'performance' and 'ondemand' are common profiles). 
sudo cpufreq-set -g powersave   # set governor to powersave 
You can verify the result by running cpufreq-info (or if you’re old-school using cat /proc/cpuinfo).

… but it doesn’t work!

This sometimes doesn’t work, for one of two reasons. First, your CPU may no be “supported” by Linux. This is pretty uncommon but can actually happen if you have a very odd P4 processor. If that is the case, you are out of luck :(
A more common problem is that the upper and lower frequency limits are set wrong and need to be adjusted. To do this, you must know what frequencies the CPU actually supports. This command lists available frequencies for each CPU (CPU 0 in this example)
5. List supported frequencies
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
3201000 3200000 3100000 3000000 2900000 2700000 2600000 2500000 
2400000 2300000 2200000 2100000 1900000 1800000 1700000 1600000
Next you need to manually adjust the frequency bounds – for each CPU. In my case, the CPU was stuck at 3.2 GHz even in powersave mode, and the reason for that was because the upper and lower frequency limits were both incorrectly set to 3.2 GHz. So I changed the lower bound to 1.6 GHz:
6. Force CPU frequency bound
$ sudo echo 1600000 >  /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq 
# The upper limit is set by writing to scaling_max_freq.
In 12.04 and above (?), this can fail with a “permission denied” (reason: it will run echo as root but re-direct stdout with your normal permissions). Try this if that happens
6.B Force CPU frequency bound (fixed)
$ echo 1600000 | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
Repeat this scheme any time a write operation fails!
Note that you must repeat this for each CPU. You may also need to do this every time the machine reboots (?). I even had a machine that would reset this once every couple of hours so I had to ran it hourly as a cron job…

Adjusting the governor…

Once you have adjusted the frequency bounds, you can set a “governor” to adjust the current frequency automatically.
To check what governors are available, try this:
7. List available governors
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
conservative ondemand userspace powersave performance
On a laptop, you probably want to use ‘powersave’. On a desktop PC, you can go with ‘ondemand’. To activate a governor, you do this:
8. Activate a governor
$ echo powersave >  /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
You can check it has taken effect by doing this:
9. Check current governor
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
powersave
Source: http://blog.tube42.se/?p=1225

Thứ Sáu, 21 tháng 2, 2014

Kích hoạt bộ gõ Tiếng Việt trên Ubuntu 13.10

Vừa qua phiên bản Ubuntu 13.10 đã chính thức phát hành, đối với cộng đồng Linux nói chung thì đây là tin vui bởi Ubuntu 13.10 mang đến nhiều cải tiến đang quan tâm, nhưng đối với cộng đồng Việt thì lại gặp đôi chút rắc rối trong việc kích hoạt bộ gõ Tiếng Việt, cụ thể là app iBus trên Ubuntu 13.10 đã bị thay đổi nên gây đôi chút "mù mịt" cho người dùng.
Để có thể gõ Tiếng Việt trên Ubuntu 13.10 bạn cần cài thêm ứng dụng hỗ trợ Unikey đi kèm với iBus có sẵn trên Ubuntu, mặc dù bản thân Ubuntu đã có phần hỗ trợ gõ Tiếng Việt nhưng rất khó sử dụng. Bạn có thể tìm thấy ứng dụng hỗ trợ Unikey trên hệ thống Ubuntu Software Center.
Kích hoạt bộ gõ Tiếng Việt trên Ubuntu 13.10
 
Sau khi cài xong ứng dụng hỗ trợ, bạn vào Terminal và nhập vào dòng lệnh "ibus restart".
Kích hoạt bộ gõ Tiếng Việt trên Ubuntu 13.10
 
Kế tiếp, bạn vào All Apps và gõ vào từ khóa "Text Entry" để tiến hành thêm ứng dụng hỗ trợ Unikey vào bộ gõ iBus của Ubuntu 13.10
Kích hoạt bộ gõ Tiếng Việt trên Ubuntu 13.10
 
Trên giao diện Text Entery, bấm chuột vào biểu tượng dấu "+" sau đó nhập vào ô tìm kiếm là Vietnamese (Unikey) để tích hợp Unikey vào iBus và nhấn nút Add để thêm vào.
Kích hoạt bộ gõ Tiếng Việt trên Ubuntu 13.10
 
Cuối cùng chỉ cần di chuyển Vietnamese (Unikey) bằng các phím mũi tên bên dưới danh sách sao cho Vietnamese (Unikey) đứng hàng đầu tiên, như thế Ubuntu sẽ hiểu là Vietnamese (Unikey) là bộ gõ mặc định.
Chúc bạn thành công!


Nguồn: GenK.VN

Chủ Nhật, 1 tháng 12, 2013

Installing Node.js via package manager

The packages on this page are maintained and supported by their respective packagers, not the node.js core team. Please report any issues you encounter to the package maintainer. If it turns out your issue is a bug in node.js itself, the maintainer will report the issue upstream.

Gentoo

Node.js is available in the portage tree.
# emerge nodejs

Debian, LMDE

For Debian Wheezy, you have two options:

Build from source

sudo apt-get install python g++ make checkinstall
mkdir ~/src && cd $_
wget -N http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd node-v* #(remove the "v" in front of the version number in the dialog)
./configure
checkinstall 
sudo dpkg -i node_*
Uninstall:
sudo dpkg -r node
In case you get a permission denied on the node executable, an alternative path might be:
umask 0022
./configure
make
checkinstall -D --umask 0022 --reset-uids --install=no
dpkg -i node_*.deb

Backports

Alternatively, you can install nodejs from wheezy-backports. If you rely on having node as an executable, install nodejs-legacy as well.
If you need npm as well, you can get it through the installer
curl https://npmjs.org/install.sh | sudo sh

Ubuntu, Mint, Elementary OS

At Least from Ubuntu 13.04, an old version (0.6.x) of Node is in the standard repository. To install, just run:
sudo apt-get install nodejs
Obtaining a recent version of Node or installing on older Ubuntu and other apt-based distributions may require a few extra steps. Example install:
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
It installs current stable Node on the current stable Ubuntu. Quantal (12.10) users may need to install the software-properties-commonpackage for the add-apt-repository command to work: sudo apt-get install software-properties-common
As of Node.js v0.10.0, the nodejs package from Chris Lea's repo includes both npm and nodejs-dev.
There is a naming conflict with the node package (Amateur Packet Radio Node Program), and the nodejs binary has been renamed fromnode to nodejs. You'll need to symlink /usr/bin/node to /usr/bin/nodejs or you could uninstall the Amateur Packet Radio Node Program to avoid that conflict.

openSUSE & SLE

Node.js stable repos list. Also node.js is available in openSUSE:Factory repository.
Available RPM packages for: openSUSE 11.4, 12.1, Factory and Tumbleweed; SLE 11 (with SP1 and SP2 variations).
Example install on openSUSE 12.1:
sudo zypper ar http://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_12.1/ NodeJSBuildService 
sudo zypper in nodejs nodejs-devel

Fedora

Node.js and npm are available in Fedora 18 and later. Just use your favorite graphical package manager or run this on a terminal to install both npm and node:
sudo yum install npm

RHEL/CentOS/Scientific Linux 6

Node.js and npm are available from the Fedora Extra Packages for Enterprise Linux (EPEL) repository. If you haven't already done so, firstenable EPEL.
To check if you have EPEL, run
yum repolist
if you don't see epel, download it (At the time of this writing, the last version is 6.8.)
curl -O http://download-i2.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
then install it
sudo rpm -ivh epel-release-6-8.noarch.rpm
And then run the following command to install node and npm:
sudo yum install npm --enablerepo=epel

Arch Linux

Node.js is available in the Community Repository.
pacman -S nodejs

FreeBSD and OpenBSD

Node.js is available through the ports system.
/usr/ports/www/node
Development versions are also available using ports
cd /usr/ports/www/node-devel/ && make install clean
or packages on FreeBSD
pkg_add -r node-devel

OSX

Using a package
Simply download Macintosh Installer.
Using homebrew:
brew install node
Using macports:
port install nodejs  

Windows

Using a package
Simply download Windows Installer.
Using chocolatey to install Node:
cinst nodejs  
cinst nodejs.install

Source: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

Thứ Năm, 14 tháng 11, 2013

How To Add and Delete Users on Ubuntu 12.04 and CentOS 6

When you log into a new freshly spun up droplet, you are accessing it from the root user. Although this gives you the power to make any changes you need on the server, you are much better off creating another new user with root privileges on the virtual private server. Additionally, if other people will be accessing the virtual server, you will need to make new users for them as well. This tutorial will go over creating a new user, granting them root privileges, and deleting users.

When you perform any root tasks with the new user, you will need to use the phrase “sudo” before the command. This is a helpful command for 2 reasons: 1) it prevents the user making any system-destroying mistakes 2) it stores all the commands run with sudo to a file where can be reviewed later if needed. Keep in mind however, that this user is as powerful as the root user. If you only need a user for a limited number of tasks on the VPS, you do not need to give them root privileges. 

Setup


This tutorial requires access to the root user or a user with sudo privileges. 

You should have received your root password from the welcome email after you launched your droplet.

Users on Ubuntu 12.04


How to Add a User on Ubuntu 12.04


To add a new user in Ubuntu, use the adduser command, replacing the “newuser” with your preferred username.
sudo adduser newuser

As soon as you type this command, Ubuntu will automatically start the process:
  • Type in and confirm your password

  • Enter in the user’s information. This is not required, pressing enter will automatically fill in the field with the default information

  • Press Y (or enter) when Ubuntu asks you if the information is correct

Congratulations—you have just added a new user. You can log out of the root user by typingexit and then logging back in with the new username and password.

How to Grant a User Root Privileges


As mentioned earlier, you are much better off using a user with root privileges.

You can create the sudo user by opening the sudoers file with this command:
sudo /usr/sbin/visudo

Adding the user’s name and the same permissions as root under the the user privilege specification will grant them the sudo privileges.
# User privilege specification
root    ALL=(ALL:ALL) ALL 
newuser ALL=(ALL:ALL) ALL

Press ‘cntrl x’ to exit the file and then ‘Y’ to save it.

How to Delete a User


Should you find that you find that you no longer want to have a specific user on the virtual private server you can delete them with a single command.
sudo userdel newuser

Finish up by the deleting the user’s home directory:
 sudo rm -rf /home/newuser



Users on CentOS 6


How to Add a User on CentOS 6


To add a new user in CentOS, use the adduser command, replacing the “newuser” with your preferred username.
sudo adduser newuser

Follow up by providing the user with a new password, typing and confirming the new password when prompted:
sudo passwd newuser

Congratulations—you have just added a new user and their password. You can log out of the root user by typing exit and then logging back in with the new username and password.

How to Grant a User Root Privileges


As mentioned earlier, you are much better off using a user with root privileges.

You can create the sudo user by opening the sudoers file with this command:
sudo /usr/sbin/visudo

You will find the section to make the user privilege modifications at the bottom of the file. Type “a” to start inserting text. Adding the user’s name and the same permissions as root under the the user privilege specification will grant them the sudo privileges.
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
newuser ALL=(ALL)       ALL

Save and Exit the file by press “shift” ZZ. 

How to Delete a User


Should you find that you find that you no longer want to have a specific user on the virtual private server you can delete them with a single command.
sudo userdel newuser

You can add the flag “-r” to the command if you would like to simultaneously remove the users’s home directory and files.
sudo userdel -r newuser

Next Steps


Once you have set up the users will you need, you can start building up your VPS. A good place to start is to install the LAMP stack (a collection of basic web server software) on your droplet, using the tutorials below. 

LAMP on Ubuntu 12.04 

LAMP on CentOS 6



By Etel Sverdlov

How to use FTP from the command line.

FTP (File Transfer Protocol) allows you to transfer files between your PC and other Internet systems (hosts). You can transfer files, work with local or remote directories, rename and display files, and execute system commands. Before you start, you must know how to log on to the remote system and have a userid and password on that system.

Note: Some systems allow anonymous ftp access. To use anonymous ftp, use anonymous as your userid andyour e-mail address as the logon password.


Logging Onto and Off of a Remote System

To begin using Microsoft's FTP client, Open a command prompt and switch to the destination directory (where you want the download file).
To start an FTP session, enter: ftp host_name
where hostname is the name or IP address of the remote system.
You will then be asked to enter your userid and password.
Once you have successfully logged onto a remote system, you will be able to use ftp commands to view a listing of files on the remote system and transfer files between the two systems.
Example: Download i386.exe (Windows NT 3.5 Resource Kit) from ftp://ftp.microsoft.com/bussys/winnt/winnt-public/reskit/nt35/i386 to C:\Temp\Download

  1. Open a command prompt. Enter CD C:\Temp\Download (assuming that directory exists).
    Enter: ftp ftp.microsoft.com

    You should now see a prompt similar to this:
    Connected to ftp.microsoft.com.
    220 Microsoft FTP Service
    User (ftp.microsoft.com:(none)):


  2. For the userid, Enter: anonymous

    You should see a prompt similar to this:
    331 Anonymous access allowed, send identity (e-mail name) as password.
    Password:


  3. Enter: userid@domain.com as the password at the "Password:" prompt.
    Note: Any e-mail address in a userid@domain.com format should work. You will not be able to see the password as you type it.


  4. To download i386.exe from the bussys/winnt/winnt-public/reskit/nt35/i386 directory, Enter: get bussys/winnt/winnt-public/reskit/nt35/i386/i386.exe
    Note: You could have also used ls to view the directory and file names, cd bussys/winnt/winnt-public/reskit/nt35/i386 to switch directories, and get i386.exe to download the file from within that directory.


  5. To end the FTP session, Enter: quit or bye.
Note: Once you have extracted the resource kit, you will have to expand individual files
example: expand choice.ex_ choice.exe


FTP Commands

For a list of FTP commands, at the "ftp>" prompt, Enter: help
When using ftp from the command prompt, the following list of supported commands will be displayed:
Note: Hover your mouse over a command to see what the output of "help *" is for that command.
!   
delete
literal
prompt
send
?   
debug
ls  
put 
status
append
dir
mdelete
pwd 
trace
ascii
disconnect
mdir
quit
type
bell
get 
mget
quote
user
binary
glob
mkdir
recv
verbose
bye 
hash
mls 
remotehelp
 
cd  
help
mput
rename
 
close
lcd 
open
rmdir
 
The question mark (?) command is equivalent to the help command. Typing help or ? followed by the name of a command will display a brief description of the command's purpose.
The exclamation point (!) can be used to shell to the system (command) prompt. Type Exit to return to the FTP session. You can also issue a subset of system commands to perform as you shell out, e.g., ! dir %windir% | more. When the commands in the shell have completed, you will be returned to the FTP session.
The pwd command will list the current directory on the remote machine. To change directories on the remote machine, use the cd command. To create a new directory on the remote machine, use the mkdir command followed by the name you would like to assign to the new directory. The lcd command can be used to change directories on the local (PC) machine.
To display a listing of files on the remote system, enter: ls or dir.
To download a file (copy a file from the remote system to your PC), you can use the command get or recvfollowed by the name of the file you would like to download. Optionally, you can follow the filename with a second filename which will be assigned to the file when it is downloaded to your PC. To download multiple files, you can use the mget command followed by a descriptor for the files you would like to download (e.g.: *.f for all files ending in ".f" or *.* for all files). You will be prompted to indicate whether you would like to download each file in turn. To turn off this prompting, enter the prompt command prior to entering the mget command; you will receive the message "Interactive mode OFF" indicating that prompting has been deactivated.
By default, files are downloaded and uploaded in ASCII file transfer mode. To download or upload files using Binary format mode, enter the command Binary at the "ftp>" prompt prior to downloading or uploading the file(s). To return to ASCII file transfer mode, enter the ASCII command.
To upload a file (copy a file from your PC to the remote system), you can use the command put or send followed by the name of the file you would like to upload. Optionally, you can follow the filename with a second filename which will be assigned to the file when it is uploaded to the remote system. The mput command can be used to upload multiple files.
You can use the close or disconnect command to drop the current ftp connection without exiting from the command enironment and then use the open command to connect to a new host.

Much of this article was taken from the dead link,http://www.cc.vt.edu/cc/us/docs/faqlib/windows95/clients/msftp.html

To see the original article, go tohttp://web.archive.org/web/*/http://www.cc.vt.edu/cc/us/docs/faqlib/windows95/clients/msftp.html



Source: http://www.tburke.net/info/misc/cmdline-ftp.htm

Ubuntu Linux: Compress files using tar Command

How do I compress and backup files using tar command to another directory on same computer or another Linux computer under Ubuntu Linux?

First, open up a terminal under Ubuntu Linux. Some directories such as /etc require root permissions to read and write for backup. So you may need to run tar command using sudo command. In this example backup, /etc and your /home/vivek to /backup directory, enter:
$ sudo mkdir /backup
$ sudo tar -zcvpf /backup/files.backup.Nov_6_2009.tar.gz /etc/ /home/vivek

Where,
  • z : Compress the backup file with 'gzip' to make it smaller.
  • c : Create a new backup archive called /backup/files.backup.Nov_6_2009.tar.gz.
  • v : Verbose mode, the tar command will display what it's doing to the screen.
  • p : Preserves the permissions of the files put in the archive for restoration later.
  • f /backup/files.backup.Nov_6_2009.tar.gz: Specifies where to store the backup, /backup/files.backup.Nov_6_2009.tar.gz is the filename used in this example.

How Do I Exclude Certain Files or Directories?

You can exclude all *.mp3 stored in /home/vivek/music directory with --exclude option:
$ sudo tar --exclude='/home/vivek/music/' -zcvpf /backup/files.backup.Nov_6_2009.tar.gz /etc/ /home/vivek
Another example (exclude ~/music/ and ~/Downloads/*.avi files):
$ sudo tar --exclude='/home/vivek/music/' --exclude='/home/vivek/Downloads/*.avi' -zcvpf /backup/files.backup.Nov_6_2009.tar.gz /etc/ /home/vivek

How Do I See a List Of Files Stored In Tar Ball or an Archive?

Type the following command:
$ sudo tar -ztvf /backup/files.backup.Nov_6_2009.tar.gz
Where,
  • t: List the contents of an archive.

How Do I Restore Files?

You can use the command as follows to restore everything in / directory:
$ sudo tar -xvpzf /backup/files.backup.Nov_6_2009.tar.gz -C /
OR
$ cd /
$ sudo tar -xvpzf /backup/files.backup.Nov_6_2009.tar.gz

Where,
  • -x: Extract the files.
  • -C / : Extract the files in / directory.
In this example, you are restoring to the /delta directory.
$ sudo tar -xvpzf /backup/files.backup.Nov_6_2009.tar.gz -C /delta

How Do I Backup Files To a Remote Server Called backup.example.com?

Type the command as follows to backup /etc/ and /home/vivek directories to a remote system called backup.example.com:
$ sudo -s
# ssh user@backup.example.com "mkdir /backup"
# tar zcvpf - /etc/ /home/vivek | ssh user@backup.example.com "cat > /backup/files.backup.Nov_6_2009.tar.gz"

How Do I Restore Backup From a Remote System to Local Ubuntu Box?

Type the command
$ sudo -s
# cd /
# ssh user@backup.example.com "cat /backup/files.backup.Nov_6_2009.tar.gz" | tar zxpvf -
Source: http://www.cyberciti.biz/faq/ubuntu-howto-compress-files-using-tar/