| No comment yet

Advance Linux Commands


System information

Command Description
# arch show architecture of machine(1)   [man]
# cal 2007 show the timetable of 2007   [man]
# cat /proc/cpuinfo show information CPU info   [man]
# cat /proc/interrupts show interrupts   [man]
# cat /proc/meminfo verify memory use   [man]
# cat /proc/swaps show file(s) swap   [man]
# cat /proc/version show version of the kernel   [man]
# cat /proc/net/dev show network adpters and statistics   [man]
# cat /proc/mounts show mounted file system(s)   [man]
# clock -w save date changes on BIOS   [man]
# date show system date   [man]
# date 041217002007.00 set date and time - MonthDayhoursMinutesYear.Seconds   [man]
# dmidecode -q show hardware system components - (SMBIOS / DMI)   [man]
# hdparm -i /dev/hda displays the characteristics of a hard-disk   [man]
# hdparm -tT /dev/sda perform test reading on a hard-disk   [man]
# lspci -tv display PCI devices   [man]
# lsusb -tv show USB devices   [man]
# uname -m show architecture of machine(2)   [man]
# uname -r show used kernel version   [man]


Shutdown, Restart and Logout of a system

Command Description
# init 0 shutdown system(2)   [man]
# logout leaving session   [man]
# reboot reboot(2)   [man]
# shutdown -h now shutdown system(1)   [man]
# shutdown -h 16:30 & planned shutdown of the system at 16:30   [man]
# shutdown -c cancel a planned shutdown of the system   [man]
# shutdown -r now reboot(1)   [man]
# telinit 0 shutdown system(3)   [man]

Files and Directory

Command Description
# cd /home enter to directory '/ home'   [man]
# cd .. go back one level   [man]
# cd ../.. go back two levels   [man]
# cd go to home directory   [man]
# cd ~user1 go to home directory   [man]
# cd - go to previous directory   [man]
# cp file1 file2 copying a file   [man]
# cp dir/* . copy all files of a directory within the current work directory   [man]
# cp -a /tmp/dir1 . copy a directory within the current work directory   [man]
# cp -a dir1 dir2 copy a directory   [man]
# cp file file1 outputs the mime type of the file as text   [man]
# iconv -l lists known encodings   [man]
# iconv -f fromEncoding -t toEncoding inputFile > outputFile converting the coding of characters from one format to another   [man]
# find . -maxdepth 1 -name *.jpg -print -exec convert batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)   [man]
# ln -s file1 lnk1 create a symbolic link to file or directory   [man]
# ln file1 lnk1 create a physical link to file or directory   [man]
# ls view files of directory   [man]
# ls -F view files of directory   [man]
# ls -l show details of files and directory   [man]
# ls -a show hidden files   [man]
# ls *[0-9]* show files and directory containing numbers   [man]
# lstree show files and directories in a tree starting from root(2)   [man]
# mkdir dir1 create a directory called 'dir1'   [man]
# mkdir dir1 dir2 create two directories simultaneously   [man]
# mkdir -p /tmp/dir1/dir2 create a directory tree   [man]
# mv dir1 new_dir rename / move a file or directory   [man]
# pwd show the path of work directory   [man]
# rm -f file1 delete file called 'file1'   [man]
# rm -rf dir1 remove a directory called 'dir1' and contents recursively   [man]
# rm -rf dir1 dir2 remove two directories and their contents recursively   [man]
# rmdir dir1 delete directory called 'dir1'   [man]
# touch -t 0712250000 file1 modify timestamp of a file or directory - (YYMMDDhhmm)   [man]
# tree show files and directories in a tree starting from root(1)   [man]


File search

Command Description
# find / -name file1 search file and directory into root filesystem from '/'   [man]
# find / -user user1 search files and directories belonging to 'user1'   [man]
# find /home/user1 -name \*.bin search files with '. bin' extension within directory '/ home/user1'   [man]
# find /usr/bin -type f -atime +100 search binary files are not used in the last 100 days   [man]
# find /usr/bin -type f -mtime -10 search files created or changed within 10 days   [man]
# find / -name *.rpm -exec chmod 755 '{}' \; search files with '.rpm' extension and modify permits   [man]
# find / -xdev -name \*.rpm search files with '.rpm' extension ignoring removable partitions as cdrom, pen-drive, etc.…   [man]
# locate \*.ps find files with the '.ps' extension - first run 'updatedb' command   [man]
# whereis halt show location of a binary file, source or man   [man]
# which halt show full path to a binary / executable   [man]

Mounting a Filesystem

Command Description
# fuser -km /mnt/hda2 force umount when the device is busy   [man]
# mount /dev/hda2 /mnt/hda2 mount disk called hda2 - verify existence of the directory '/ mnt/hda2'   [man]
# mount /dev/fd0 /mnt/floppy mount a floppy disk   [man]
# mount /dev/cdrom /mnt/cdrom mount a cdrom / dvdrom   [man]
# mount /dev/hdc /mnt/cdrecorder mount a cdrw / dvdrom   [man]
# mount /dev/hdb /mnt/cdrecorder mount a cdrw / dvdrom   [man]
# mount -o loop file.iso /mnt/cdrom mount a file or iso image   [man]
# mount -t vfat /dev/hda5 /mnt/hda5 mount a Windows FAT32 file system   [man]
# mount /dev/sda1 /mnt/usbdisk mount a usb pen-drive or flash-drive   [man]
# mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share mount a windows network share   [man]
# umount /dev/hda2 unmount disk called hda2 - exit from mount point '/ mnt/hda2' first   [man]
# umount -n /mnt/hda2 run umount without writing the file /etc/mtab - useful when the file is read-only or the hard disk is full   [man]

Disk Space

Command Description
# df -h show list of partitions mounted   [man]
# dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n show the used space by installed deb packages, sorting by size (debian, ubuntu and alike)   [man]
# du -sh dir1 estimate space used by directory 'dir1'   [man]
# du -sk * | sort -rn show size of the files and directories sorted by size   [man]
# ls -lSr |more show size of the files and directories ordered by size   [man]
# rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n show the used space by rpm packages installed sorted by size (fedora, redhat and alike)   [man]

Users and Groups

Command Description
# chage -E 2005-12-31 user1 set deadline for user password   [man]
# groupadd [group] create a new group   [man]
# groupdel [group] delete a group   [man]
# groupmod -n moon sun rename a group from moon to sun   [man]
# grpck check correct syntax and file format of '/etc/group' and groups existence   [man]
# newgrp - [group] log into a new group to change default group of newly created files   [man]
# passwd change password   [man]
# passwd user1 change a user password (only by root)   [man]
# pwck check correct syntax and file format of '/etc/passwd' and users existence   [man]
# useradd -c "User Linux" -g admin -d /home/user1 -s /bin/bash user1 create a new user "user1" belongs "admin" group   [man]
# useradd user1 create a new user   [man]
# userdel -r user1 delete a user ( '-r' eliminates home directory)   [man]
# usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 change user attributes as description, group and other   [man]

Permits on Files

Command Description
# chgrp group1 file1 change group of files   [man]
# chmod ugo+rwx directory1 set permissions reading (r), write (w) and (x) access to users owner (u) group (g) and others (o)   [man]
# chmod go-rwx directory1 remove permits reading (r), write (w) and (x) access to users group (g) and others (or   [man]
# chmod u+s /bin/file1 set SUID bit on a binary file - the user that running that file gets same privileges as owner   [man]
# chmod u-s /bin/file1 disable SUID bit on a binary file   [man]
# chmod g+s /home/public set SGID bit on a directory - similar to SUID but for directory   [man]
# chmod g-s /home/public disable SGID bit on a directory   [man]
# chmod o+t /home/public set STIKY bit on a directory - allows files deletion only to legitimate owners   [man]
# chmod o-t /home/public disable STIKY bit on a directory   [man]
# chown user1 file1 change owner of a file   [man]
# chown -R user1 directory1 change user owner of a directory and all the files and directories contained inside   [man]
# chown user1:group1 file1 change user and group ownership of a file   [man]
# find / -perm -u+s view all files on the system with SUID configured   [man]
# ls -lh show permits on files   [man]
# ls /tmp | pr -T5 -W$COLUMNS divide terminal into 5 columns   [man]

Special Attributes on files

Command Description
# chattr +a file1 allows write opening of a file only append mode   [man]
# chattr +c file1 allows that a file is compressed / decompressed automatically by the kernel   [man]
# chattr +d file1 makes sure that the program ignores Dump the files during backup   [man]
# chattr +i file1 makes it an immutable file, which can not be removed, altered, renamed or linked   [man]
# chattr +s file1 allows a file to be deleted safely   [man]
# chattr +S file1 makes sure that if a file is modified changes are written in synchronous mode as with sync   [man]
# chattr +u file1 allows you to recover the contents of a file even if it is canceled   [man]
# lsattr show specials attributes   [man]

Archives and compressed files

Command Description
# bunzip2 file1.bz2 decompress a file called 'file1.bz2'   [man]
# bzip2 file1 compress a file called 'file1'   [man]
# gunzip file1.gz decompress a file called 'file1.gz'   [man]
# gzip file1 compress a file called 'file1'   [man]
# gzip -9 file1 compress with maximum compression   [man]
# rar a file1.rar test_file create an archive rar called 'file1.rar'   [man]
# rar a file1.rar file1 file2 dir1 compress 'file1', 'file2' and 'dir1' simultaneously   [man]
# rar x file1.rar decompress rar archive   [man]
# tar -cvf archive.tar file1 create a uncompressed tarball   [man]
# tar -cvf archive.tar file1 file2 dir1 create an archive containing 'file1', 'file2' and 'dir1'   [man]
# tar -tf archive.tar show contents of an archive   [man]
# tar -xvf archive.tar extract a tarball   [man]
# tar -xvf archive.tar -C /tmp extract a tarball into / tmp   [man]
# tar -cvfj archive.tar.bz2 dir1 create a tarball compressed into bzip2   [man]
# tar -xvfj archive.tar.bz2 decompress a compressed tar archive in bzip2   [man]
# tar -cvfz archive.tar.gz dir1 create a tarball compressed into gzip   [man]
# tar -xvfz archive.tar.gz decompress a compressed tar archive in gzip   [man]
# unrar x file1.rar decompress rar archive   [man]
# unzip file1.zip decompress a zip archive   [man]
# zip file1.zip file1 create an archive compressed in zip   [man]
# zip -r file1.zip file1 file2 dir1 compress in zip several files and directories simultaneously   [man]

RPM Packages ( Fedora, Red Hat and like)

Command Description
# rpm -ivh [package.rpm] install a rpm package   [man]
# rpm -ivh --nodeeps [package.rpm] install a rpm package ignoring dependencies requests   [man]
# rpm -U [package.rpm] upgrade a rpm package without changing configuration files   [man]
# rpm -F [package.rpm] upgrade a rpm package only if it is already installed   [man]
# rpm -e [package] remove a rpm package   [man]
# rpm -qa show all rpm packages installed on the system   [man]
# rpm -qa | grep httpd show all rpm packages with the name "httpd"   [man]
# rpm -qi [package] obtain information on a specific package installed   [man]
# rpm -qg "System Environment/Daemons" show rpm packages of a group software   [man]
# rpm -ql [package] show list of files provided by a rpm package installed   [man]
# rpm -qc [package] show list of configuration files provided by a rpm package installed   [man]
# rpm -q [package] --whatrequires show list of dependencies required for a rpm packet   [man]
# rpm -q [package] --whatprovides show capability provided by a rpm package   [man]
# rpm -q [package] --scripts show scripts started during installation / removal   [man]
# rpm -q [package] --changelog show history of revisions of a rpm package   [man]
# rpm -qf /etc/httpd/conf/httpd.conf verify which rpm package belongs to a given file   [man]
# rpm -qp [package.rpm] -l show list of files provided by a rpm package not yet installed   [man]
# rpm --import /media/cdrom/RPM-GPG-KEY import public-key digital signature   [man]
# rpm --checksig [package.rpm] verify the integrity of a rpm package   [man]
# rpm -qa gpg-pubkey verify integrity of all rpm packages installed   [man]
# rpm -V [package] check file size, permissions, type, owner, group, MD5 checksum and last modification   [man]
# rpm -Va check all rpm packages installed on the system - use with caution   [man]
# rpm -Vp [package.rpm] verify a rpm package not yet installed   [man]
# rpm -ivh /usr/src/redhat/RPMS/`arch`/[package.rpm] install a package built from a rpm source   [man]
# rpm2cpio [package.rpm] | cpio --extract --make-directories *bin* extract executable file from a rpm package   [man]
# rpmbuild --rebuild [package.src.rpm] build a rpm package from a rpm source   [man]

YUM packages tool (Fedora, RedHat and alike)

Command Description
# yum -y install [package] download and install a rpm package   [man]
# yum localinstall [package.rpm] That will install an RPM, and try to resolve all the dependencies for you using your repositories.   [man]
# yum -y update update all rpm packages installed on the system   [man]
# yum update [package] upgrade a rpm package   [man]
# yum remove [package] remove a rpm package   [man]
# yum list list all packages installed on the system   [man]
# yum search [package] find a package on rpm repository   [man]
# yum clean [package] clean up rpm cache erasing downloaded packages   [man]
# yum clean headers remove all files headers that the system uses to resolve dependency   [man]
# yum clean all remove from the cache packages and headers files   [man]

DEB packages (Debian, Ubuntu and like)

Command Description
# dpkg -i [package.deb] install / upgrade a deb package   [man]
# dpkg -r [package] remove a deb package from the system   [man]
# dpkg -l show all deb packages installed on the system   [man]
# dpkg -l | grep httpd show all deb packages with the name "httpd"   [man]
# dpkg -s [package] obtain information on a specific package installed on system   [man]
# dpkg -L [package] show list of files provided by a package installed on system   [man]
# dpkg --contents [package.deb] show list of files provided by a package not yet installed   [man]
# dpkg -S /bin/ping verify which package belongs to a given file   [man]

APT packages tool (Debian, Ubuntu and alike)

Command Description
# apt-cache search [package] returns list of packages which corresponds string "searched-packages"   [man]
# apt-cdrom install [package] install / upgrade a deb package from cdrom   [man]
# apt-get install [package] install / upgrade a deb package   [man]
# apt-get update update the package list   [man]
# apt-get upgrade upgrade all of the installed packages   [man]
# apt-get remove [package] remove a deb package from system   [man]
# apt-get check verify correct resolution of dependencies   [man]
# apt-get clean clean up cache from packages downloaded   [man]

Pacman packages tool (Arch, Frugalware and alike)

Command Description
# pacman -S name Install package 'name' with dependencies   [man]
# pacman -R name Delete package 'name' and all files of it   [man]

View file content

Command Description
# cat file1 view the contents of a file starting from the first row   [man]
# head -2 file1 view first two lines of a file   [man]
# less file1 similar to 'more' command but which allows backward movement in the file as well as forward movement   [man]
# more file1 view content of a file along   [man]
# tac file1 view the contents of a file starting from the last line   [man]
# tail -2 file1 view last two lines of a file   [man]
# tail -f /var/log/messages view in real time what is added to a file   [man]

Text Manipulation

Command Description
# cat example.txt | awk 'NR%2==1' remove all even lines from example.txt   [man]
# echo a b c | awk '{print $1}' view the first column of a line   [man]
# echo a b c | awk '{print $1,$3}' view the first and third column of a line   [man]
# cat -n file1 number row of a file   [man]
# comm -1 file1 file2 compare contents of two files by deleting only unique lines from 'file1'   [man]
# comm -2 file1 file2 compare contents of two files by deleting only unique lines from 'file2'   [man]
# comm -3 file1 file2 compare contents of two files by deleting only the lines that appear on both files   [man]
# diff file1 file2 find differences between two files   [man]
# grep Aug /var/log/messages look up words "Aug" on file '/var/log/messages'   [man]
# grep ^Aug /var/log/messages look up words that begin with "Aug" on file '/var/log/messages'   [man]
# grep [0-9] /var/log/messages select from file '/var/log/messages' all lines that contain numbers   [man]
# grep Aug -R /var/log/* search string "Aug" at directory '/var/log' and below   [man]
# paste file1 file2 merging contents of two files for columns   [man]
# paste -d '+' file1 file2 merging contents of two files for columns with '+' delimiter on the center   [man]
# sdiff file1 file2 find differences between two files and merge interactively alike "diff"   [man]
# sed 's/string1/string2/g' example.txt replace "string1" with "string2" in example.txt   [man]
# sed '/^$/d' example.txt remove all blank lines from example.txt   [man]
# sed '/ *#/d; /^$/d' example.txt remove comments and blank lines from example.txt   [man]
# sed -e '1d' exampe.txt eliminates the first line from file example.txt   [man]
# sed -n '/string1/p' view only lines that contain the word "string1"   [man]
# sed -e 's/ *$//' example.txt remove empty characters at the end of each row   [man]
# sed -e 's/string1//g' example.txt remove only the word "string1" from text and leave intact all   [man]
# sed -n '1,5p' example.txt print from 1th to 5th row of example.txt   [man]
# sed -n '5p;5q' example.txt print row number 5 of example.txt   [man]
# sed -e 's/00*/0/g' example.txt replace more zeros with a single zero   [man]
# sort file1 file2 sort contents of two files   [man]
# sort file1 file2 | uniq sort contents of two files omitting lines repeated   [man]
# sort file1 file2 | uniq -u sort contents of two files by viewing only unique line   [man]
# sort file1 file2 | uniq -d sort contents of two files by viewing only duplicate line   [man]
# echo 'word' | tr '[:lower:]' '[:upper:]' convert from lower case in upper case   [man]

Character set and Format file conversion

Command Description
# dos2unix filedos.txt fileunix.txt convert a text file format from MSDOS to UNIX   [man]
# recode ..HTML < page.txt > page.html convert a text file to html   [man]
# recode -l | more show all available formats conversion   [man]
# unix2dos fileunix.txt filedos.txt convert a text file format from UNIX to MSDOS   [man]

Filesystem Analysis

Command Description
# badblocks -v /dev/hda1 check bad blocks on disk hda1   [man]
# dosfsck /dev/hda1 repair / check integrity of dos filesystems on disk hda1   [man]
# e2fsck /dev/hda1 repair / check integrity of ext2 filesystem on disk hda1   [man]
# e2fsck -j /dev/hda1 repair / check integrity of ext3 filesystem on disk hda1   [man]
# fsck /dev/hda1 repair / check integrity of linux filesystem on disk hda1   [man]
# fsck.ext2 /dev/hda1 repair / check integrity of ext2 filesystem on disk hda1   [man]
# fsck.ext3 /dev/hda1 repair / check integrity of ext3 filesystem on disk hda1   [man]
# fsck.vfat /dev/hda1 repair / check integrity of fat filesystem on disk hda1   [man]
# fsck.msdos /dev/hda1 repair / check integrity of dos filesystem on disk hda1   [man]

Format a Filesystem

Command Description
# fdformat -n /dev/fd0 format a floppy disk   [man]
# mke2fs /dev/hda1 create a filesystem type linux ext2 on hda1 partition   [man]
# mke2fs -j /dev/hda1 create a filesystem type linux ext3 (journal) on hda1 partition   [man]
# mkfs /dev/hda1 create a filesystem type linux on hda1 partition   [man]
# mkfs -t vfat 32 -F /dev/hda1 create a FAT32 filesystem   [man]
# mkswap /dev/hda3 create a swap filesystem   [man]


Filesystem SWAP

Command Description
# mkswap /dev/hda3 create a swap filesystem   [man]
# swapon /dev/hda3 activating a new swap partition   [man]
# swapon /dev/hda2 /dev/hdb3 activate two swap partitions   [man]

Backup


Command Description
# find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 find all files with '.log' extention and make an bzip archive   [man]
# find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents find and copy all files with '.txt' extention from a directory to another   [man]
# dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' make a backup of a local hard disk on remote host via ssh   [man]
# dd if=/dev/sda of=/tmp/file1 backup content of the harddrive to a file   [man]
# dd if=/dev/hda of=/dev/fd0 bs=512 count=1 make a copy of MBR (Master Boot Record) to floppy   [man]
# dd if=/dev/fd0 of=/dev/hda bs=512 count=1 restore MBR from backup copy saved to floppy   [man]
# dump -0aj -f /tmp/home0.bak /home make a full backup of directory '/home'   [man]
# dump -1aj -f /tmp/home0.bak /home make a incremental backup of directory '/home'   [man]
# restore -if /tmp/home0.bak restoring a backup interactively   [man]
# rsync -rogpav --delete /home /tmp synchronization between directories   [man]
# rsync -rogpav -e ssh --delete /home ip_address:/tmp rsync via SSH tunnel   [man]
# rsync -az -e ssh --delete ip_addr:/home/public /home/local synchronize a local directory with a remote directory via ssh and compression   [man]
# rsync -az -e ssh --delete /home/local ip_addr:/home/public synchronize a remote directory with a local directory via ssh and compression   [man]
# tar -Puf backup.tar /home/user make a incremental backup of directory '/home/user'   [man]
# ( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' copy content of a directory on remote directory via ssh   [man]
# ( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' copy a local directory on remote directory via ssh   [man]
# tar cf - . | (cd /tmp/backup ; tar xf - ) local copy preserving permits and links from a directory to another   [man]

CDROM

Command Description
# cd-paranoia -B rip audio tracks from a CD to wav files   [man]
# cd-paranoia -- rip first three audio tracks from a CD to wav files   [man]
# cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force clean a rewritable cdrom   [man]
# cdrecord -v dev=/dev/cdrom cd.iso burn an ISO image   [man]
# gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - burn a compressed ISO image   [man]
# cdrecord --scanbus scan bus to identify the channel scsi   [man]
# dd if=/dev/hdc | md5sum perform an md5sum on a device, like a CD   [man]
# mkisofs /dev/cdrom > cd.iso create an iso image of cdrom on disk   [man]
# mkisofs /dev/cdrom | gzip > cd_iso.gz create a compressed iso image of cdrom on disk   [man]
# mkisofs -J -allow-leading-dots -R -V create an iso image of a directory   [man]
# mount -o loop cd.iso /mnt/iso mount an ISO image   [man]

Networking (LAN / WiFi)

Command Description
# dhclient eth0 active interface 'eth0' in dhcp mode   [man]
# ethtool eth0 show network statistics of eth0   [man]
# host www.example.com lookup hostname to resolve name to ip address and viceversa   [man]
# hostname show hostname of system   [man]
# ifconfig eth0 show configuration of an ethernet network card   [man]
# ifconfig eth0 192.168.1.1 netmask 255.255.255.0 configure IP Address   [man]
# ifconfig eth0 promisc configure 'eth0' in promiscuous mode to gather packets (sniffing)   [man]
# ifdown eth0 disable an interface 'eth0'   [man]
# ifup eth0 activate an interface 'eth0'   [man]
# ip link show show link status of all network interfaces   [man]
# iwconfig eth1 show wireless networks   [man]
# iwlist scan wifi scanning to display the wireless connections available   [man]
# mii-tool eth0 show link status of 'eth0'   [man]
# netstat -tup show all active network connections and their PID   [man]
# netstat -tupl show all network services listening on the system and their PID   [man]
# netstat -rn show routing table alike "route -n"   [man]
# nslookup www.example.com lookup hostname to resolve name to ip address and viceversa   [man]
# route -n show routing table   [man]
# route add -net 0/0 gw IP_Gateway configure default gateway   [man]
# route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 configure static route to reach network '192.168.0.0/16'   [man]
# route del 0/0 gw IP_gateway remove static route   [man]
# echo "1" > /proc/sys/net/ipv4/ip_forward activate ip routing temporarily   [man]
# tcpdump tcp port 80 show all HTTP traffic   [man]
# whois www.example.com lookup on Whois database   [man]

Microsoft Windows networks (samba)

Command Description
# mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share mount a windows network share   [man]
# nbtscan ip_addr netbios name resolution   [man]
# nmblookup -A ip_addr netbios name resolution   [man]
# smbclient -L ip_addr/hostname show remote shares of a windows host   [man]
# smbget -Rr smb://ip_addr/share like wget can download files from a host windows via smb   [man]

IPTABLES (firewall)

Command Description
# iptables -t filter -L show all chains of filtering table   [man]
# iptables -t nat -L show all chains of nat table   [man]
# iptables -t filter -F clear all rules from filtering table   [man]
# iptables -t nat -F clear all rules from table nat   [man]
# iptables -t filter -X delete any chains created by user   [man]
# iptables -t filter -A INPUT -p tcp --dport telnet -j ACCEPT allow telnet connections to input   [man]
# iptables -t filter -A OUTPUT -p tcp --dport http -j DROP block HTTP connections to output   [man]
# iptables -t filter -A FORWARD -p tcp --dport pop3 -j ACCEPT allow POP3 connections to forward chain   [man]
# iptables -t filter -A INPUT -j LOG --log-prefix Logging on input chain   [man]
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE configure a PAT (Port Address Traslation) on eth0 masking outbound packets   [man]
# iptables -t nat -A PREROUTING -d 192.168.0.1 -p tcp -m tcp --dport 22 -j DNAT --to-destination 10.0.0.2:22 redirect packets addressed to a host to another host   [man]

Monitoring and debugging

Command Description
# free -m displays status of RAM in megabytes   [man]
# kill -9 process_id force closure of the process and finish it   [man]
# kill -1 process_id force a process to reload configuration   [man]
# last reboot show history reboot   [man]
# lsmod display kernel loaded   [man]
# lsof -p process_id display a list of files opened by processes   [man]
# lsof /home/user1 displays a list of open files in a given path system   [man]
# ps -eafw displays linux tasks   [man]
# ps -e -o pid,args --forest displays linux tasks in a hierarchical mode   [man]
# pstree Shows a tree system processes   [man]
# smartctl -A /dev/hda monitoring reliability of a hard-disk through SMART   [man]
# smartctl -i /dev/hda check if SMART is active on a hard-disk   [man]
# strace -c ls >/dev/null display system calls made and received by a process   [man]
# strace -f -e open ls >/dev/null display library calls   [man]
# tail /var/log/dmesg show events inherent to the process of booting kernel   [man]
# tail /var/log/messages show system events   [man]
# top display linux tasks using most cpu   [man]
# watch -n1 'cat /proc/interrupts' display interrupts in real-time   [man]

Others useful commands

Command Description
# alias hh='history' set an alias for a command - hh = history   [man]
# apropos ...keyword display a list of commands that pertain to keywords of a program , useful when you know what your program does, but you don't know the name of the command   [man]
# chsh change shell command   [man]
# chsh --list-shells nice command to know if you have to remote into another box   [man]
# gpg -c file1 encrypt a file with GNU Privacy Guard   [man]
# gpg file1.gpg decrypt a file with GNU Privacy Guard   [man]
# ldd /usr/bin/ssh show shared libraries required by ssh program   [man]
# man ping display the on-line manual pages for example on ping command - use '-k' option to find any related commands   [man]
# mkbootdisk --device /dev/fd0 `uname -r` create a boot floppy   [man]
# wget -r www.example.com download an entire web site   [man]
# wget -c www.example.com/file.iso download a file with the ability to stop the download and resume later   [man]
# echo 'wget -c www.example.com/files.iso' | at 09:00 start a download at any given time   [man]
# whatis ...keyword displays description of what a program does   [man]
# who -a show who is logged on, and print: time of last system boot, dead processes, system login processes, active processes spawned by init, current runlevel, last system clock change   [man]

| No comment yet

Important Plesk backend files


Following is the location of the different configuration files in plesk:
Apache configuration and log files locations
Main apache configuration files
/etc/httpd/conf/httpd.conf
Users apache configuration files
/etc/httpd/conf.d/*_psa_httpd.conf
Users apache configuration files
Include /home/httpd/vhosts/<domainname>/conf/httpd.include
Apache’s log file is located in
/var/log/httpd/error_log
Apache include files directory
/etc/httpd/conf.d/
Apache binary file
/usr/sbin/httpd
Qmail configuration and log files locations
qmail directory
/var/qmail
Location of qmail maildirs
/var/qmail/mailnames/
Log file location
/usr/local/psa/var/log/maillog
Binary directory
/var/qmail/bin/
My Sql configuration file and log location
location of mysql
/var/lib/mysql
Configuration File
/etc/my.cnf
Log file
/var/log/mysqld.log
Binary file
/usr/bin/mysql
BIND configuration file
Configuration File
/var/named/run-root/etc/named.conf
Zone file location
/var/named/run-root/var/<domain>
Plesk configuration files
Plesk admin password
/etc/psa/.psa.shadow
Plesk configuration file
/etc/psa/psa.conf
Plesk directory
/usr/local/psa
Directory for the config file is
/usr/local/psa/etc
postgresql directory
/var/lib/pgsql/data
FTP configuration files and logs
FTP configuration file
/etc/proftpd.conf
FTP log file
/usr/local/psa/var/log/xferlog
FTP bianry file
/usr/bin/ftp
Awstatics configurtion files and logs
Configuration file location
/etc/awstats/awstats.com
Log file are located in
/var/log/httpd/access_log
Domains access logs
/home/httpd/vhosts/<domain name>/statistics/logs/access_log
| No comment yet

Important Cpanel logs


Cpanel installation directory structure
=============================
/usr/local/cpanel
+ 3rdparty/ - tools like fantastico, mailman files are located here
+ addons/ - AdvancedGuestBook, phpBB etc
+ base/ - phpmyadmin, squirrelmail, skins, webmail etc
+ bin/ - cpanel binaries
+ cgi-sys/ - cgi files like cgiemail, formmail.cgi, formmail.pl etc
+ logs/ - cpanel access log and error log
+ whostmgr/ - whm related files

WHM related files
===============
/var/cpanel - whm files
+ bandwidth/ - rrd files of domains
+ username.accts - reseller accounts are listed in this files
+ packages - hosting packages are listed here
+ root.accts - root owned domains are listed here
+ suspended - suspended accounts are listed here
+ users/ - cpanel user file - theme, bwlimit, addon, parked, sub-domains all are listed in this files
+ zonetemplates/ - dns zone template files are taken from here

Common CPanel scripts
===================
cpanel/whm Scripts are located in /scripts/
+ addns - add a dns zone
+ addfpmail - Add frontpage mail extensions to all domains without them
+ addfpmail2 -Add frontpage mail extensions to all domains without them
+ addnetmaskips - Add the netmask 255.255.255.0 to all IPs that have no netmask
+ addnobodygrp - Adds the gorup nobody and activates security
+ addpop - add a pop account
+ addservlets - Add JSP support to an account (requires tomcat)
+ addstatus - (Internal use never called by user)
+ adduser - Add a user to the system
+ bandwidth - (OLD)
+ betaexim - Installs the latest version of exim
+ biglogcheck - looks for logs nearing 2 gigabytes in size
+ bsdcryptoinstall - Installs crypto on FreeBSD
+ bsdldconfig - Configures the proper lib directories in FreeBSD
+ bsdpkgpingtest - Tests the connection speed for downloading FreeBSD packages
+ buildbsdexpect - Install expect on FreeBSD
+ builddomainaddr - (OLD)
+ buildeximconf - Rebuilds exim.conf
+ buildpostgrebsd-dev - Installs postgresql on FreeBSD.
+ chcpass - change cpanel passwords
+ easyapache - recompile/upgrade apache and/or php
+ exim4 - reinstall exim and fix permissions
+ fixcommonproblems - fixes most common problems
+ fixfrontpageperm - fixes permission issues with Front Page
+ fixmailman - fixes common mailman issues
+ fixnamed - fixes common named issues
+ fixndc - fixes rndc errors with named
+ fixquotas - fixes quota problems
+ fullhordereset - resets horde database to a fresh one - all previous user data are lost
+ initquotas - initializes quotas
+ installzendopt - installs zend optimizer
+ killacct - terminate an account - make sure you take a backup of the account first
+ mailperm - fixes permission problems with inboxes
+ park - to park a domain
+ pkgacct - used to backup an account
+ restartsrv - restart script for services
+ restorepkg - restores an account from a backup file ( pkgacct file)
+ runlogsnow - update logs of all users
+ runweblogs - update stats for a particular user
+ securetmp - secures /tmp partition with options nosuexec and nosuid
+ suspendacct - suspends an account
+ unsuspendacct - unsuspends a suspended account
+ upcp - updates cpanel to the latest version
+ updatenow - updates the cpanel scripts
+ updateuserdomains - updates userdomain entries


Important cpanel/whm files
====================
/etc/httpd/conf/httpd.conf - apache configuration file
/etc/exim.conf - mail server configuration file
/etc/named.conf - name server (named) configuration file
/etc/proftpd.conf - proftpd server configuration file
/etc/pure-ftpd.conf - pure-ftpd server configuration file
/etc/valiases/domainname - catchall and forwarders are set here
/etc/vfilters/domainname - email filters are set here
/etc/userdomains - all domains are listed here - addons, parked,subdomains along with their usernames
/etc/localdomains - exim related file - all domains should be listed here to be able to send mails
/var/cpanel/users/username - cpanel user file
/var/cpanel/cpanel.config - cpanel configuration file ( Tweak Settings )*
/etc/cpbackup-userskip.conf -
/etc/sysconfig/network - Networking Setup*
/etc/hosts -
/var/spool/exim -
/var/spool/cron -
/etc/resolv.conf - Networking Setup--> Resolver Configuration
/etc/nameserverips - Networking Setup--> Nameserver IPs ( FOr resellers to give their nameservers )
/var/cpanel/resellers - For addpkg, etc permissions for resellers.
/etc/chkserv.d - Main >> Service Configuration >> Service Manager *
/var/run/chkservd - Main >> Server Status >> Service Status *
/var/log/dcpumon - top log process
/root/cpanel3-skel - skel directory. Eg: public_ftp, public_html. (Account Functions-->Skeleton Directory )*
/etc/wwwacct.conf - account creation defaults file in WHM (Basic cPanel/WHM Setup)*
/etc/cpupdate.conf - Update Config *
/etc/cpbackup.conf - Configure Backup*
/etc/clamav.conf - clamav (antivirus configuration file )
/etc/my.cnf - mysql configuration file
/usr/local/Zend/etc/php.ini OR /usr/local/lib/php.ini - php configuration file
/etc/ips - ip addresses on the server (except the shared ip) (IP Functions-->Show IP Address Usage )*
/etc/ipaddrpool - ip addresses which are free
/etc/ips.dnsmaster - name server ips
/var/cpanel/Counters - To get the counter of each users.
/var/cpanel/bandwidth - To get bandwith usage of domain
===
| 1 comment

Compiling and Installing MySQL on Linux/CentOS


Download MySQL Source Code fromhttp://dev.mysql.com/downloads/

shell> groupadd mysql
shell> useradd -g mysql mysql
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
shell> cd mysql-VERSION
shell> ./configure --prefix=/usr/local/mysql
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql var
shell> bin/mysqld_safe --user=mysql &
----
yum install ncurses-devel
yum install gcc gcc-c++
libxml2-devel
libxml2-utils
make clean

Follow this command by typing;

#./configure --prefix=/usr/local/mysql --localstatedir=/home/system/data/mysql --disable-maintainer-mode --with-mysqld-user=mysql --enable-large-files-without-debug (enter)
Sit back and wait for a while while configure does its thing, once the system returns the prompt to you issue the following command;

#make (enter)

Unless you have a very fast machine this will take some time, so spend time with your family, grab a beer, go for a walk, or whatever you're into. When you get back, assuming the system has returned the prompt to you issue the following command;
#make install (enter)

Cool !, MySQL is installed, there are only a couple things left to do to get it working, first we need to create a group for MySQL as follows;
#/usr/sbin/groupadd mysql (enter)

Then we create a user called mysql which belongs to the mysql group;
#/usr/sbin/useradd -g mysql mysql (enter)

Now we install the database files as follows;
#./scripts/mysql_install_db (enter)

Then we make a couple minor ownership changes;
# chown -R root:mysql /usr/local/mysql (enter)
# chown -R mysql:mysql /usr/local/mysql/data (enter)

Last but not least, we use vi to add a line the ld.so.conf file as follows;
#vi /etc/ld.so.conf

And we add the following line;
/usr/local/mysql/lib/mysql

Thats it, MySQL is installed, you can run it by issuing the following command;
#/usr/local/mysql/bin/mysqld_safe --user=mysql &

And as long as we're here we might as well set a root password for MySQL as follows;
#/usr/local/mysql/bin/mysqladmin -u root password new_password
Where new_password is the password you want to use.

Starting Apache and MySQL Automatically 
---------------------------------------------------

Lets start with MySQL, as root make your working directory that of the MySQL source directory you worked with earlier, something similar to;
#cd /home/xxxx/mysql-4.0.16

Then, copy the file mysql.server to your /etc/init.d directory as follows;
#cp support-files/mysql.server /etc/init.d/mysql

Ok, lets create some links in the startup folders for run levels 3 and 5.
#cd /etc/rc3.d
#ln -s ../init.d/mysql S85mysql
#ln -s ../init.d/mysql K85mysql
#cd /etc/rc5.d
#ln -s ../init.d/mysql S85mysql
#ln -s ../init.d/mysql K85mysql
#cd ../init.d
#chmod 755 mysql

Thats it for MySQL, it should start automatically now when you reboot your machine!
| 1 comment

HyperVM


HyperVM is a multi-platform, multi-tiered, multi-server, multi-virtualization web based
application that will allow you to create and manage different virtual machines each
based on different technologies across machines and platforms. Currently it supports
OpenVZ and Xen virtualization and is available for RHEL 4/5 as well as CentOS 4 and
CentOS 5.

Installation

You wouldn't need to install OpenVZ in addition to HyperVM in the main node since
HyperVM will also install OpenVZ . Also The slave is needed only if you want to control
OpenVZ containers on remote servers with HyperVM.

Installing A HyperVM Master

The HyperVM master allows you to control OpenVZ containers on the master itself and
on slave machines. Even if you don't want to run slave machines, you need a master.
First step is to disable selinux. For this you can run

#setenforce 0
Afterwards we install HyperVM as follows:

#wget http://download.lxlabs.com/download/hypervm/production/hyper- vminstallmaster.
sh

#sh ./hypervm-install-master.sh --virtualization-type=openvz

Next step is to configure the boot loader. For that you have to edit the
/boot/grub/grub.conf and change the value assigned to default to appropriate one inorder
to make OpenVZ kernel as the default kernel.

Then we reboot the system:
#reboot

Using HyperVM

1. You can use either https://IP_ADDRESS:8887 or http://IP_ADDRESS:8888.
2. Log in with the user admin and the password admin.
3. The first thing you are asked to do after the first login is to change the default
password for admin.
4. The next thing you are asked to do is configure LXguard. LXguard is a tool like
fail2ban or DenyHosts that blocks remote IP addresses from which too many logins
originated (this is to prevent brute-force attacks.
Fill in the maximum number of failed login attempts that are allowed before LXguard
kicks in and blocks the IP.
You should then go to the Whitelist tab and whitelist your own IP

Please check how HyperVM looks:
















1. Creating IP Pools

Before we can create our first OpenVZ container, we need to define an IP pool from
which new containers can take an IP address. Go to Ip Pools. On the Ip Pools page, click
on the Add Ip Pool tab. You have to provide the IP Pool Name, First IP address, Lst
IP address, Resolv Entries and Gateway in the page showing. This is almost similar to
the way through which we add IP pools in solusvm master.

2. Define at least one resource

Besides creating an IP pool, we must also define at least one resource plan before we
can create our first OpenVZ container. On the HyperVM Home, click on Resource
Plans, and then on the Add Resource Plan tab.
Fill in a name and description and then specify the resources for each OpenVZ container
that will use this resource plan

3. Create VM

Now we can create our first OpenVZ container. Click on the Virtual Machines icon in
the Resources section of the HyperVM Home; on the page that loads, click on the Add
Openvz tab
Provide a name for that new OpenVZ container and fill in a root password. Type in a
free IP address from the IP pool that you've created before. Then rovide a hostname,
select the resource plan you've just created and an OS template for the container, then
click on Add.
After a few moments, you should see your new container on the Virtual Machines
overview page. You can start and stop the container by clicking on the bulb in the S
column, but you can as well control it from its own control panel that you can reach by
clicking on the container's name in the VM Name column.
| 1 comment

SolusVM (Solus Virtual Manager)


Solus Virtual Manager (SolusVM)

It is a powerful GUI based VPS management system with full OpenVZ, Linux KVM,
Xen Paravirtualization and Xen HVM support. SolusVM allows you and your clients to
manage a VPS cluster with security & ease. With SolusVM you can easily do the
following:

1. Start, Stop & Reboot your VPS.
2. Monitor your VPS Servers DiskSpace, Memory & Bandwidth Usages.
3. Rebuild the VPS back to it's original state (Fresh).
4. Change the VPS Servers Hostname.
5. Change the VPS root password.
6. Login to the VPS directly via a Serial SSH Console.

Installation

Installing a Master

In SSH as root do the following:

wget http://soluslabs.com/installers/solusvm/install
chmod 755 install
./install

Please note that you can not Install a SolusVM Master on a Xen Slave Directly, you can
however install your Master on a Xen VPS which is hosted on this slave, it just cant be
installed directly onto the slave.

You will now be presented with the following menu as illustrated below:











Select option 1
You will now be presented with the next menu as illustrated below:

If you need to install a master that won't host any virtual servers, select option 2
(recommended)
If you need to install a master that will host virtual servers, select option 1
Once installed go to http://myipaddress:5353/admincp/ and login using username
vpsadmin amd password vpsadmin
Installing a Slave
In SSH as root do the following:
wget http://soluslabs.com/installers/solusvm/install
chmod 755 install
./install
You will now be presented with the following menu as illustrated below:











Select option 2
You will now be presented with the next menu as illustrated below:

















If you need to install a slave that will host OpenVZ virtual servers, select option 1
If you need to install a slave that will host Xen virtual servers, select option 2
If you need to install a slave that already hosts virtual servers, select option 3

Basic actions in solusvm panel

Add a Slave Node

Hover over "Nodes" and click "Add Node".
a) Node Name - Enter a name for your node so that you can recognise it easily. Some use
"Node1" or some use "Server 1", however, you can use whatever you please
b) IP Address - Enter the IP address of the slave server you just made.
c) Hostname - Enter the Hostname of the slave server you just made.
d) SSH Port - Enter the SSH port of the slave server you just made.
e) ID Key - Enter the identification key that the SolusVM slave installer gave you.
f) ID Password - Enter the identification password the SolusVM installer gave you.
g) Country - Enter the country where the server is located.
h) City - Enter the City where the server is located.
i) Add Node -- The management server will now attempt to connect to the slave and
verify any needed data such as OpenVZ installation and the correct variables for the

SolusVM slave installation.

Create a Client

1. Entering the clients information When entering clients information,
a) Reseller : This box is to choose whether or not the client should be owned by a
reseller. If not, then choose Root (No Reseller).
b) First Name : Enter your clients First Name.
c) Last Name : Enter your clients Last Name.
d) Company : Enter your clients company name. If they do not have one, leave it blank
or enter N/A.
e) Email Address : Enter your clients email address.
f) Username : Enter your clients desired username, or a username that you want the
client to have, such as: vps1 or 101 or maybe even 1
g) Password : Enter the requested password for your clients account.
h) Add Client:

Create a Virtual Server

Hover over the "Virtual Servers" menu and click "Create {Type} Virtual Server". Where
{type} is, you would choose the corresponding Virtualization, i.e. OpenVZ, Xen or
HVM.
a) Node : Choose which server you want the VPS to be created on, whether it be
localhost or node99 .
b) Plan : Choose which preset plan (specifications) you would like your new VPS server
to have, if you don't have one setup, You can still continue creating a "Custom" VPS.
Now, click "Continue".
c) Client : Choose which client this VPS is being made for. If you haven't already setup a
client, then you need too.
d) Hostname : Enter the Hostname that your client requested when ordering their VPS.
e) Operating System : Choose which operating system the VPS should have.
f) IP Address : Select the VPS servers main IP address. You can add more IPs after the
VPS has been created. If there is a notice displaying "No Available IP Addresses" then
you need to add an "IP Block", otherwise, you cannot continue.
Now, if you chose a plan on the first stage of creating the VPS then all you have to do
now is enter the Username either asked for by the client or designated by yourself and
then the password, either asked for by the client or designated yourself. Once you have
done that, you can click "Create Virtual Server", if you didn't choose a resource plan,
then read on.
g) Hdd Space: Enter the amount of hard drive space you would like this particular VPS
to have. Remember to type the amount in GB not MB.
h) Guaranteed RAM: Enter the amount of Guaranteed Memory the VPS should have.
Remember to type the amount in MB not GB.
i) Burstable RAM: Enter the amount of Burstable Memory the VPS should have.
Remember to type the amount in MB not GB.
j) Bandwidth: Enter the amount of Bandwidth the VPS should have. Remember to enter
the amount in GB not MB.
k) Create Virtual Server

OpenVZ migration Around SlousVM cluster

On the node that hosts the container run the following commands

wget http://files.soluslabs.com/solusvm/scripts/keyput.sh
chmod a+x keyput.sh
./keyput.sh <destination_node_ip> <destination_node_port>
vzmigrate -v --ssh="-p <destination_node_port>" <destination_node_ip>
<container_id>

When the restore is complete you need to update SolusVM so it knows where the vps has
been moved to.
In SSH on the master run the following command

/scripts/vm-migrate <VSERVERID> <NEWNODEID