Linux Basic
Commands (Part-2)
Process Management
Due to multitasking
behavior of Linux operating system there are running many processes at the same
time. Every process has its id. Along with OS own processes running there are
user’s processes are also running on the machine. If Administrator would like
to get a snapshot of what is currently happening on the machine may use top
command. But top shows only real time view which fits on the screen. Here is
another command i.e ps stand for processes. It will shows you the processes running
on current terminal but it takes aux argument will show complete
system view which may be more helpful. System Admins use grep with ps
usually pipe the output. Any process can be killed by kill command. Examples
are mentioned below for more detail;
1. top
(shows what is currently happening with system)
2. ps
aux | less (shows the all running processes with process ids even by other
users)
3. ps
aux | grep ‘firefox’ (output of ps will be piped through grep to search for
specific process i.e firefox.)
4. pstree
(displays the process in tree format)
5. kill
1234 (kills the process having id 1234)
6. kill
-9 1234 (forefully kills the process having id 1234)
Package Management
Package
Management System is collection of software tools that automates the process of
installing, upgrading, configuring and removing programs of OS in a consistent
manner. Following are the commands to handle the various packages in linux;
1. rpm
–qa sendmail (checks currently installed package of sendmail)
2. rpm
–qi sendmail (list all the information about sendmail package)
3. rpm
–qd sendmail (lists the documentation files and their location of particular
installed package)
4. rpm
–ivh /mnt/cdrom/mail/sendmail.rpm (check the particular package if not then
install it from mounted cd rom)
5. rpm
–Uvh /mnt/cdrom/mail/sendmail.rpm (check the particular package installed then upgrade
it to newer version.)
6. rpm
–e sendmail (To remove/uninstall the particular package)
System Services Configuration
Running
linux systems have a number of background processes executing at any time.
These processes are also known as services or daemon run as part of an
application. OS services are like sshd and application daemons are httpd. These
services are supposed to continuously to make sure that our websites, mail,
databases and other applications are always running and up. Furthermore System
Admins needs to continuously run these services without failing and start
automatically after when system crash or reboots. A reboot can be planned
restart, due to patch update or unexpected system behavior. Crash may stop the process unexpectedly and application
may be unresponsive.
These
Linux services can be made largely self-healing by changing the way they are
handled by service management daemons, also known as init systems.
After crash or unexpected reboot services need to start automatically via
following commands;
1. netstat –at (To check the
status of the daemons listing on different ports)
2. Chkconfig --level 3 bind on
(bind service will be automatically start on run level 3 when system reboots)
Device Configuration
For hardware
configuration you can use following commands;
1. Sysreport
(will generate a hardware list of your computer and save it in tar file)
2. Kbconfig
(for keyboard layout)
3. Mouseconfig
(for mouse)
4. Printconfig
(for printer configuration)
5. Timeconfig
(for time zone configuration)
Hardware information
1. Like
everything, there are commands to check hardware information of linux system;
2. lscpu
(displays cpu information)
3. lshw
(displays detailed and brief information about different hardware units.)
4. lspci
(displays details about all pci busses)
5. lsscsi
(lists the scsci/sata drives and optical devices.)
6. lsusb
(lists usb devices and details about devices connected)
7. free
–m (check the amount of ram used, free and total)
User Management and File Permissions/Ownerships
The control of users and groups is a core
element of Linux System Administration. A user may be a human being or account
used by specific applications identified by a unique numerical number called
user ID (UID). Users within a group can have read, write and execute
permissions or any combination of read/write/execute permissions of files owned
by group.
A group is an organization unit tying users
together for a common purpose, which can be reading, writing, or executing
permissions for files owned by that group. Similar to UID, each group is
associated with a group ID (GID). Each file and directory on your system is
assigned access rights for the owner of the file, the members of a group of
related users, and everybody else. Rights can be assigned to read a file, to
write a file, and to execute a file (i.e., run the file as a program). A user who
creates a file is also the owner and primary group owner of that file.
Following are the commands for creating users and groups;
1. Groupadd
mailusers (create new group named mailusers)
2. useradd
–a /bin/false –g mailusers imran (create
new user named imran and make him member of group mailusers)
3. passwd
imran (to change the password of new created user imran)
4. passwd
–l imran (to lock the password of the user imran)
5. passwd
–u imran (to unlock the password of the user imran)
6. userdel
–r imran (to delete the user named imran with his home directory)
7. chmod
770 myfile.txt (change the permissions of the file myfile.txt to read, write,
and execute for owner and group)
8. chown
–R /imran:mailusers /project (change the ownernship of the directory /project
to user imran and set the group permissions to group mailusers)
Note: I will cover Permissions topic in
detail in my next blog separately.
Modules Management
The Linux kernel allows drivers and features
to be compiled as modules rather than as part of the kernel itself. This means
that users can often change features in the kernel or add drivers without
recompiling, and that the Linux kernel doesn't have
to carry a lot of unnecessary baggage. Here are few commands for listing,
inserting and removing modules;
1. lsmod
(list the current modules loaded)
2. modprobe
modulename (add/insert a module)
3. rmmod
(remove a module)
Routing table and naming
Routing table guides incoming and outgoing
traffic to and from your system towards network. Linux kernel supports multiple
routing tables. Following are the commands to handle with routing tables.
1. route
–n (to check the routing table)
2. route
add default gw 192.168.1.1 (add default gateway to your system)
3. route
del default (to delete default gateway)
4. route
add –net 192.168.1.0 netmask 255.255.255.0 dev eth0 (add route to specific
network)
5. route
del –net 192.168.1.0 netmask 255.255.255.0 dev eth0 (add route to specific
network)
6. traceroute
192.168.1.1 (to trace number or hops to particular host)
7. mtr
192.168.1.1 (to trace and ping at the same time to particular host)
8. host
imran.mydomain.com (to find host and its ip address on the network)
9. nslookup
imran.mydomain.com (to find host and its ip address on the network)
10.
dig imran.mydomain.com (to find host
and its ip address on the network)
11.
hostname (to find FQDN of your
system)
Miscellaneous
Here are
some miscellaneous commands below;
1. Man
snmp (to find help on some topic i.e snmp)
2. Info
snmp (another command to find help on some topic i.e snmp)
3. find
/usr –name “*.doc” (to find a *.doc file in /usr directory)
4. find
/usr –group mailusers (to find files and directories owned by group mailusers
in /usr directory)
5. find
/ -user imran –exec rm ‘{}’ ‘; (to find and delete files owning by user imran
who left organization for security reasons)
6. uptime
(check the system how long it is up)
7. who
–b (to find out when system last time booted)
8. service
sendmail status (to check the status of the service)
No comments:
Post a Comment