Category Archives: command line

How to change default editor

Each works well with your favorite text editor. It is important that there is a default editor known. In debian and in other linux distro, default editor is vi.

You could change default editor:

  1. during distro installation
  2. custom each user into .bashrc or .profile file with line:
    export EDITOR=/usr/bin/emacs
  3. custom locally in a shell session and/or particular program:
    env EDITOR=nano crontab -e

crontab

NAME
crontab – maintain crontab files for individual users (V3)
SYNOPSIS
crontab [ -u user ] file
crontab [ -u user ] { -l | -r [ -i ] | -e }

EXAMPLE
Stamp output about crontab file:
crontab -l

Modify crontab with default editor:
crontab -e

yum segmentation fault in centos

After an upgrading with yum program, yum will end with segmentation fault.

Last link about libz is the cause:
-rwxr-xr-x 1 root root  75028  9 gen  2007 libz.so.1.2.3
-rwxr-xr-x 1 root bin   96572  8 nov  2010 libz.so.1.2.5
-rw-r--r-- 1 root bin  101462  8 nov  2010 libz.a
lrwxrwxrwx 1 root root     13  8 apr  2011 libz.so -> libz.so.1.2.3
lrwxrwxrwx 1 root root     13  8 apr  2011 libz.so.1 -> libz.so.1.2.5

libz.so.1 need a different link:
lrwxrwxrwx 1 root root     13  8 apr  2011 libz.so.1 -> libz.so.1.2.3

Reference: yum fails with segfault after source zlib upgrade

dig

NAME
DNS lookup utility.
SYNTAX
dig [@server] [-b address] [-c class] [-f filename] [-k filename] [-p port#] [-t type] [-x addr] [-y name:key] [-4] [-6] [name] [type] [class] [queryopt...]
dig [-h]
dig [global-queryopt...] [query...]

EXAMPLE
dig bilardi.net

Set TimeZone on Centos

CentOS update breaks another thing – the logwatch perl timezone manipulation. The exact error message is:
ERROR: Date::Manip unable to determine TimeZone.

Execute the following command in a shell prompt:
perldoc Date::Manip
The section titled TIMEZONES describes valid TimeZones and where they can be defined.

You could fix it modify /etc/localtime. You could use tzconfig command line and follow its questions or:
cp /usr/share/zoneinfo/Europe/Rome /etc/localtime
If your localtime is different, you could choose your zoneinfo in /usr/share/zoneinfo/.

Referece: fullo.net

rdate

NAME
rdate – get the time via the network
SYNOPSIS
rdate [-p] [-s] [-u] [-l] [-t sec] [host...]
EXAMPLE
rdate -s ntp0.cornell.edu

If you want syncronize date, then you could add this line into crontab:
* * * * 0 rdate -s ntp0.cornell.edu

How to add a directory to my PATH statement or variable

When you type the name of an executable file, GNU/Linux searches for that executable in all the directories specified in the PATH environment variable.
By default, your GNU/Linux distribution probably set up a default PATH variable during install. To see what your current PATH variable is set to, in a terminal window, type:
echo $PATH
and press ENTER. The system should respond by writing out the current value of the PATH variable. That probably looks something like:
/usr/bin:/usr/sbin
To add a directory to the PATH statement is a relatively straight forward process, but first a question needs to be answered:
Note that these instructions are for a bash shell which is very common n GNU/Linux systems. If you are running another shell, please consult the directions for that shell.
Which users do you want to be affected by this new PATH value?
1. In a home GNU/Linux system, it’s likely that there is only one user and therefore the answer is: me and my root account.
2. If you are running a multi-user system, then the answer is likely: everybody and root.
3. Possibly the third answer is: only ‘joe’ or some other single user on the system.
Regardless of which user(s) are to affected, the same line(s) need to be added to a profile file. The only variable is: which file?
The line(s) or code to add are:
PATH=$PATH:/directory/you/want/to/add
export PATH

NOTE: The export command need only be called once in the profile file and after all the PATH statements in that file. If an export command is already present in the applicable profile file (see below), then you need not add another one.
You are going to add these lines to the following location depending on which user(s) you want to affect:

1. To add that PATH to every user but root, add the line(s) to /etc/profile
2. To add that PATH to root, add those line(s) to /root/.bash_profile
3. To add that PATH to a specific user(s), add the line(s) to /home/user/.bash_profile

PATH=$PATH:$HOME/bin
PATH=$PATH:/home/flebber/Python
export PATH

Reference: everyjoe.com, linuxforums.org

How to add user to group

How can I add a user to a group under Linux operating system?

You can use the useradd or usermod commands to add a user to a group. The useradd command creates a new user or update default new user information. The usermod command modifies a user account i.e. it is useful to add user to existing group. There are two types of group. First is primary user group and other is secondary group. All user account related information is stored in /etc/passwd, /etc/shadow and /etc/group files to store user information.

useradd Example – Add A New User To Secondary Group
You need to the useradd command to add new users to existing group (or create a new group and then add user). If group does not exist, create it. The syntax is as follows:
useradd -G {group-name} username

In this example, create a new user called vivek and add it to group called developers. First login as a root user (make sure group developers exists), enter:
grep developers /etc/group
Output:
developers:x:1124:

If you do not see any output then you need to add group developers using groupadd command:
groupadd developers
Next, add a user called vivek to group developers:
useradd -G developers vivek
Setup password for user vivek:
passwd vivek
Ensure that user added properly to group developers:
id vivek
Output:
uid=1122(vivek) gid=1125(vivek) groups=1125(vivek),1124(developers)
Please note that capital G (-G) option add user to a list of supplementary groups. Each group is separated from the next by a comma, with no intervening whitespace. For example, add user jerry to groups admins, ftp, www, and developers, enter:
useradd -G admins,ftp,www,developers jerry

useradd example – Add a new user to primary group
To add a user tony to group developers use following command:
useradd -g developers tony
id tony

Output:
uid=1123(tony) gid=1124(developers) groups=1124(developers)
Please note that small -g option add user to initial login group (primary group). The group name must exist. A group number must refer to an already existing group.

usermod example – Add a existing user to existing group
Add existing user tony to ftp supplementary/secondary group with usermod command using -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option :
usermod -a -G ftp tony
Change existing user tony primary group to www:
usermod -g www tony

Reference: cyberciti.biz

useradd

NAME
useradd – create a new user or update default new user information

SYNOPSIS
useradd [options] LOGIN
useradd -D
useradd -D [options]

EXAMPLE
add user jerry to groups admins, ftp, www, and developers, enter:
useradd -G admins,ftp,www,developers jerry
add a user tony to group developers use following command:
useradd -g developers tony

usermod

NAME
usermod – modify a user account

SYNOPSIS
usermod [options] LOGIN
EXAMPLE
Add existing user tony to ftp supplementary/secondary group with usermod command using -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option :
usermod -a -G ftp tony
Change existing user tony primary group to www:
usermod -g www tony