List of Useful Linux Commands

Here is a list of basic Linux commands:

SYSINFO

Server Release Info cat /etc/redhat_release
lsb_release
Server Type dmidecode
Hardwareinfo lspci
lsusb
lshal
Note: hal = hardware abstraction layer
Operating system uname -a
Memory cat /proc/meminfo
free -m
cat /proc/slabinfo
CPU (Type,number,etc) cat /proc/cpuinfo (detailed)
Disk drives fsdisk -l
sfdisk -l (advanced server)
partprobe -s <device>
Kernel File and associated directories /boot/initrd.????.img
/boot/vmlinuz
kernel 32 or 64 uname -a
uname -m
getconf -a | grep -i ‘long_bit’
Display Firmware boot into the BIOS (normally F2 or F12)
Display IRQ, IO ports and DMA /proc/interrupts
/proc/ioports
/proc/dma
GUI admin tool linuxconf

MEMORY AND SWAP

MEMORY cat /proc/meminfo (detailed)
Page size (memory) /usr/bin/getconf -a | egrep -i  ‘pagesize|page_size’
Display Swap cat /proc/swaps (detailed)
swapon -s
Adding swap device:
create partition with fdisk (type 82)
file (create 50MB swap file):
dd if=/dev/zero of=/var/swapfile
bs=1024 count=50000
mkswap <device>|<file>
swapon <device>|<file>
update /etc/fstab
removing swap swapoff <device>|<file>
Remove device or file as normal

DISKS, FILESYSTEMS AND DEVICES

Disk drivers fsdisk -l
sfdisk -l (advanced server)
partprobe -s <device>
Disk serial number, Type etc., hdparm -i /dev/hda
hdparm -i /dev/hda (detailed)
hdparm -Tt /dev/hda (speed test)
sdparm -i /dev/sdb
cat /proc/ide/ide0/hda/model
cat /proc/scsi/scsi
Disk Disk Partitions fdisk -l
sfdisk -l (advanced server)
cat /proc/partitions (very high level)
cat /etc/fstab
List raw partitions ##old way
/etc/sysconfig/rawdevices
service rawdevices start
chkconfig rawdevices start
##New way, Edit below file
/etc/udev/rules.d/60-raw.rules
udevinfo -d or udevadm
##Display raw partitions
raw -qa
Filesystem commands df -k
df -h
Filesystem (create/remove) mkfs -t ext 3 /dev/sdb1
Tune file system tune2fs
tune2fs -l /dev/sda1
Force fsck touch /forcefsck
shutdown -Fr now
tune2fs -l /dev/sdb<?> | grep -i ‘filesystem state’
backup filesystem dump/restore
tar
dd
cpio
Display the boot device cat /boot/grub/grub.conf
cat /etc/lilo.conf
grub = grand unified boot loader
lilo= linux loader
setting the boot device /boot/grub/grub.comf
/etc/lilo.conf
Creating boot device (MBR) grub-install <raw-device>
lilo -v
Fromat floppy drive floppy –probe (use device obtained below)
floppy — createrc  >  /etc/fd0
floppy  –format /dev/fd0
mkfs /dev/fd0
Mount/Unmount floppy mount /dev/fd0/mnt/floppy
unmount /mnt/floppy
Mount/Unmount CDROM mount -rt iso9660 /dev/cdrom/mnt/cdrom
umount /mnt/cdrom
eject cdrom
Create boot disk or recovery tape mkboot ‘uname -r’ (boot dsikette)
boot cdrom/diskette (single user) using the grub window append the word single to the kernel line
boot into maintenance mode f10 or f12
Device Paths floppy:
/dev/fd0
disk:
/dev/hda or/dev/sda
/dev/hdb or /dev/sdb
tape:
cdrom:
/dev/hda (depends on number of IDE disks)
update /dev directory /dev/MAKEDEV <device>
remove or change a device n/a
List device drivers cat /proc/devices

NETWORKING

Basic network information (hostname, ip address) /etc/sysconfig/networks
/etc/sysconfig/network-scripts/ifcfg-eth0
Displaying Network interfaces ifconfig
system-config-network (GUI)
Configure network interfaces ifconfig
Starting and stopping a network interface /sbin/ifup eth0
/sbin/ifdown eth0
Setting NIC speed mii-tool -F 100baseTx-Fd eth0
ethtool -s eth1 speed  100 duplex full
Change NIC parameters mii-tool -v
ethtool eth1
ethtool -t eth0 online
sysctl -a | grep net*
Display Mac address ifconfig
system-config-network (GUI)
Displaying Network packets tcpdump -i <interface>
ethereal (needs to be installed)
Default router edit /etc/sysconfig/network
add : GATEWAY=<IP address>
display routing table netstat -nr
route -n
Test IPMP , BONDING ifenslave -d bond0 eth1 (detach)
ifenslave -d bond0  eth1 (reattach)
cat /proc/net/bonding/bond0
change the hostname /etc/sysconfig/network
/etc/hosts
sysctl -a | grep hostname
setup DNS /etc/resove.conf
Name service switch file (DNS client_ /etc/nsswitch.conf
/etc/host.conf
/etc/resolve.conf
flush DNS cache ## if installed
service nscd restart
Domain name /etc/sysconfig/network (hostname option)
/etc/resolv.conf
Obtain IP address routing ip route get <IP address>
traceroute
Find services on the network Boot (jumpstart) servers:
rpcinfo -b bootparam 1
NFS server:
rpcinfo -b mounted 1
NIS server/slaves:
rpcinfo -u <yp servers> ypserv

CRASH DUMP

Crash Dump diskdump
netdump
kdump (part of kexec rpm)
/etc/kdump.conf (select where you want the dump to go)
service kdump start
chkconfig kdump on
## to crash the system
echo “c” > /proc/sysrq-trigger
crash (used to analyse crash dumps)

PERFORMANCE MONITORING AND DIAGNOSTICS

CPU top
sar
mpstat
w
uptime
ps
vmstat
procinfo
oprofile
cat /proc/cpuinfo
Memory free
vmstat
top
procinfo
slabtop
sar
cat /proc/meminfo
Network I/O ethtool
mii-tool
netstat
lsof
tcpdump
ip
iptraf
Disk I/O sar -d
iostat
vmstat
lsof
Application strace -p <pid>
NFS nfsstat

KERNEL MODULES AND PARAMETERS

Display loaded modules cat /proc/modules (more detailed)
lsmodLocation:
/lib/modules/’uname -r’ /kernel/drivers
Config:
/etc/modprobe.conf
/etc/modprobe.d
Load modules modprobe <module>
insmod
unloaded modules modprobe -r <module>
rmmod
Set kernel Parameters (tunig) /etc/sysctl.conf (edit and update then reboot)
sysctl -p <filename>sysctl -w param=value
No reboot (dynamically):
echo “250 32000 100 28”> /proc/sys/kernel/sem
echo”536870912″> /proc/sys/kernel/shmmax
echo “4096”> /proc/sys/kernel/shmmni
echo “2097152”> /proc/sys/kernel/shmall
etc……………..
Display kernel parameters sysctl -a
cat /etc/sysctl.conf
cat /proc/sys/kernel/sem
cat /proc/sys/kernel/shmmax
etc……………..
Build kernel cd /usr/src/linux-2.5
edit Makefile (change EXTRAVERSION)
make mrproper
backup .config
make xconfig
make dep
make bzImage
make modules
move nem kernel
make modules_install
change lilo/grub config file
reboot
Interprocess communication ipcs -a

SERVICES

Display services service –status all
start service service nfs start
stop service service nfs stop
reload service service nfs reload
restart service service nfs restart
service status service nfs status
service dependencies n/a
service logging, etc n/a
change service start up chkconfig –level 2345 nfs on
Add a new service ## Create your stop/start
##script in /etc/init.d
chkconfig –add <script>

PATCHING /SOFTWARE

Adding patch patch -p1 <patch>
zcat patch46.gz | patch -p1
Note : -p = # of patch stripping
removing patch patch -R -p1 <patch>
Display installed packages rpm -qa (all packages)
rpm -qa (single package)
rpm -qa (file belongs)
rpm -qi <package> (very detailed)
adding package rpm -Uhv (updates/intalls if not already)
rpm -ivh (install)
removing packages rpm -e <package>
verify package rpm -V <package>
List files ihn package rpm -ql <package>
package directory /var/lib/rpm
List libraries required for binary program ldd <file>

ACCOUNTS

User creation useradd
adduser (These may not work under some flavours)
luseradd (These may not work under some flavours)
To know create user exist or not id name
su – username
Remove all data of user userdel -r name
To verify user password’s status passwd -s username
To remove passwd passwd -d username
To  coustomize any flavours related to user account usermod
To lock user account usermod -s /sbin/nologin username
To revert it back usermod -s /bin/bash username
To lock user passwd usermod -L username
To unlock passwd usermod -U username
Every user is identified with unique user id
Types of users can be created super user (root) UID range (0)
local user (user accounts created in every individual)
domain user (user accounts in a centralised manner)
system user ( Default users created while installing OS)
Domian server (LDAP, NIS, IPA) Domain environment configuration files
UID range for (local and domains)
(1000  — 6,0000)
(1-999) —- reserved for system users
To create a group groupadd user1
Configuration file for group accounts information /etc/group
To add a member into a secondary group usermod -G security username
Removing user from a group gpasswd -d username security
Adding user for a primary group gpasswd -a username security
To change users primary group usermod -g security username
To change username usermod -l u1 username
To change UID for user usermod -u 5000 username
To change group name groupmod -n newname oldname
To change group id number groupmod -g 3333 username
To change name of the user mv /home/username  /home/username2
ls -l /home
usermod -d /home/username2  username2
To recreate user’s home directory mkdir /home/mani
chmod 700 /home/mani
Important bash shell configurations .bashrc  —is used for shell configuration ,, we can store any kind of alias, userdefined functions, userdefined varialble and etc.,
.bash_profile — It is used for login intialinzation which contains global built in variable functions
/etc/skel — Default bash files are stored.
cp /etc/skel/.bash*  /home/username
To change owner of the user chown -R owner:groupname filename or directory
To create user home directory when it is deleted mkhomedir_helper
chmod 700 /home/mani
7 fields in /etc/paswd 1. username
2.userpasswd |***| —/etc/shadow file
3.UID
4.GID  (password file indicates users primary group)
5.  ::—-> banner message, login prompt
6. home directory path for a username
7. shell for a user
3 fields in /etc/shadow 1.username
2. userpassswd (!!) it means it is locked
userpasswd () it means empty passwd
3.account policy information
4 fields in /etc/group 1. group name
2. group passwords—-> passwd file will stored in /etc/gshadow
3.Id number
4. group number
To display the default values useradd -D
/etc/default/useradd
/etc/login.defs  ——> It conatins UID & GID range, It can change default home directory path
Account Policy of a user chage – I —-> value from last expires username
chage -m —-> (minimum no of days
chage -w —> warning
chage -E —-> account expiry
chage -M —-> max no of days
chage username

NFS

Nfs Daemons server:rpc.mountd,nfsd
client: rpc.statd, lockd
NFS files /etc/exports
/var/lib/nfs/etab
/var/lib/nfs/xtab
List nfs clients that have a remote mount /var/lib/nfs/rmtab
Display nfs shares showmount -e localhost
create nfs share redhat-config-nfs (GUI)
/etc/exports (edit and share)
/sbin/service nfs reload
## /etc/exports example
/export *(rw,fsid=0,insecure,no_root_squash,sync)
uncreate nfs share /etc/exports (edit and remove share)
/sbin/service nfs reload
start/change nfs daemons /sbin/service nfs start
stop nfs daemons /sbin/service nfs stop
nfs status /sbin/service nfs status
nfs reload /sbin/service nfs reload
nfs performance nfsstat
nfs options cat /var/lib/nfs/etab

NTP

Time daemons ntpd
ntp setup /etc/ntp.conf (edit with ntp servers)
dateconfig (GUI)
chkconfig —list ntpd
chkconfig — level 2345 ntpd on
/sbin/service ntpd start
ntp daemon options /etc/sysconfig/ntpd
NTP trace commands ntpq -p
ntptarce

LOG FILES

Messages /var/log/messages
/var/log/syslog
/var/log/mail.*
/var/log/cron.log
boot /var/log/boot/dmesg
Error logging logging

SECURITY

Checking the passwd file pwck
Checking the group file grpck
console login (allow/deny) ## No reboot required
/etc/securetty

MISC

Startup grub (GUI)
lilo(text based)
shutdown shutdown -h (halt)
shutdown -r (reeboot)
shutdown -f (fast reboot no fsck)
shutdown -F (force fsck)
change run level halt
init
poweroff
reboot
shutdown
telinit
Init status
0 0- halt
1 1-single user
2 2- multiuser (no networking)
3 3- multiuser (networking)
4 4- unused
5 5- GUI
6 6- reboot
##change default
vi /etcinittab
Startup options single:- use grub to edit kernel line
emergency:- use grub to edit kernel line
linux rescue:- use at the boot prompt
single:-runlevel1, local fs mounted , no network
emergency:-root fs read-only, no init files run
rescue: use cd-rom/network, root mounted as /mnt/sysimage
Startup scripts /etc/init.d
/etc/rc0.d-/etc/rc6.d
Boot prompt commands F10 or F12
Determine the run level who -r
runlevel
Obtain default run level cat /etc/inittab
list locale locale -a
start xwindows startx (shorthand of below)
initx (lots of parms)
Time Zone /etc/sysconfig/clock
/usr/share/zoneinfo/zone.tab
Facebook Comments Box

Comments

Leave a Reply

Your email address will not be published.