Linux Commands

Basic Linux Operations

 

Showing the kernel version and hostname

uname -a

 

Verify the kernel module list

lsmod

 

 

Showing the list of packets installed

rpm -qa|more

 

 

Information about the mounted file systems

mount

 

 

Disk Usage

fdisk -l /dev/sda

 

 

Showing the status of the Volume Group

vgdisplay

 

 

Showing the disks and partitions included in the Volume Group

pvscan

 

 

Showing the logical volumes

lvdisplay

 

 

Showing the Default Gateway

netstat -rn (look for the IP that has FLAG UG)

 

 

Showing the NIC status

ethtool eth0

 

 

Changing NIC configuration

ethtool -s eth0 speed 1000 duplex full autoneg off

 

 

Showing the Iptables rules

iptables -L -n

iptables -t nat -vnL

 

 

Verify the processes that are listening in a specific port

lsof –iTCP –n –P

 

 

Verify the IP tunnel configuration

iptunnel

 

 

Showing the MACs associated to a bridge

brctl showmacs br0

 

 

Showing the routing table

route

 

 

Showing CPU configuration

more /proc/cpuinfo

 

 

Showing Memory information

more /proc/meminfo

 

 

Verify and change of the IP address

To verify what is the actual IP, first execute “ifconfig –a”, if the output is too long use this command instead “ifconfig –a|more” and look for the “eth0” interface.

To change your Linux IP temporarily: Use the following command, the IP will be changed until next reboot.

ifconfig eth0 [New IP] NETMASK 255.255.255.0

where eth0 is the interface whose IP you want to change.

 

Permanently changing your Linux IP: For this change, you have to edit /etc/sysconfig/network-scripts/ifcfg-eth0 (if you want to change the IP of a different interface then look for the proper file, for example ifcfg-eth1 for eth1 and so on). Change the following parameters:

DEVICE=eth0 -> Indicates the interface you are changing

BOOTPROTO=none -> Shows if the IP is dynamic (via DHCP) or static

ONBOOT=yes -> Shows if the interface is active after the system starts

HWADDR=00:0c:29:4f:3a:c7 -> Shows the NIC MAC address

IPADDR=192.168.65.129 -> Shows the actual IP used by this interface

NETMASK=255.255.255.0 -> Shows the network mask

 

 

Creating a new file

Go to the path where you want to create your new file or write the complete path as shown below:

vi new.txt

vi /etc/new.txt

 

An empty file will be opened, you can start adding lines to your new file or you just can close it by typing:

:wq!

 

The file will be created in the path indicated when you executed the “vi” command.

 

 

Rename a file

Go to the path of the file or specify it as shown below:

mv oldfile.txt newfile.txt

mv /etc/oldfile.txt /etc/newfile.txt

 

Be carefull to change the appropiate extension or the file may end up without extension.

 

 

Deleting a file

Go to the path or specify it as shown below:

rm file.txt

rm /etc/file.txt

 

If you get a confirmation prompt just type “y”. If you want to force the operation just add “-f”.

rm -f file.txt

 

If you want to delete a folder with all its contents type:

rm -rf folder

rmdir –ignore-fail-on-non-empty folder

 

 

Creating a folder

mkdir folder

 

 

 

Showing the CPU and Memory Use

top

This will give you a list ordered by the highes CPU usage, to change it to memory usage type “m” and then “q” to return to CPU.

 

 

Finding a process

ps -fea|grep process

 

 

Showing network connections

netstat

To show the port number instead of the port name (show 25 instead of smtp) use:

[root@tmcent01 ~]# netstat -n

 

 

Showing files and folders

ls          Shows the names of files and folders

ls -lha   Shows all files and folders in a detailed list with sizes of  KB,MB,GB,etc…

ls -lct     Shows and sorts the list by modification time

 

 

 

 

LDAP Commands

 

Search for all objects of Active Directory

ldapsearch -h <ldap_server_IP> -b ′dc=example,dc=com′ -x -D “administrator@example.com” -W ′(objectClass=*)′

 

 

Search for all objects of OpenLDAP

ldapsearch -h <ldap_server_IP> -b ′dc=example,dc=com′ -x -D “cn=Manger,dc=example,dc=com” -W ′(objectClass=*)′

 

Remember to send us your questions and comments to our Twitter account:@redinskala where you can find more information and security tips.

Thanks for your visit!