Wednesday, July 27, 2011

Important Daemons and Startup Services

Important Daemons and Startup Services



These are programs or processes which are run at boot time. Some remain in

memory to execute various tasks when required (daemons). Most are started and

stopped with scripts in the /etc/rc.d/init.d directory (see above). The exact

contents of this directory will depend on which packages from a particular

distribution are installed. For example, installing the Apache package will

cause an httpd script to be placed in /etc/rc.d/init.d.


There are man pages on most of these. The Red Hat program tksysv (ntsysv is

the non graphical version) allows root to automatically configure which of

these are started automatically at boot time. The linuxconf program does the

same thing, although I haven't tried it. The utility chkconfig is also

designed to query and configure runtime services for different runlevels. The

www.mandrakeuser.org site has a good page on common services/daemons,

especially those included in recent versions of the Mandrake distribution.


A good source of information on daemons and services is the ``Linux Devices,

Daemons, Services'' chapter of the CTDP (2000a) document.



  • amd - runs the automount daemon for remote filesystem mounting such as

    nfs



  • anacron - checks delayed `cron' tasks (see below) at boot time and

    executes them. Useful if you have cron jobs scheduled but don't run your

    machine all the time.



  • apmd - Advanced Power Management BIOS daemon. For use on machines,

    especially laptops, that support apm. Monitors battery status and can shut

    down the system if power is too low.



  • arpwatch - keeps watch for ethernet IP address pairings that are

    resolved using the ARP protocol.



  • atd - runs jobs queued by `at'



  • autofs - control the operation of automount daemons, used to mount and

    unmount devices on demand



  • bootparamd - allows computers to boot from a Linux machine using the

    BOOTP network protocol. A server process that provides information to

    diskless clients necessary for booting



  • crond - automatic task scheduler. Manages the execution of tasks that

    are executed at regular but infrequent intervals, such as rotating log

    files, cleaning up /tmp directories, etc.



  • cups - daemon for print services under the Common Unix Printer System,

    a replacement for lpd



  • dhcpd - implements the Dynamic Host Configuration Protocol (DHCP) and

    the Internet Bootstrap Protocol (BOOTP). Used to lease out IP addresses to

    remote machines.



  • drakfont - font server in Mandrake



  • fetchmail - daemon to fetch mail at regular intervals from mail servers



  • ftpd - ftp server daemon



  • gated - routing daemon that handles multiple routing protocols and

    replaces routed and egpup



  • gpm - useful mouse server for applications running on the Linux

    console.



  • httpd - the Apache webserver hypertext transfer protocol daemon



  • identd - The identd server provides a means to determine the identity

    of a user of a particular TCP connection. Given a TCP port number pair, it

    returns a character string which identifies the owner of that connection on

    the server's system.



  • inetd - listens for service requests on network connections,

    particularly dial-in services. This daemon can automatically load and

    unload other daemons (ftpd, telnetd, etc.), thereby economizing on system

    resources. In the latest version of Red Hat (7.0 at the time of writing), it

    has been replaced by xinetd. A partial list of services controlled by inetd

    is listed below. Under many distributions, inetd will execute scripts in the

    file /etc/inetd.conf.



  • innd - Usenet news server daemon



  • ipchains - daemon for packet forwarding. Used for configuring a

    gateway/firewall.



  • isdn provides ISDN network interfacing services



  • isdn4linux - for users of ISDN cards



  • kerneld - automatically loads and unloads kernel modules



  • keytable - loads the appropriate keyboard map from /etc/sysconfig/

    keyboard



  • kheader -



  • kudzu - detects and configures new or changed hardware during boot



  • linuxconf - ``startup hook'' needed for the linuxconf system

    configuration tool



  • lpd - line printer and print spooler daemon



  • mcserv - server program for the Midnight Commander networking file

    system. It provides access to the host file system to clients running the

    Midnight file system (currently, only the Midnight Commander file manager).

    If the program is run as root the program will try to get a reserved port

    otherwise it will use 9876 as the port. If the system has a portmapper

    running, then the port will be registered with the portmapper and thus

    clients will automatically connect to the right port. If the system does not

    have a portmapper, then a port should be manually specified with the -p

    option (see below).



  • mysql - database server daemon



  • named - provides DNS services



  • netfs - network filesystem mounter. Used for mounting nfs, smb and ncp

    shares on boot.



  • network -activates all network interfaces at boot time by calling

    scripts in /etc/sysconfig/network-scripts



  • nfsd - used for exporting nfs shares when requested by remote systems



  • nfslock - starts and stops nfs file locking service



  • numlock - locks numlock key at init runlevel change



  • pcmcia - generic services for pcmcia cards in laptops



  • portmap - needed for Remote Procedure Calls



  • postfix - mail transport agent which is a replacement for sendmail.

    Now the default on desktop installations of Mandrake.



  • postgresql - database server daemon



  • random - random number generating daemon, related to security and

    encryption



  • routed - manages routing tables



  • rstatd - kernel statistics server. Allows users on a network to get

    performance statistics for any connected machine.



  • rusersd - provides services that allow users to find one another over

    the network



  • rwalld - allows users to use rwall to write messages on remote

    terminals



  • rwhod - server which maintains the database used by the rwho(1) and

    ruptime(1) programs. Its operation is predicated on the ability to broadcast

    messages on a network.



  • sendmail - mail transfer agent. This is the agent that comes with Red

    Hat. Others, such as smtpd, are not included.



  • smb - needed for running SAMBA



  • snmpd - provides Simple Network Management Protocol support



  • sound - daemon for managing sound



  • squid - web page proxy server daemon



  • syslogd - manages system log files



  • smtpd - Simple Mail Transfer Protocol, designed for the exchange of

    electronic mail messages. Several daemons that support SMTP are available,

    including sendmail, smtpd, rsmtpd, qmail, zmail, etc.



  • tcpd - from the tcp_wrappers package. Intercepts requests normally

    handled by inetd and filters them through the files hosts.allow and

    hosts.deny files, which can restrict access to services based on type of

    service, origin of request, destination, etc. Requests are intercepted

    because calls to particular services are replaced with calls to tcpd in

    /etc/inetd.conf.



  • telnetd - telnet server daemon



  • usb - daemon for devices on Universal Serial Bus



  • xfs - X font server



  • xinetd - more modern replacement for inetd. It apparently allows for

    similar kinds of access filters to the ones used by tcpd in conjunction with

    inetd. xinetd replaces inetd as the default network services daemon in Red

    Hat 7.0.



  • xntpd - Network Time Protocol daemon. Provides a means to syncronize

    time over the network.



  • webmin - daemon for webmin web-based system administration program



  • ypbind - NIS binder. Needed if computer is part of Network Information

    Service domain.


Most important linux networking commands


 Linux is most powerful operating system which often needs to use commands to explore it effectively.Some of the commands are restricted to normal user groups as they are powerful and has more functionality involved in it.Here we summarized most interesting and useful networking commands which every linux user are supposed to be familiar with it.


1.Arp  manipulates the kernel’s ARP cache in various ways.  The primary options are clearing an address mapping entry and manually setting up one.  For debugging purposes, the arp program also allows a complete dump of the ARP cache.ARP displays the IP address assigned to particular ETH card and mac address

[sufi@bistasolutions ]# arp
Address                  HWtype  HWaddress           Flags Mask            Iface
59.36.13.1              ether       C                        eth0

2.Ifconfig is used to configure the network interfaces.  Normally we use this command to check the IP address assigned to the system.It is used at boot time to set up interfaces as necessary.  After that, it is usually only needed when debugging or when system tuning is needed.

[sufi@bistasolutions ~]# /sbin/ifconfig
eth0     UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:126341 errors:0 dropped:0 overruns:0 frame:0
          TX packets:44441 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
         
3. Netstat  prints information about the networking subsystem.  The type of information which is usually printed  by netstat are Print  network connections, routing tables, interface statistics, masquerade connections, and multicast.

[sufi@bistasolutions ~]# netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0                       .230.87:https           ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags       Type       State         I-Node Path
unix  10     [ ]         DGRAM                    4970   /dev/log
unix  2      [ ]         DGRAM                    6625   @/var/run/hal/hotplug_socket
unix  2      [ ]         DGRAM                    2952   @udevd
unix  2      [ ]         DGRAM                    100564
unix  3      [ ]         STREAM     CONNECTED     62438  /tmp/.X11-unix/X0
unix  3      [ ]         STREAM     CONNECTED     62437
unix  3      [ ]         STREAM     CONNECTED     10271  @/tmp/fam-root-
unix  3      [ ]         STREAM     CONNECTED     10270
unix  3      [ ]         STREAM     CONNECTED     9276
unix  3      [ ]         STREAM     CONNECTED     9275

4.ping command is used to check the connectivity of a system to a network.Whenever there is problem in network connectivity we use ping to ensure the system is connected to network.

[root@smashtech ~]# ping google.com
PING google.com (74.125.45.100) 56(84) bytes of data.
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=0 ttl=241 time=295 ms
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=1 ttl=241 time=277 ms
64 bytes from yx-in-f100.google.com (74.125.45.100): icmp_seq=2 ttl=241 time=277 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 6332ms
rtt min/avg/max/mdev = 277.041/283.387/295.903/8.860 ms, pipe 2

5.Nslookup  is  a program to query Internet domain name servers. Nslookup has two modes: interactive and non-interactive. Interactive mode allows the user to query name servers for information about various hosts and domains or  to print  a  list  of hosts in a domain. Non-interactive mode is used to print just the name and requested information for a host or domain.

[sufi@bistasolutions ~]# nslookup google.com
Server:         server ip
Address:       gateway ip 3

Non-authoritative answer:
Name:   google.com
Address: 209.85.171.100
Name:   google.com
Address: 74.125.45.100
Name:   google.com
Address: 74.125.67.100

6. dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups  and  displays  the  answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarity of output. Other lookup tools tend to have less functionality than dig.

[sufi@bistasolutions ~]# dig google.com

; <<>> DiG 9.2.4 <<>> google.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4716
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 4, ADDITIONAL: 4

;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             122     IN      A       74.125.45.100
google.com.             122     IN      A       74.125.67.100
google.com.             122     IN      A       209.85.171.100

;; AUTHORITY SECTION:
google.com.             326567  IN      NS      ns3.google.com.
google.com.             326567  IN      NS      ns4.google.com.
google.com.             326567  IN      NS      ns1.google.com.
google.com.             326567  IN      NS      ns2.google.com.

;; ADDITIONAL SECTION:
ns1.google.com.         152216  IN      A       216.239.32.10
ns2.google.com.         152216  IN      A       216.239.34.10
ns3.google.com.         152216  IN      A       216.239.36.10
ns4.google.com.         152216  IN      A       216.239.38.10

;; Query time: 92 msec
;; SERVER: 172.29.36.1#53(172.29.36.1)
;; WHEN: Thu Mar  5 14:38:45 2009
;; MSG SIZE  rcvd: 212

7.Route manipulates the  IP routing tables.  Its primary use is to set up static routes to specific hosts  or  networks via an interface after it has been configured with the ifconfig program.When the add or del options are used, route modifies the routing tables.  Without these options, route displays the  current contents of the routing tables.

[sufi@bistasolutions ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
 54.192.56.321    *               255.255.255.0   U     0      0        0 eth0
     *               255.255.0.0     U     0      0        0 eth0
default            0.0.0.0         UG    0      0        0 eth0

8.Traceroute : Internet is a large and complex aggregation of network hardware, connected together by gateways.  Tracking the route one’s packets follow (or finding the miscreant gateway that’s discarding  your  packets)  can  be  difficult.

Traceroute utilizes the IP protocol ‘time to live’ field and attempts to elicit an ICMP TIME_EXCEEDED response from  each gateway along the path to some host. The only mandatory parameter is the destination host name or IP number.  The default probe datagram  length  is  40 bytes, but this may be increased by specifying a packet length (in bytes) after the destination host name.

[sufi@bistasolutions ~]# traceroute google.com
traceroute: Warning: google.com has multiple addresses; using 209.85.171.100
traceroute to google.com (209.85.171.100), 30 hops max, 38 byte packets
 1  * * *

9.W-displays  information  about the users currently on the machine, and their processes.  The header shows, in this order,  the current time, how long the system has been running, how many users are currently  logged on, and  the system load averages for the past 1, 5, and 15 minutes.

[sufi@bistasolutionsl ~]# w
 15:18:22 up  4:38,  3 users,  load average: 0.89, 0.34, 0.19
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     :0       -                10:41   ?xdm?  24:53   1.35s /usr/bin/gnome-session
root     pts/1    :0.0             10:58    1.00s  0.34s  0.00s w
root     pts/2    :0.0             12:10   23:32   0.03s  0.03s bash

10. Nmap  is  designed to allow system administrators and curious individuals to scan large networks to determine which hosts are up and what services they are offering.  nmap supports a large number of  scanning  techniques  such  as:UDP,  TCP  connect(), TCP SYN (half open), ftp proxy (bounce attack), ICMP (ping sweep), FIN, ACK sweep, Xmas Tree,SYN sweep, IP Protocol, and Null scan.  See the Scan Types section for more details.  nmap also offers a number of advanced  features  such  as  remote  OS  detection  via TCP/IP fingerprinting, stealth scanning, dynamic delay and retransmission calculations, parallel scanning, detection of down hosts via parallel pings,  decoy  scanning, port filtering  detection,  direct  (non-portmapper)  RPC scanning, fragmentation scanning, and flexible target and port specification.
       Significant effort has been put into decent nmap performance for non-root users.  Unfortunately, many critical kernel  interfaces  (such  as raw sockets) require root privileges.  nmap should be run as root whenever possible (not setuid root, of course).
       The result of running nmap is usually a list of interesting ports on the machine(s) being scanned (if  any).   Nmap always  gives  the  port’s  "well  known"  service name (if any), number, state, and protocol.  The state is either"open", "filtered", or "unfiltered".  Open means that the target machine will accept() connections  on  that  port.Filtered  means  that  a  firewall, filter, or other network obstacle is covering the port and preventing nmap from determining whether the port is open.  Unfiltered means that the port is known by nmap to be closed  and  no  fire-wall/filter  seems  to be interfering with nmap’s attempts to determine this.  Unfiltered ports are the common case and are only shown when most of the scanned ports are in the filtered state.
       Depending on options used, nmap may also report the following characteristics of the remote host: OS  in  use,  TCP sequentiality,  usernames  running  the programs which have bound to each port, the DNS name, whether the host is a smurf address, and a few other--Network exploration tool and security scanners.

[sufi@bistasolutions ~]# nmap 52.194.69.152

Linux Commands

General Commands

Q.How to write a boot image from your hard disk to a floppy
A.dd if=boot.img of=/dev/fd0

Q.How to copy the boot image from your hard disk to a floppy
A.dd if=/dev/fd0 of=floppy.img

Q.How to search for a file arul.jpg recursively in your Unix account
A.find ~/ -name "arul.jpg"

Q.How to display all the processes running on the host
A.ps -af

Q.How to check the current quota and tell how much you have used
A.quota

Q.How to check disk space in a directory (say /usr)
A.du -s -H /usr

Q.How to report size (in kBytes) of all enclosed directories (recursive)
A.du -k

Q.How to report size (in kBytes) of all enclosed directories (non-recursive)
A.du -ms *

Q.How to list login IDs of users currently logged in to the system
A.users

Q.How to change the permanent information kept by the system about your logon ID
A.chfn


Administrator commands lines:


Q.change user's shell to /usr/bin/bash (user arul):
A.usermod -s /usr/bin/bash arul

Q.access a windows (only FAT or FAT32) partition (say hda2) under linux
A.mount -t vfat /dev/hda2 /win

Q.allow root user and other users(where user id=500) to get rw permission for that windows partition
A.mount -t vfat -o uid=500 /dev/hda2 /win

Q.list all device files corresponding to hda
A.fdisk -l /dev/hda

Q.track down symbolic links, for example, to see where xterm points to
A.namei /usr/X11/bin/xterm

Q.print Linux version information
A.uname -r

Q.measure hard disk speed
A.hdparm -tT /dev/hda

Q.print hardware summary
A.more /proc/cpuinfo

Q.check inode usage of all mounted partitions
A.df -i

Q.monitoring the system for the growth of a file
A.tail -f /var/log/messages



Openerp Instillation on Linux




OpenERP Installation Guide

Requisites for Python:


Install following modules:
  1. readline-devel
  2. libxml2
  3. libxml2-devel
  4. libxslt
  5. libxslt-devel
  6. zlib
  7. zlib-devel

Note: Above requisites were identified while installing python modules on a centos 64 bit server, these might change server to server.

  1. Postgresql Installation from Source
  1. Download source (tar.gz) of postgresql 8.4.6 from http://postgresql.org
  2. Extract using #tar –xvzf postgresql_file_name
  3. cd to postgresql folder and run following commands:
      1. #./configure
      2. #make
      3. #make install
  4. After successful installation create a user postgres and data directory:
      1. #adduser postgres
      2. #mkdir /usr/local/pgsql/data
      3. #chown postgres /usr/local/pgsql/data
  5. Now , initialize the cluster: #/usr/local/pgsql/bin/initd/ -D /usr/local/pgsql/data
  6. Run postgresql: #su postgres -c ‘/usr/local/pgsql/bin/postgres –D /usr/local/pgsql/data’  >/home/postgres/postgres_logfile 2>&1 &
  7. Create symbolic links :
      1. #ln /usr/local/pgsql/bin/psql /usr/bin/psql –s
      2. # ln /usr/local/pgsql/bin/pg_dump /usr/bin/ pg_dump –s
      3. # ln /usr/local/pgsql/bin/pg_dumpall /usr/bin/ pg_dumpall –s
      4. # ln /usr/local/pgsql/pg_restore /usr/bin/ pg_restore –s
  8. Create a user in postgresql with which openerp can communicate:
      1. #psql –d template1 –U postgres
      2. #create user openerp with password ‘solutions’ createdb;
      3. Above user and password will be used in config file of OpenERP server, so please make a note of it.



  1. Python Installation from Source:
  1. Download Python2.6.7 from http://python.org
  2. Extract using #tar –xvzf python_file_name
  3. cd to python folder and run following commands:
      1. #./configure
      2. #make
      3. #make install
  4. Check installed python details: #python2.6 -V
  5. After successful installation of python, go to http://python.org/pypi and download setuptools module(Copy link address of source and download using wget command)

Note: All python modules are available on ftp://ftp.bistasolutions.com/OpenERP_python_mods
  1. Extract using #tar –xvzf setuptools_file.tar.gz
  2. Cd to setuptools folder and run #python2.6 setup.py install
  3. Once installed, easy_install-2.6 command will be available.
  4. Following are the python modules required by OpenERP:
    1. lxml - #easy_install-2.6 lxml

Requisites for this are: libxml2, libxml-devel2, libxslt and libxslt-devel
    1. mako - #easy_install-2.6 mako
    2. pydot - #easy_install-2.6 pydot
    3. pytz - #easy_install-2.6 pytz
    4. reportlab - #easy_install-2.6 reportlab
    5. caldav - #easy_install-2.6 caldav
    6. python-dateutil - #easy_install-2.6 python-dateutil
    7. psycopg2 -
      1. Give LD_LIBRARY_PATH in /etc/profile as
        1. #nano /etc/profile
        2. At the end of file put : export LD_LIBRARY_PATH=/usr/local/pgsql/lib
        3. CTRL+O and CTRL+X
        4. #source /etc/profile
      2. #easy_install-2.6 psycopg2
      3. Run #python2.6
      4. #import psycopg2
      5. If no errors than psycopg2 installation successful, otherwise download psycopg2 as per point no. 5,6 7
    8. Yaml - #easy_install-2.6 PyYAML
    9. Cherrypy - #easy_install-2.6 cherrypy==3.1.2
    10. Babel - #easy_install-2.6 babel
    11. FormEncode - #easy_install-2.6 formencode==1.2.2
    12. Omelette- #easy_install-2.6 omelette
    13. Python Imaging Library -#easy_install-2.6 pil



  1. OpenERP Server and Web installation:


  1. Download Source files of OpenERP Server from http://openerp.com
  2. Extract using #tar –xvzf openerp-server.tar.gz
  3. Cd to openerp-server folder and run:#python2.6 setup.py install
  4. Create system user for :
    1. #adduser openerp
  5. Change db_user,db_password,admin_passwd in /usr/local/lib/python2.6/site-packages/openerp-server/tools/config.py
  6. Run #su openerp –c ‘openerp-server start’. If this runs successfully then to keep it running first do CTRL+C then execute: # su openerp –c ‘openerp-server start’ >/home/openerp/oerp_serv_logfile 2>&1 &
  7. Download Source files of OpenERP Web from http://openerp.com
  8. Extract using #tar –xvzf openerp-web.tar.gz
  9. Cd to openerp-web folder and run:#python2.6 setup.py install
  10. Run #su openerp –c ‘openerp-web start’. If this runs successfully then to keep it running first do CTRL+C then execute: # su openerp –c ‘openerp-web start’ > /home/openerp/oerp_web_logfile 2>&1 &
  11. To open port on linux use command: #iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
  12. Put the following three lines in /etc/rc.local so that OpenERP starts on Server Startup:
    1. #nano /etc/rc.local
    2. Put the following three line(obviously without #) at the last:
      1. #su postgres -c ‘/usr/local/pgsql/postgres –D /usr/local/pgsql/data’  >/home/postgres/postgres_logfile 2>&1 &
      2. #su openerp –c ‘openerp-server start’ >/home/openerp/oerp_serv_logfile 2>&1 &
      3. # su openerp –c ‘openerp-web start’ > /home/openerp/oerp_web_logfile 2>&1 &
  13. Redirection from 80 port (proxy setup):
    1. Add Virtual Host entry in apache configuration::

#<VirtualHost 173.192.201.242:80>
   ServerName erp.myibsource.com
   ServerAdmin ashaynimkar@gmail.com
   <Proxy *>
      Order deny,allow
      Allow from all
   </Proxy>
   ProxyRequests Off
   RewriteEngine on
       RewriteRule ^/(.*) http://127.0.0.1:8080/$1 [P]
       ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>



    1. Uncomment #tools.proxy.on = TRUE from openerp-web.cfg


  1. Error messages and their solutions
  1. ImportError: No module named _thread
    1. Formencode python module issue
    2. Remove Formencode #easy_install-2.6 –m formencode
    3. Install #easy_install-2.6 formencode==1.2.2
  2. ImportError: No module named bz2
    1. Install readline-devel #yum install readline-devel
    2. Recompile python:
      1. Cd to Python source folder and run #./configure
      2. #make
      3. #make install


Basic Linux Commands


Basic Linux Commands


This section gives insight into the most important commands of your SuSE Linux system. Along with the individual commands, parameters are listed and, where appropriate, a typical sample application is introduced. To learn more about the various commands, it is usually possible to get additional information with the man program followed by the name of the command, for example, man ls.
In these manual pages, move up and down with PgUp and PgDn and move between the beginning and the end of a document with Home and End. End this viewing mode by pressing Q. Learn more about the mancommand itself with man.
There are many more commands than listed in this chapter. For information about other commands or more detailed information, we recommend the O'Reilly publication Linux in a Nutshell. In the following overview, the individual command elements are written in different typefaces.
  • The actual command is always printed as command. Without this, nothing can function.
  • Options without which the respective program cannot function are printed in italics.
  • Further details, like file names, which must be passed to a command for correct functioning, are written in the Courier font.
  • Specifications or parameters that are not required are placed in [brackets].
Adjust possible specifications to your needs. It makes no sense to write ls file(s), if no file named file(s) actually exists. You can usually combine several parameters, for example, by writing ls -la instead of ls -l -a.

File Administration


ls [option(s)] [file(s)]
If you run ls without any additional parameters, the program will list the contents of the current directory in short form.
-l
detailed list
-a
displays hidden files

cp [option(s)] sourcefile targetfile





Copies sourcefile to targetfile.

-i
Waits for confirmation, if necessary, before an existing targetfile is overwritten
-r
Copies recursively (includes subdirectories)

mv [option(s)] sourcefile targetfile





Copies sourcefile to targetfile then deletes the original sourcefile.

-b
Creates a backup copy of the sourcefile before moving
-i
Waits for confirmation, if necessary, before an existing targetfile is overwritten

rm [option(s)] file(s)





Removes the specified files from the file system. Directories are not removed by rm unless the option -r is used.

-r
Deletes any existing subdirectories
-i
Waits for confirmation before deleting each file.

ln [option(s)] sourcefile targetfile





Creates an internal link from the sourcefile to the targetfile, under a different name. Normally, such a link points directly to the sourcefile on one and the same file system. However, if ln is executed with the -s option, it creates a symbolic link that only points to the directory where the sourcefile is located, thus enabling linking across file systems.

-s
Creates a symbolic link

cd [options(s)] [directory]





Changes the current directory. cd without any parameters changes to the user's home directory.

mkdir [option(s)] directoryname





Creates a new directory.

rmdir [option(s)] directoryname





Deletes the specified directory, provided it is already empty.

chown [option(s)] username.group file(s)





Transfers the ownership of a file to the user with the specified user name.

-R
Changes files and directories in all subdirectories.

chgrp [option(s)] groupname file(s)





Transfers the group ownership of a given file to the group with the specified group name. The file owner can only change group ownership if a member of both the existing and the new group.

chmod [options] mode file(s)





Changes the access permissions.
The mode parameter has three parts: groupaccess, and access typegroup accepts the following characters:

u
user
g
group
o
others
For access, access is granted by the + symbol and denied by the - symbol.
The access type is controlled by the following options:

r
read
w
write
x
eXecute — executing files or changing to the directory.
s
Set uid bit — the application or program is started as if it were started by the owner of the file.

gzip [parameters] file(s)





This program compresses the contents of files, using complex mathematical algorithms. Files compressed in this way are given the extension .gz and need to be uncompressed before they can be used. To compress several files or even entire directories, use the tar command.

-d
decompresses the packed gzip files so they return to their original size and can be processed normally (like the command gunzip).

tar options archive file(s)





The tar puts one file or (usually) several files into an archive. Compression is optional.
tar is a quite complex command with a number of options available. The most frequently used options are:

-f
Writes the output to a file and not to the screen as is usually the case
-c
Creates a new tar archive
-r
Adds files to an existing archive
-t
Outputs the contents of an archive
-u
Adds files, but only if they are newer than the files already contained in the archive
-x
Unpacks files from an archive (extraction)
-z
Packs the resulting archive with gzip
-j
Compresses the resulting archive with bzip2
-v
Lists files processed
The archive files created by tar end with .tar. If the tar archive was also compressed using gzip, the ending is .tgz or .tar.gz. If it was compressed using bzip2.tar.bz2.
Application examples can be found in Section “Archives and Data Compression”.

locate pattern(s)





The locate command can find in which directory a specified file is located. If desired, use wild cards to specify file names. The program is very speedy, as it uses a database specifically created for the purpose (rather than searching through the entire file system). This very fact, however, also results in a major drawback: locate is unable to find any files created after the latest update of its database.
The database can be generated by root with updatedb.

updatedb [options(s)]





This command performs an update of the database used by locate. To include files in all existing directories, run the program as root. It also makes sense to place it in the background by appending an ampersand (&), so you can immediately continue working on the same command line (updatedb &).

find [option(s)]





The find command allows you to search for a file in a given directory. The first argument specifies the directory in which to start the search. The option -name must be followed by a search string, which may also include wild cards. Unlike locate, which uses a database, find scans the actual directory.

Commands to Access File Contents



cat [option(s)] file(s)
The cat command displays the contents of a file, printing the entire contents to the screen without interruption.
-n
Numbers the output on the left margin

less [option(s)] file(s)





This command can be used to browse the contents of the specified file. Scroll half a screen page up or down with PgUp and PgDn or a full screen page down with Space. Jump to the beginning or end of a file usingHome and End. Press Q to exit the program.

grep [option(s)] searchstring filenames





The grep command finds a specific searchstring in the specified file(s). If the search string is found, the command displays the line in which the searchstring was found along with the file name.

-i
Ignores case
-l
Only displays the names of the respective files, but not the text lines
-n
Additionally displays the numbers of the lines in which it found a hit
-l
Only lists the files in which searchstring does not occur

diff [option(s)] file1 file2





The diff command compares the contents of any two files. The output produced by the program lists all lines that do not match.
This is frequently used by programmers who need only send their program alterations and not the entire source code.

-q
Only reports whether the two given files differ

File Systems


mount [option(s)] [<device>] mountpoint
This command can be used to mount any data media, such as hard disks, CD-ROM drives, and other drives, to a directory of the Linux file system.
-r
mount read-only
-t filesystem
Specifies the file system. The most common are ext2 for Linux hard disks, msdos for MS-DOS media, vfat for the Windows file system, and iso9660 for CDs.

For hard disks not defined in the file /etc/fstab, the device type must also be specified. In this case, only root can mount. If the file system should also be mounted by other users, enter the option user in the appropriate line in the /etc/fstab file (separated by commas) and save this change. Further information is available in mount.

umount [option(s)] mountpoint





This command unmounts a mounted drive from the file system. To prevent data loss, run this command before taking a removable data medium from its drive. Normally, only root is allowed to run the commandsmount and umount. To enable other users to run these commands, edit the /etc/fstab file to specify the option user for the respective drive.

System Commands


df [option(s)] [directory]
The df (disk free) command, when used without any options, displays information about the total disk space, the disk space currently in use, and the free space on all the mounted drives. If a directory is specified, the information is limited to the drive on which that directory is located.
-H
shows the number of occupied blocks in gigabytes, megabytes, or kilobytes — in human-readable format
-t
Type of file system (ext2, nfs, etc.)

du [option(s)] [path]





This command, when executed without any parameters, shows the total disk space occupied by files and subdirectories in the current directory.

-a
Displays the size of each individual file
-h
Output in human-readable form
-s
Displays only the calculated total size

free [option(s)]





The command free displays information about RAM and swap space usage, showing the total and the used amount in both categories.

-b
Output in bytes
-k
Output in kilobytes
-m
Output in megabytes

date [option(s)]





This simple program displays the current system time. If run as root, it can also be used to change the system time. Details about the program are available in date.

Processes



top [options(s)]
top provides a quick overview of the currently running processes. Press H to access a page that briefly explains the main options to customize the program.
ps [option(s)] [process ID]
If run without any options, this command displays a table of all your own programs or processes — those you started. The options for this command are not preceded by hyphen.
aux
Displays a detailed list of all processes, independent of the owner.

kill [option(s)] process ID





Unfortunately, sometimes a program cannot be terminated in the normal way. However, in most cases, you should still be able to stop such a runaway program by executing the kill command, specifying the respective process ID (see top and ps).
kill sends a TERM signal that instructs the program to shut itself down. If this does not help, the following parameter can be used:

-9
Sends a KILL signal instead of a TERM signal, with which the process really is annihilated by the operating system. This brings the specific processes to an end in almost all cases.

killall [option(s)] processname





This command is similar to kill, but uses the process name (instead of the process ID) as an argument, causing all processes with that name to be killed.

Networking


ping [option(s)] host name|IP address
The ping command is the standard tool for testing the basic functionality of TCP/IP networks. It sends a small data packet to the destination host, requesting an immediate reply. If this works, ping displays a message to that effect, which indicates that the network link is basically functioning.
-c
number Determines the total number of packages to send and ends after they have been dispatched. By default, there is no limitation set.
-f
flood ping: sends as many data packages as possible. A popular means, reserved to root, to test networks.
-i
value Specifies the interval between two data packages in seconds. Default: one second

nslookup



The Domain Name System resolves domain names to IP addresses. With this tool, send queries to information servers (DNS servers).

telnet [option(s)] host name or IP address


Open Port 25 on Linux machine for SMTP send-email feature

 

man ufw for policies

                 OR

sudo ufw allow 25