linux notes

Eject cd-rom tray from console
#eject -r

Close cd-rom tray from console
          #eject -t

Mount a CD-rom

          #mount -o loop /dev/cdrom /media/cdrom
CPAN set proxy
           #perl -MCPAN -eshell
        o conf ftp_proxy 'http://proxy:port'
        o conf http_proxy 'http://proxy:port'
        o conf commit
Set proxy

export http_proxy="http://your.proxy.server:port"

Software Raid
          #fdisk /dev/sd?
          press n
          create the correct partition
          press t to change the newly created partition system id
          type fd for the Linux raid auto
          press w to commit the changes
          create partitions as needed.
          #mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sda2
          NAT conf file
          /etc/vmware/vmnet?/nat/nat.conf (? = vmnet adapter number)
          Cannot add user to web access
          #vi /etc/vmware/hostd/authorization.xml

edit the line that talks about


increment it past the current "root" or administrator account you have.

so it now reads

restart the vmware-mgmt service
#service vmware-mgmt restart

now click on the inventory side bar, click on the host name
on the "permission" tab
add the new user to the administrator group

dump databases
mysqldump -u root --password***** database_name > exported_file.sql

import database
mysql -u root --password***** database_name < exported_file.sql

Add proxy to yum
vi /etc/yum.conf

# The proxy server - proxy server:port number
# The account details for yum connections

Import Key for Yum and RPM
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*

Set Global Proxy
export http_proxy
OS command not registered.
echo $PATH
if :/sbin and /usr/sbin is not listed. do the below command

Cannot write to files in recovery mode as root, (File is read only)

Example (chmod: changing permissions of 'etc/fstab': Read-only file system)

use this command
mount -o rw,remount /

unable to boot linux installer in intel motherboard

linux pci=noacpi,nommconf

Detect a hot-swapped SCSI hard-disk without reboot
                After adding in the scsi hdd

# cat /proc/scsi/scsi

Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02

from the above it shows there is only 1scsi hdd at Id: 00
so the newly swapped in disk will be id 1
# echo “scsi add-single-device 0 0 1 0″ > /proc/scsi/scsi

# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02

#cat /var/log/messages
kernel: Vendor: VMware Model: Virtual disk Rev: 1.0
kernel: Type: Direct-Access ANSI SCSI revision: 02
kernel: target0:0:1: Beginning Domain Validation
kernel: target0:0:1: Domain Validation skipping write tests
kernel: target0:0:1: Ending Domain Validation
kernel: target0:0:1: FAST-160 WIDE SCSI 320.0 MB/s DT IU RDSTRM RTI WRFLOW PCOMP (6.25 ns, offset 127)
kernel: SCSI device sdb: 104857600 512-byte hdwr sectors (53687 MB)

now you can process the harddisk just like you have rebooted after plugging

Make a LVM
#pvcreate /dev/hda
#vgcreate test_vg /dev/hda"?"
#lvcreate -L1500 -n outlook_LV outlook_vg

#lvcreate -L 50G -n outlook_LV outlook_vg // set to be 50GB
#lvcreate -l 60%VG -n outlook_LV outlook_vg // use 60% of VG
#lvcreate -l 100%FREE -n outlook_LV outlook_vg // use 100% of free space in VG

Increase Size of a LVM
              #lvextend -L+4G /dev/LVname/LogVol00
            4G is the size of the partition created earlier, u will have to use a smaller number like +3900M to compensate for overhead of using the VG
              # resize2fs /dev/LVname/LogVol00

for RHEL 7
            mount the data partition and run
                #xfs_grow /data
Downsize a LVM
Boot into rescue, do not allow the rescue disk to detect and mount the OS partition

# lvm vgchange -a y
# e2fsck -f /dev/VolGroup00/LogVol00

Change Harddisk Label

#e2label <device> <label>
Finding a command

For example; the quota commands includes quotacheck, edquota, repquota
if you were to type quota and press 'tab' twice it will not return the command not starting with quota like edquota and repquota

to search for sets of keyword related command use this

#locate quota | grep sbin


List shares on ip
#smbclient -L

Connect to windows share
#smbclient \\\\\\sharename -Uusername

#put /etc/hosts

#get pdf995\setup.exe
List users in system
              #cat /etc/passwd | grep "/home"
List users in group

#lid -g groupname

List groups which user belong to

#lid username
User account with blank password
#passwd -d username

Establish Quota on mounted volumes
              /dev/VolGroupHOME/LogVol00 /home                   ext3    defaults,usrquota        1 2
              #mount -o remount /home
To check if usrquota options is activated
/dev/mapper/VolGroupHOME-LogVol00 on /home type ext3 (rw,usrquota)

Create the quota database file
               #quotacheck -ufm /home

Use static IP

go to /etc/sysconfig/network-scripts

#vim ifcfg-eth0

add a new line “GATEWAY=” as per below




Recall command used by
to use a previous entered command use the !(followed by the number for the command)
Clear history by
#history -c


install VNC thru yum, set passwd and config desktop manager


config desktop manager

#vim $HOME/.vnc/xstartup


# Uncomment the following two lines for normal desktop:
exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

Type the below command to launch server


port 5801,5901,6001 will be for desktop 1

port 5802,5902,6002 will be for desktop 2

and so forth.

LDAP-client CLI setup

#yum install authconfig

#authconfig --enableldap  --enableldapauth --ldapbasedn="ou=group, o=companyname ,c=sg" --enableldaptls

Detect new Partition after fdisk



#vi /etc/exports


#service nfs restart

#chkconfig nfs on

#chmod a+rwx /mnt/shared_directory

connecting to NFS

#mount -o defaults /mnt/local_directory

(via a new entry in fstab)

#vi etc/fstab     /mnt/local_directory    nfs    defaults 0 0

NFS troubleshooting guide


#echo $(date +%d%m%y)

this show the current date

Sound Beeper from terminal

#echo -e "\007" >/dev/tty10

NTP setup

  1. Logged in as root, check which timezone your machine is currently using by executing `date`. You'll see something like Mon 17 Jan 2005 12:15:08 PM PST, PST in this case is the current timezone.
  2. Change to the directory /usr/share/zoneinfo here you will find a list of time zone regions. Choose the most appropriate region, if you live in Canada or the US this directory is the "America" directory.
  3. If you wish, backup the previous timezone configuration by copying it to a different location. Such as
    mv /etc/localtime  /etc/localtime-old

  4. Create a symbolic link from the appropiate timezone to /etc/localtime. Example:
    ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

  5. If you have the utility rdate, update the current system time by executing
    /usr/bin/rdate -s

  6. Set the ZONE entry in the file /etc/sysconfig/clock file (e.g. "America/Los_Angeles")
  7. Set the hardware clock by executing:
    /sbin/hwclock --systohc
  • On some versions of RedHat Linux, Slackware, Gentoo, SuSE, Debian, Ubuntu, and anything else that is "normal", the command to display and change the time is 'date', not 'clock'
  • On RedHat Linux there is a utility called "Setup" that allows one to select the timezone from a list, but you must have installed the 'redhat-config-date' package. <note... on RHEL5 it is actually 'system-config-date' >
  • On mobile phones and other small devices that run Linux, the time zone is stored differently. It is written in /etc/TZ, in the format that is described, for instance, in [1]. Edit this file manually or use echo (for instance, echo GMT0BST > /etc/TZ to set the the timezone of the United Kingdom).
  • To setup UTC :
  • vi /etc/sysconfig/clock and change the UTC line to: "UTC=true"
Find Largest directory in filesystem
#du -k . | sort -n |more

#du -sk *|sort -n

Find Largest file in Directory
#find $1 -type d | xargs du -sm | sort -g

Find Largest Directory
#du -a /var | sort -n -r | head -n 10

Find the UUID of devices
check which hub is usb on

Increase file limit
#vi /etc/sysctl.conf
(add in)
fs.file-max = 331287
#sysctl -p
(apply change)

#sysctl -a|grep file
(to check if setting has changed)

in the /etc/security/limits.conf file
(add this line)
* - nofile 104854
Free up Memory cache
#sync; echo 3 > /proc/sys/vm/drop_caches

Check CPU use

No ethernet after installation
        #vi /etc/sysconfig/network-scripts/ifcfg-eth0
        set onboot=yes

Check dependencies for rpm
#rpm -qpR xxx.rpm
#rpm -ivh xxx.rpm

nc Command Example

The nc (or netcat utility) is used for just about anything under the sun involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6. In this example, open port 5000 using nc command:

$ nc -l 5000

On a second console or from a second UNIX / Linux machine, connect to the machine and port being listened on:
$ nc localhost 5000

$ nc 5000

In this example, send data from one computer to another:
$ nc -l 5555 > output.txt

Using a second machine, connect to the listening nc process (@ port 5555), feeding it the file which is to be transferred:
$ nc 5555 < input.txt

You can run netstat command to view open ports:
$ netstat -a
$ netstat -nat | grep LISTEN

Sample outputs:
tcp4 0 0 *.5555 *.* LISTEN
tcp4 0 0 *.* LISTEN
tcp4 0 0 *.* LISTEN
tcp4 0 0 *.* LISTEN
tcp4 0 0 *.* LISTEN
tcp4 0 0 *.* LISTEN
tcp4 0 0 *.* LISTEN
tcp6 0 0 ::1.631 *.* LISTEN

ArchLinux pacman & packer
Install Prerequisite
#pacman -S base-devel fakeroot


#makepkg PKGBUILD

install the built package
#pacman -U packer-*.pkg.tar.xz

Change the default AUR PKG directory
#vi /etc/makepkg.conf

Change this variable in file /etc/makepkg.conf

Remove Old BLKID listed partitions
remove them from /etc/

importing vmdk to virtualbox
use either HDA or SCSI but not SATA

doing screen-paging in FTP (no space between | and less)
#ls * |less

list all cron jobs for all users
    #for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done

list all cron jobs for all users and count all valid cron.    
    #for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done|grep -v "no crontab for "| grep -v "#"| grep -vc '^$'

list active users
    #less /etc/shadow |grep -v "*" |cut -d ":" -f1

list inactive users  
    #less /etc/shadow |grep "*" |cut -d ":" -f1

check http
#telnet www.somesite 80
GET /index.html HTTP/1.1
Host: www.somesite

check https
#openssl s_client -connect www.somesite:443
[watch the ssl certificate details scroll by]
GET /index.html HTTP/1.1
Host: www.somesite

check usb devices
#udevadm info --query=all -n /dev/sda 

Enable Display of date time in history
If you don't have HISTTIMEFORMAT set, but do have a history file, and then set HISTTIMEFORMAT, your history will all show the same time.

If you then set HISTTIMEFORMAT in .bashrc, say, so that it's persistent across sessions, log out, log back in, run some commands, and then run history, you'll see the timestamps being updated correctly.

If, as I wonder if you did, you didn't have HISTTIMEFORMAT set at some time in the past, then set it and expected your previous history entries to have the correct datestamp, it won't work. Essentially, having this variable set acts as a switch to have history _start_ saving datestamp data - if it wasn't set, then it won't save it. 

#echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile 

is showing ip address instead of relayed hosts instead of hostname;

options {
        sync (0);
        time_reopen (10);
        log_fifo_size (1000);
        long_hostnames (off);
        use_dns (yes);
        use_fqdn (no);
        create_dirs (no);
        keep_hostname (yes);

use_dns (yes) syslog server must be able to resolve the ip address to hostname of the servers; 

keep_hostname (yes); allow hostname to be kept when forwarded

chain_hostnames(yes); append hostname and syslog server name in message.

Create Machine Image
qemu-img create -f qcow2 vdisk.img 10G
Install OS onto OS disk Image
qemu-system-x86_64 -hda vdisk.img -cdrom /path/to/boot-media.iso -boot d -m 384
Starting Virtual Machine
qemu-system-x86_64 vdisk.img -m 384

Starting With bridged adapter
qemu-system-x86_64 -hda xp-curr.img -m 512 -soundhw es1370 -no-acpi -snapshot -localtime -boot c -usb -usbdevice tablet -net nic,vlan=0,macaddr=00:00:10:52:37:48 -net tap,vlan=0,ifname=tap0,script=no

Set Ulimt
To see the hard and soft values, issue the command as follows:
#ulimit -Hn
#ulimit -Sn

# vi /etc/sysctl.conf
Append / modify the following line:
fs.file-max = 70000

# vi /etc/security/limits.conf
Set soft and hard limit for all users

*               soft    nofile          35000
*               hard    nofile          35000

Save and close the file. Finally, reload
# sysctl -p

 for daemon to show own wallet address
#bitcoind listreceivedbyaddress 0 true


Rolling back yum packages

To configure yum to save rollback information, add the line tsflags=repackage to /etc/yum.conf.

To configure command-line rpm to do the same thing, add the line %_repackage_all_erasures 1 to /etc/rpm/macros (If does not exist, just create it).
If/when you want to rollback to a previous state, perform an rpm update with the --rollback option followed by a date/time specified.

Some examples:
#rpm -Uhv --rollback '9:00 am'
#rpm -Uhv --rollback '4 hours ago'
#rpm -Uhv --rollback 'december 25'.

        copy with limited IO speed.
        #rsync --bwlimit=5000 --progress /media/san/bt/complete/* /media/san/public/unsorted/

        #nohup SOME_COMMAND &
        #nohup scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1

Then press ctrl + z which will temporarily suspend the command, then enter the command:

Pick up new partitions
#partx -v -a /dev/sdb

#qemu-img create -f qcow2 ubuntu.qcow2 30G
#qemu-system-i386 -cdrom ubuntu-12.04.1-desktop-i386.iso -hda ubuntu.qcow2 -m 1024 -vnc :1  -boot "c"

Checking hdd status
#smartctl -a -i /dev/sdi -T permissive|less

Scrub Mdraid
#echo check >> /sys/block/mdX/md/sync_action

LVM Cheatsheet

Remove missing pv
vgreduce --removemissing --force VolData00


zfs mount -a
operate Screen within a screen
The answer (courtesy of Google and Yacin Nadji) is that Ctrl+a will target the outer screen. Each a that you add after that will go down one nesting level.

Single instance of cron job runnign rsync
if [ -e /home/myhomedir/rsyncjob.lock ]
echo "Rsync job already running...exiting"
touch /home/myhomedir/rsyncjob.lock
#your code in here
#delete lock file at end of your job
rm /home/myhomedir/rsyncjob.lock

better way in crontab
* * * * * /usr/bin/flock -n /tmp/fcj.lockfile /usr/local/bin/frequent_cron_job --minutely

If you've ever tried using xargs with a list of filenames, you've probably at some point come across errors like these:
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

ls: cannot access /home/sophie/directory: No such file or directory
ls: cannot access with: No such file or directory
ls: cannot access spaces: No such file or directory
ls: cannot access in/blah.txt: No such file or directory

Both of these errors are due to xargs by default interpreting some characters as special; in the first one, it won't allow apostrophes, and in the second it treats spaces as if they meant separate arguments. And the -0 switch doesn't help at all if you're using newlines.

Both of these errors can be resolved very easily: just add the -d"\n" switch before the command you want xargs to execute. This tells xargs that you don't want xargs to mess with your input at all except to treat newline characters as delimiters. This time, you should find that both apostrophes and spaces are accepted properly.

Set Timezone

[a] setup or redhat-config-date for RHEL based distros.

[b] dpkg-reconfigure tzdata for Debian based distros.


figure the dependency of systemd service.
#systemctl list-dependencies --after