Wednesday, July 30, 2014

About Linux and some useful commands

The most popular Linux distribution (and very good for newbies) is Mint, followed by Ubuntu. Both are based on the Debian packaging system (Ubuntu is based on Debain and Mint is based on Ubuntu). On the other side of the divide, you have the RPM systems, the most popular one for end users are Fedora and openSuSe.
Then you have the various source based ones like Arch and Gentoo.
As a new user, I would recommend you try one of Mint, Ubuntu or openSuSe or perhaps Manjaro.
there is a Mint Debian Edition you could try.

Debian is not user friendly. It is not very scary either but Mint actually actively tries to be user friendly while Debian does not.
Well, Debian is a distribution. RPM is a package format. The two main package formats in the Linux world are .deb (used by Debian and its derivatives) and RPM (used by RedHat/Fedora and their derivatives).
That is true for all Debian based distributions. Kind of true for RPM-based ones too but they often have fewer choices immediately available from their repositories.
Well, Linux is just a kernel. Think of that as the core of the operating system. A distribution is a collection of software (kernel+tools) that all together make a working operating system. Different distributions have set up a different ecosystem around the core Linux kernel.
 from the perspective of a new user, the most important differences are 1) the package management system (which defines how you can install/manage your software) and 2) the default graphical environment (the Desktop Environment, or DE).
 While any DE can be installed on any distribution, different distros have chosen different DEs as default and that can affect your choice if you don't feel comfortable installing one yourself.

1. Start, stop, restart  a service:
sudo service service_name start
For example, if want to start mysql service, execute command like: sudo service mysql start
sudo service service_name stop
sudo service service_name restart

2. Find a file or directory:
locate xyz
find directory_path -name "file_name / directory_name"
you can also use wildcard characters. For example sudo find /bin -name "mysql*"
If you want to search a file in all the sub-directories, run below command:
find . -name "filename" - you can also use wildcard characters.
For example: find . -name 'abhishek_xyz*.csv'

3. To collect memory / CPU information of Linux server
 cat /proc/meminfo
cat /proc/cpuinfo

4. display the contents of the fstab configuration file, which contains all partitions and storage devices connected to the computer, both internal and external:
sudo cat /etc/fstab

5. Describe Filesystem,Size,Used,Avail,Use%, Mounted on
df -h

6. Describe Filesystem,Size,Used,Avail,Use%, Mounted on
df -h

7. find the filesystem of below directory:
df /home

8. List all the installed applications:
rpm -qa | less or
yum list installed

9. Know all the processor running status
mpstat -P ALL

10. Know CPU running history:
sar

11. Find out running Linux kernel version:
uname -mrs  or
uname -a  or
cat /proc/version

12. Display list of all open ports
netstat -tulpn

13. List PID of all the HTTP applications running on Port 80
 fuser 80/tcp

14. Display list of all running tasks likewise task manager of windows server
top

15. Unzip a tar  and zip file
tar -zxvf data.tar.gz
unzip sourcefilename destinationfilename

15. List directories under a file system
tree -LP levelnumber partitionNumber
The -P command stands for pattern and L is level Max display depth of the directory tree.
Make sure your in the / directory when running this command
For example:
If you have 4 partitions of your hard disk likewise sda1,sda2,sda3,sda4 and you want to list all the files and directories till 2 levels only under partition sda2: run the below command:
tree -LP 2 /dev/sda2

16. Copy a directory from source to destination
cp -avr sourceDIR destinationDir
For example:
cp -avr /var/lib/mysql/proddb /var/lib/mysql
-a : Preserve the specified attributes such as directory an file mode, ownership, timestamps, if possible additional attributes: context, links, xattr, all.
-v : Explain what is being done.
-r : Copy directories recursively.

No comments:

Post a Comment

Thanks for your valuable comments.

Important queries based formulas to watch performance of a MySQL based application

(1) Session Vs global status variables value select G.variable_name,G.variable_value GlobalValue,S.variable_value SessionValue from (selec...