Linux Command Cheat Sheet

  • Best Pratices for *inux
    • DMZ – FreeBSD
    • Server – CentOS
    • Desktop – Ubuntu
  • Mount NFS
    • create folder mnt/nfsmount
    • chmod -R 777 mnt /nfsmount
    • mount -t nfs server:/vol/share /mnt/nfsmount/
    • touch /mnt/nfsmount
    • umount /mnt/nfsmount
    • cat /etc/fstab (NFSServer:/dir /mnt nfs defaults 0 0)
  • Check if OS is 32 or 64 Bit
    • getconf LONG_BIT
  • Reset Root Password
    • At boot press F2 to access GRUB
    • Select KERNEL and Press E to edit
    • type single at the end of the line ENTER
    • Select KERNEL and Press B
    • type passwd at prompt and change the password
  • Enable Superuser Root account

sudo – means superuser do

$sudo passwd root

  • Disable root account

$sudo passwd -l root

  • Work on a root console

$sudo -i

  • Remove entering password for sudo

$sudo visudo

%admin ALL=NOPASSWD: ALL

  • Excute .sh script

sh file.sh

chmod +x file.sh

./file.sh

  • System Reboots and Shutdowns

sudo reboot

sudo shutdown -h 0

halt

  • Mount and Unmount

sudo umount /media/CDROM/ << check Capital Letters

mount /media/CDROM/

  • ifconfig
  • Get Linux and Distro Version

cat /etc/*-release

cat /etc/issue

uname -r

  • Edit NIC Configuration

– /etc/sysconfig/networking/devices/ifcfg-eth0

– /etc/network/interfaces (ubuntu)

– /etc/sysconfig/network-scripts/ifcfg-ethX (CentOS, XenServer, RedHat, OLE)

  • Change Hostname

– /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=hostname.com

– nano /etc/hosts

10.0.0.1 hostname.com hostname

127.0.0.1 localhost.localdomain localhost

– sysctl kernel.hostname=NEW_HOSTNAME

– grep -r -l $( hostname)

– vi $( grep -r -l $(hostname) . )

– sudo find /etc/ -type f -exec sed -i ‘s/old_hostname/new_hostname/g’ {} \;

– sudo find /etc -type f -exec grep old_hostname {} \;

– hostname -v yourhostname

– system-config-network

– “newhostname” > /proc/sys/kernel/hostname

  • Static IP Address Format

ifconfig add eth0 192.168.63.129

DEVICE=eth0BOOTPROTO=noneONBOOT=yesNETMASK=255.255.255.0IPADDR=10.0.0.9

iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

  • Renew IP Address

$sudo dhclient -r

# ifdown eth0
# ifup eth0
# /etc/init.d/network restart

  • Enable DHCP

/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=”eth0″
HWADDR=”5A:7B:9B:44:64:00″
NM_CONTROLLED=”yes”
ONBOOT=”yes”
BOOTPROTO=”dhcp”
DHCP_HOSTNAME=”hostname”

  • Edit Firewall (IPtables)
  • Set Static IP on XenServer
    • Edit the file /etc/sysconfig/network-scripts/ifcfg-eth0 and change: BOOTPROTO=dhcpto:BOOTPROTO=none
    • In the file /etc/sysconfig/network-scripts/ifcfg-xenbr0, enter the following parameters, then save the file:IPADDR=<static ip of XenServer Host>NETMASK=<netmask value>GATEWAY=<gateway ip>
  • Mount CD-ROM
    • mount /dev/hdc /mnt/cdrom
    • ls /mnt/cdrom
  • Check Diskspace
    • Df –h check diskspace
  • Find file
    • find {/path/to/directory/} -type f -size +{size-in-kb}k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’         
  • Unload and load the HBA driver which will cause it to rescan the SCSI devices: 
    • modprobe -r <hba-driver-module> 
    • modprobe <hba-driver-module> 
  • IRC
    • /msg nickserv register PASSWORD EMAIL
    • /msg nickserv identify PASSWORD
  • Storage Commands
    • vgscan
    • lvscan
    • pvscan
    • fdisk -l
    • multipath -ll
  • Show open files
    • lsof
  • Show hardware info
    • dmidecode
  • Display continuous clock for 1000 seconds
  • [source]repeat 1000 sh -c ‘( clear ; date +” %H.%M.%S” | xargs banner ; sleep 1)'[/source]
  • DU
  • Watch Startwars
    • telnet towel.blinkenlights.nl
  • Compile from source
    • tar xzf htop-2.2.0.tar.gz
    • cd htop-2.2.0
    • ./configure
    • make
    • sudo make install
    • sudo make uninstall
whoami
cd `
w
ls -a
pwd
last 
uptime
sudo rpm -i htop-2.2.0-3.el7.x86_64.rpm
sudo rpm -e htop
sudo dpkg -i htop_2.0.2-1_amd64.deb
sudo dpkg --remove htop
apt-get
yum install
cat /etc/*release*
cat /etc/*issue*
lsb_release -a
hostnamectl
ldd filename (Check dependencies)