COMS148

LINUX Command Notes




Linux System Information and Utilities NOTES
 

ADMINISTRATIVE and SECURITY-----------------------------------------------------
 To change root password when forgotten.  Get into single usermode and issue passwd root.
    Type 'b' at GRUB bootloader menu.
    Get into single usermode.
    Append SINGLE to kernel line using editor 'e'.
    Get back to GRUB by entering 'b'.
    Issue passwd root at prompt sb-2.xx#
    Exit and reboot.
commands:
 hostname  
 visudo
 useradd
 usermod
 userdel
 users
 who
 passwd  
 find / -user  -print
 du -s /home/*             disk usage
 chmod rwx          change access permissions  (4-read, 2-write, 1-execute)
 chown       change owner of files
 uid             displays UID and GID numbers of username 
data:
 /etc/sudoers              semi-priv users defs   
 /etc/passwd               lists all users with logins


AUTOMATION  --------------------------------------------------------------------
commands:
 chkconfig --list | grep smb     shows status of smb automation
 chkconfig --add    adds task and builds links in /etc/rcn.d directories
 chkconfig --del    deletes task and removes links in /etc/rcn.d directories
 chkconfig --level n smb on|off  sets runlevel n either on or off  
 serviceconf &                   brings up Service Configuration task autostart panel
 runlevel                        shows current (and maybe last) runlevel
 telinit n    n=0,1,2,3,4,5,6    init command will bring system to runlevel n
 service     restart|stop|start|status
 crontab fname.crontab           start time utility using configuration file
data:
  /etc/sysctl.conf               modify kernel parameters at runtime and boot time,
                                 the parameters available are found under /proc/sys/
  /etc/inittab                   entry id:X:initdefault:  change 'X' from '3' to '5'.
  fname.crontab                  cron entries for regularly scheduled tasks 
                                 Field      Description     Valid Values
                                   1        Minute,min,,    0-59
                                   2        Hour,hr,,       0-23 
                                   3        Day of Month,,  0-31
                                   4        Month,,         1-12
                                   5        Day of Week,,   0-7 
                                   6        pathname of task module  
                                   7        pathname of task parms

 
AUTOMATIC FILE SERVICES (autofs) -----------------------------------------------
data:
 /etc/auto.master             automount targets
 /etc/auto.misc               automount definitions
commands:
 /sbin/service autofs start | stop | restart | status  | reload  
 

BASH and Scripts ---------------------------------------------------------------
debug:
 bash -x   
 bash -v   

 
BOOT ---------------------------------------------------------------------------
Install GRUB Boot Loader on target disk:
 /sbin/grub-install /dev/hda  --recheck
 /sbin/grub-install /dev/hda  --root-directory=/boot  '(hdnumber)'
Correct GRUB Boot Loader during RESCUE:
 chroot /mnt/sysimage
 grub
setup floppy:
 (use makeboot under control of Linux) 
 reboot
 root (fd0)
 setup (fd0)
 quit
setup MBR for primary (not secondary) disk drive:
 reboot
 find /boot/grub/stage1
 root (hd0,x)     where x is partid 0,1,...n
 setup (hd0)      important: not hd0,x otherwise will write on partid not MBR.
 quit
from disk starting with floppy:
 reboot
 find /boot/grub/stage1
 kernel (hd1,0)/vmlinuz-2.4.18-14 root=/dev/hdb1 ro
 boot

 
C++ COMPILING and EXECUTION -----------------------------------------------------
commands:
 gcc  -Wall -Werror -Wno-deprecated -o outputname  inputname.c          C compiling
 g++  -Wall -Werror -Wno-deprecated -o outputname  inputname.C          C++ compiling
 ./outputname               Execution
 time ./outputname            Timed Execution
 rpm --query glibc         Queries the glibc version and level
 rpm --query gcc           Queries the C-compiler version and level
 

DISK MANAGEMENT ----------------------------------------------------------------
commands:
 mount /mnt/cdrom
 mount /mnt/cdrom1
 ls -dl  
 df -h              display diskspace usage
 mkdir              make directory
CD:
 cdrecord -scanbus
 cdrecord -v speed=2 dev=0,0,0 -data /home/scanner/checks/
  note: dev=x,y,z  where x=drive,y=SCSI_id, y=Logical_Unit_Number
 cdrecord -v speed=2 dev=0,0,0 blank=all
 cdrecord -v speed=2 dev=0,0,0 blank=fast    only toc and directory pointers
 cdrecord -v dev=0,0 speed=0 -data  /home/gjcullen/temp/pserver.jar
 mkisofs -U -o /var/tmp/gjc.back  /home/gjcullen/mydirectory       all ISO stds off
 mkisofs -U -m photos -o /var/tmp/gjc.back  /home/gjcullen/mydirectory     with photos excl
 mkisofs -o /var/tmp/gjc.back  /home/gjcullen/mydirectory
 cdrecord -v speed=2 dev=0,0,0 blank=all -data /var/tmp/gjc.back
 cdrecord -v speed=2 dev=0,0,0 blank=fast -data /var/tmp/gjc.back
DVD: 
 dvdrecord -scanbus
 dvcrecord -v speed=4 dev=0,0,0 -data /home/scanner/checks/

 
DISK MANIPULATION and MAINTENANCE ----------------------------------------------
ls -dl  
df -h                 diskspace usage
fdisk -l              view layout 
mkdir                 to match mountpoint in /etc/fstab table for new disk.
rm              removes file with prompting
rm -f -r        removes files (directories) recursively with no prompting
du -s /home/*         disk usage
Partitioning utilities
 fdisk  /dev/hdx  
 parted  /dev/hdx   
Copying partitions on current device
 parted cp source_device from_partno to_partno
Formatting partitions
 /sbin/mkfs -t ext3 /dev/hdbx
       mkfs -t ext3  /dev/fd0             format diskette to Linux format 
       mkfs -t vfat  /dev/fd0             format diskette to Windows format 
Labelling partitions
 e2label /dev/hdbx /newname            Re-labelling to newname
Formatting diskettes
 fdformat /dev/fd0H1440
 mke2fs /dev/fd0
 mount -t ext2 /dev/fd0 /mnt/floppy
 *** do something ***
 umount /mnt/floppy
Mounting linux hard disks
 /sbin/mount -t ext3 /dev/hdxy /some_name/      x=a,b,c,d,...  y=1,2,3,...
Make filesystem on linux hard disks
 mkfs.ext3 /dev/hdxy      x=a,b,c,d,...  y=1,2,3,...
   

DESKTOP PROBLEMS ---------------------------------------------------------------
 startx
 XFree96 -configure
 XFree86 -xf86config /root/XF86Config.new
 Garbled... Ctrl+Alt+F2,  get Login, Pass, SHutdown X servy by typing  init 3
  then run XF86Config 

 
Dynamic Host Configuration Protocol (DHCP) -------------------------------------
commands:
 /etc/init.d/dhcpd start    | start | stop 
 /sbin/chkconfig dhcpd on    | off
data:
 /etc/dhcpd.conf
 /var/lib/dhcp/dhcpd.leases

 
DOMAIN NAME SERVICES (DNS) -----------------------------------------------------
commands:
 /etc/init.d/named restart   | start | stop 
 /sbin/service/named restart | start | stop  | restart | status 
 /sbin/chkconfig named on    | off
 host       replacement for nslookup of IP address(es)
data:
 /etc/named.conf             DNS parameters
 /etc/resolv.conf            IP addresses of DNS servers 
 /var/named/*
 

EMAIL --------------------------------------------------------------------------
commands:
data:
 /etc/sendmail.cf
 
 
ENVIRONMENTAL VARIABLES --------------------------------------------------------
commands:
 env          display all environmental variables in effect
 CLASSPATH=$CLASSPATH:
 export         ie. export CLASSPATH
 setenv  string
 set               shows all variables and settings
 echo $
 

FILE COMPRESSION----------------------------------------------------------------
commands:
 zip, unzip, tar, gzip, gunzip
 tar -cvf archive_name files...        make archive file 
 tar -xvf archive_name pathname        extract archived files 
 tar -zxvf archive_name pathname       extract archived files from GZIPped file 
 
 tar cf ‐ . | zip backup ‐            accept from piped input and compress
 unzip ‐p backup | tar xf ‐           recover files
 
 gzip tarfile_name         compress zipped files
 gzip -d archive_name      uncompress zipped files
 
 zip  pserver.zip  /home/pserver/*.*
 unzip  pserver.zip  -d /newhome/pserver/
 
 

GREP ---------------------------------------------------------------------------
count     ls -s -l -S | grep 'something' -c


GHOSTSCRIPT --------------------------------------------------------------------
gs -h
rpm -Uv ghostscript-7.07-1.i386.rpm

 
HTTP SERVER --------------------------------------------------------------------
commands:
 /etc/init.d/httpd          start | stop 
 /sbin/chkconfig httpd        on  | off
data:
 /etc/httpd/conf/httpd.conf            configuration
 /var/www/html                         html pages
 /var/log/httpd/access_log             access logging
 /var/log/httpd/error_log              error logging
 /etc/hosts                            list of hosts


INTERRUPT SIGNALS --------------------------------------------------------------
data:
man 7 signal                    manual page for signals
 
 
INFORMATION about SYSTEM -------------------------------------------------------
commands:
 uname -a               identify system
 hostname               query  the name of the system
 hostname      change the name of the system
 less /etc/passwd       show who has accounts on the system
 mount                  shows all mount points in effect
 stat         shows the status of a particular file
 man           shows manual pages for command or function
 info          shows more use information
 /sbin/lspci            query installed pci hardware devices
 /sbin/lsusb            query installed usb hardware devices
 cat /proc/cpuinfo      query CPU processor
 dmesg                  shows wrap-around kernel messages
 
 
KERNEL (nucleus) SYSGEN (build) ------------------------------------------------
commands:
 cd /usr/src/linux.....
 make mrproper
 make menuconfig or make xconfig
  use as input your last known good config,
  save the output config for later input, do not overwrite the input config.
 make dep > dep.log 2>&1
 make clean
 make bzImage > bzimage.log 2>&1	
 make modules
 make modules_install
 make install
 Check your and /boot/initrd.... and  /boot/grub/grub.conf  files. 
 ..reboot..
 Select new nucleus from GRUB menu. 
 DONE... 

 
 mkinitrd -v /boot/initrd-n.n.n.img x.y.z      where x.y.z must be module subdirectory 
                                               in /lib/modules/x.y.z
 make dep && make clean bzImage modules modules_install
 mount /boot
 cp /usr/src/linux/arch/i386/boot/bzImage /boot/
 reboot
data:  
 /usr/src/xxxxx
 

MAINTENANCE --------------------------------------------------------------------
commands:
 uname -r                            show OS release level 
 uname -v                            show time of last kernel build                   
data:  
 
 
MESSAGING ----------------------------------------------------------------------
commands:
 wall          will send message to all logged on users
 
 
MONITORING----------------------------------------------------------------------
commands:
 top                    real time task and system performance monitor
 ps -e                  list of all process ids 
 ps aux | less          list of process ids 
 ps -e -f -m | grep  list of process ids and all threads for something 
 who -umH               who is on this terminal 
 jobs                   what jobs are running in background 
 watch df  (or ls -l)   monitor disk usage in realtime
 kill              terminate a process
 iostat
 vmstat

 
MOZILLA -------------------------------------------------------------------------
data:
 /usr/local/mozilla/   
 plugins using gcc32 coding for java

 
NETWORK FILE SERVICES (NFS) ----------------------------------------------------
data:
 /etc/export           contains accesses and permissions.
 requires UDP/TCP port access to 111 (sunrpc), 369 (rpc2portmap) and 2049 (nfs services) 
 requires PORTMAP daemon
commands:
 /etc/rc.d/init.d/nfs            start NFS
 /sbin/service nfs  start | stop | restart | reload | status
 /sbin/service nfs reload        reloads the nfs permits
 exportfs
 /usr/sbin/showmount             show all users with NFS mounts
 /sbin/chkconfig nfs on
 /usr/sbin/exportfs  -ra         reloads exported file system for NFS
 cat /etc/services | grep     show tasks that are using port 
 

NETWORK ------------------------------------------------------------------------
commands:
 nmap -sT -O localhost     verify which ports are in use
 netstat -anp | grep 
 lsof -i | grep          show port bindings
 
 netstat -r -n             query network routing table with resolved names
 route                     query network routing table 
 
 dig                       query network domain name servers
 
 /etc/init.d/network restart   | start  |  stop       Restart,etc Network

 /usr/sbin/traceroute      Show path to ip_address
 ping                      Test connectivity

data:
 /etc/sysconfig/network-script/ifcfg-ppp0    
 /etc/sysconfig/network     set GATEWAYDEV to PPP0 | ip.address
 /etc/xinetd.conf           xinetd configuration file
 /etc/xinetd.d/*            all xinetd-started services (DISABLE=yes|no)


DIALUP -----
commands:
 ps x | grep ppp
 /sbin/ifconfig ppp0     show status for modem with IPaddress  
 /sbin/ifconfig  up  | down      ie. ifconfig ppp0 up
 data:
 

ETHERNET -----
commands:
 cat /proc/net/dev
 ps x | grep eth
 /sbin/ifconfig eth0
 /sbin/ifconfig  up  | down      ie. ifconfig ppp0 up
 WIN: winipcfg, msconfig, mscnfig
 data:
 

ROUTING and IPTABLES -----
commands:
 chkconfig --level 345 iptables on               Sets the iptables scripts to start autom at boot time
 iptablesflush                                   script to flush all iptables
 gjciptables                                     script to reload all iptables
 /etc/init.d/iptables restart | start | stop     Recycle iptables
 /sbin/lsmod | grep ip                           See if modules used by iptables are loaded
 /sbin/iptables
 /sbin/iptables  -t nat -R POSTROUTING 1 -o eth1 -j MASQUERADE     changes chain 1
 cp /etc/sysconfig/iptables  /etc/sysconfig/iptables.old
 /sbin/iptables-save  > /etc/sysconfig/iptables
  (or service iptables save)
 /sbin/iptables -L
 /sbin/iptables -L -t nat
 service iptables restart|stop|start|status
data:
 /etc/sysconfig/iptables                          Iptables config is saved here
 Enable IP Forwarding
  /etc/sysctl.conf               set  net.ipv4.ip_forward = 1
  /etc/sysconfig/network/sysctl.conf     
 /etc/lpd.conf
 

PORTS -----
commands:
 nmap -sT -O localhost
 cat /etc/services | grep nnn
 netstat -anp | grep nnn
 lsof -i | grep nnn
 

TCPIP and DIALER -----
commands:
 /sbin/ifconfig
 /sbin/ifconfig ppp0 up  | down
 ls -l /dev/modem
 wvdialconf create
 /sbin/route -n
 netstat -r
data:
 /etc/resolv.conf
 /etc/hosts
 /etc/host.conf
 /etc/nsswitch.conf
 /dev/ttys0     (COM1)
 /dev/ttys1     (COM2)
 /etc/wvdial.conf
 /etc/ppp/options
 
End NETWORK --------------------------------------------------------------------

 
OPENOFFICE ---------------------------------------------------------------------
Setup User Access
 /opt/OpenOffice.org1.1.2/./setup 
 

PRINTING ------------------------------------------------------------------------
commands:
/usr/sbin/lpc
  status                 to check status of printers
  enable    to enable a printer
  disable   to disable a printer
  start all              to start all printers
  stop all               to start all printers
 lpr filename.filext      for offline printing
 lpr -Plp0 test.data
 lp -d   file          print the file to designated printer
 lprm -a all           will remove all print from all printers
 lprm -Plp0  167       will remove jobid 167 from print queue of lp0
 lprm -PHP952C@GJCULLEN nnn       will remove jobid nnn from print queue of HP952C
 lprm -Plp0            will remove jobs to printer lp0
 lpq                   see print jobs queued
 printconf -gui
 /usr/sbin/lpc reread
 /usr/sbin/checkpc -f     check printer attachments
 printtool
 cat /etc/hosts > /dev/lp0
 /sbin/service lpd   restart stop start status
 /sbin/service cups  restart stop start status
 /usr/bin/lpstat -t   checks all cups printers
 Windows IPP client: wpnpins
 telnet: POST / HTTP/1.1 
data:
 /etc/cups/cupsd.conf           cups configuration
 /etc/cups/client.conf          cups client config
 /etc/printcap
 /var/log/messages

 
RECOVERY -----------------------------------------------------------------------
commands:
 fsck /dev/hdxn  -p -y -v      for automatic repair
 efsck /dev/hdxn  -p -y -v     for extended automatic repair

 
REMOTE CONNECTIVITY ------------------------------------------------------------
commands:
 from client machine:    xhost +remotename
 from client machine:    telnet -l user loginid
 or use exportxhost 
 at server via telnet:   export DISPLAY=remotename:0
 at server           :   xterm  -title "Terminal Window from Server"
 or use addxhost 
       delxhost 
 

RPM ----------------------------------------------------------------------------
/usr/bin/redhat-config-packages 
commands:
 rpm -qa | egrep kernel              show all kernel related RPMs installed 
 strace -f rpm  ....                 trace rpm
 mv __db*.*   /temp/                 save old rpm db files 
 rpm --rebuilddb -vv                 rebuild rpm db files
data:  
 /var/lib/rpm                        directory 
 rpm -qip              displays information on a package
 rpm -Va                             verify entire system 
 rpm -qf              find package owner of this file
 rpm -iv               install package 
 rpm -e                remove package 
 
 
SHUTDOWN------------------------------------------------------------------------
commands:
 shutdown
 reboot
 poweroff
 halt        shutdown -r now
 

STORAGE and MEMORY -------------------------------------------------------------
commands:
 free
 free -m
 

SQUID --------------------------------------------------------------------------
commands:
 ps  x | grep squid
 /etc/init.d/squid  restart   | start  | stop
data:
 /var/log/squid
 /etc/squid/squid.conf
 

SAMBA and SWAT SERVICES ---------------------------------------------------------
commands:
 ps  x | grep swat
 /sbin/service smb restart               restart samba server
 http://localhost:901                    use root for access
 testparm   smb.conf                     to sanity check SAMBA printing parameters
 smbclient -L yourhostnamedata           list shares available on server
 smbclient //yourhostname/aservicedata:  connect with a UNIX client
 C:\> net use d: \\servername\service    connect from a DOS client
data:
 /etc/xinetd.d/swat
 

SYSLOG --------------------------------------------------------------------------
commands:
 service syslog restart
 tail -f /var/log/pppmsg
 ifup ppp0
 ifdown ppp0
data:
 /etc/syslog.conf
 modifications:
 daemon. *  /var/log/pppmsg
 local2.*   /var.log.pppmsg
 

Telnet --------------------------------------------------------------------------
commands:
 ps  x | grep telnet
 /etc/init.d/telnetd   start | stop | restart | status
 telnet               interactive terminal connect to another machine
data:
 /etc/issue.net                change connection banner
 /etc/issue                    change connection banner


UTILITIES -----------------------------------------------------------------------
commands:
 unzip -a 
 zip  
 dos2unix  
 CLASSPATH=........:........:.....: $CLASSPATH
 xport CLASSPATH
Find data: 
 find / -name  xxxxxxx -print     will find member anywhere on system
 find / -name   -exec -ls -Fla {} \;
 whereis      will find library if in PATH
 /utilities/recover    deleted files
 locate  xxxxxx        Locates files and directories that have string xxxxx in them.
 

USB ----------------------------------------------------------------------------
commands:
 modprobe usb-storage       ensure that usb modules loaded into storage
data:
 /etc/fstab
 

VSFTP FTP-----------------------------------------------------------------------
commands:
 ps  x | grep ftp
 /etc/init.d/vsftpd   start | stop | restart | status
 ftp               ftp connect to another machine
data:
 /etc/vsftpd.conf              configuration
 /etc/vsftpd.user_list
 /etc/xinetd.d/vsftpd
 /var/log/vsftpd.log           logging data
 /etc/hosts.allow              hosts and facilities allowed via INET
 
 
XINETD --------------------------------------------------------------------------
commands:
 ps  x | grep xinetd
 /etc/init.d/xinetd  restart   | start  | stop
data:
 /var/log/squid
 /etc/squid/squid.conf
 /etc/hosts.deny               hosts and facilities denied via INET
 


 

[Return to Professor Page]