Showing posts with label Commands. Show all posts
Showing posts with label Commands. Show all posts

Commands of the day

0 comments

To shutdown the system at a particular time


# shutdown -h hours:minutes &


To find the files with an extension .html,


# locate \*.html


To list the files having SUID configured in the system, use the command:


#  find / -perm -u+s

Commands of the day

0 comments

To shutdown the system at a particular time


# shutdown -h hours:minutes &


To find the files with an extension .html,


# locate \*.html


To list the files having SUID configured in the system, use the command:


#  find / -perm -u+s

rpm command cheat sheet for Linux

6 comments
rpm is a powerful Package Manager for Red Hat, Suse and Fedora Linux. It can be used to build, install, query, verify, update, and remove/erase individual software packages. A Package consists of an archive of files, and package information, including name, version, and description:






























































SyntaxDescriptionExample(s)
rpm -ivh {rpm-file}Install the packagerpm -ivh mozilla-mail-1.7.5-17.i586.rpm
rpm -ivh --test mozilla-mail-1.7.5-17.i586.rpm
rpm -Uvh {rpm-file}Upgrade packagerpm -Uvh mozilla-mail-1.7.6-12.i586.rpm
rpm -Uvh --test mozilla-mail-1.7.6-12.i586.rpm
rpm -ev {package}Erase/remove/ an installed packagerpm -ev mozilla-mail
rpm -ev --nodeps {package}Erase/remove/ an installed package without checking for dependenciesrpm -ev --nodeps mozilla-mail
rpm -qaDisplay list all installed packagesrpm -qa
rpm -qa | less
rpm -qi {package}Display installed information along with package version and short descriptionrpm -qi mozilla-mail
rpm -qf {/path/to/file}Find out what package a file belongs to i.e. find what package owns the filerpm -qf /etc/passwd
rpm -qf /bin/bash
rpm -qc {pacakge-name}Display list of configuration file(s) for a packagerpm -qc httpd
rpm -qcf {/path/to/file}Display list of configuration files for a commandrpm -qcf /usr/X11R6/bin/xeyes
rpm -qa --lastDisplay list of all recently installed RPMsrpm -qa --last
rpm -qa --last | less
rpm -qpR {.rpm-file}
rpm -qR {package}
Find out what dependencies a rpm file hasrpm -qpR mediawiki-1.4rc1-4.i586.rpm
rpm -qR bash

{package} - Replace with actual package name

rpm command cheat sheet for Linux

6 comments
rpm is a powerful Package Manager for Red Hat, Suse and Fedora Linux. It can be used to build, install, query, verify, update, and remove/erase individual software packages. A Package consists of an archive of files, and package information, including name, version, and description:






























































SyntaxDescriptionExample(s)
rpm -ivh {rpm-file}Install the packagerpm -ivh mozilla-mail-1.7.5-17.i586.rpm
rpm -ivh --test mozilla-mail-1.7.5-17.i586.rpm
rpm -Uvh {rpm-file}Upgrade packagerpm -Uvh mozilla-mail-1.7.6-12.i586.rpm
rpm -Uvh --test mozilla-mail-1.7.6-12.i586.rpm
rpm -ev {package}Erase/remove/ an installed packagerpm -ev mozilla-mail
rpm -ev --nodeps {package}Erase/remove/ an installed package without checking for dependenciesrpm -ev --nodeps mozilla-mail
rpm -qaDisplay list all installed packagesrpm -qa
rpm -qa | less
rpm -qi {package}Display installed information along with package version and short descriptionrpm -qi mozilla-mail
rpm -qf {/path/to/file}Find out what package a file belongs to i.e. find what package owns the filerpm -qf /etc/passwd
rpm -qf /bin/bash
rpm -qc {pacakge-name}Display list of configuration file(s) for a packagerpm -qc httpd
rpm -qcf {/path/to/file}Display list of configuration files for a commandrpm -qcf /usr/X11R6/bin/xeyes
rpm -qa --lastDisplay list of all recently installed RPMsrpm -qa --last
rpm -qa --last | less
rpm -qpR {.rpm-file}
rpm -qR {package}
Find out what dependencies a rpm file hasrpm -qpR mediawiki-1.4rc1-4.i586.rpm
rpm -qR bash

{package} - Replace with actual package name

SSH server to server

0 comments
ssh -l root 12.123.123.12

SSH server to server

0 comments
ssh -l root 12.123.123.12

Shorthand at the Linux Command Prompt

0 comments
Some of these are specific to the bash shell. I have not experimented enough with other shells to know which are common to all shells. See also the ``Bash Reference Card'', SSC (2000), available online.

* / - root directory

* ./ - current directory

* ./command_name - run a command in the current directory when the current directory is not on the path

* ../ - parent directory

* ~ - home directory

* $ - typical prompt when logged in as ordinary user

* # - typical prompt when logged in as root or superuser

* ! - repeat specified command

* !! - repeat previous command

* ^^ - repeat previous command with substitution

* & - run a program in background mode

* [Tab][Tab] - prints a list of all available commands. This is just an example of autocomplete with no restriction on the first letter.

* x[Tab][Tab] - prints a list of all available completions for a command, where the beginning is ``x''

* [Alt][Ctrl][F1] - switch to the first virtual text console

* [Alt][Ctrl][Fn] - switch to the nth virtual text console. Typically, there are six on a Linux PC system.

* [Alt][Ctrl][F7] - switch to the first GUI console, if there is one running. If the graphical console freezes, one can switch to a nongraphical console, kill the process that is giving problems, and switch back to the graphical console using this shortcut.

* [ArrowUp] - scroll through the command history (in bash)

* [Shift][PageUp] - scroll terminal output up. This also works at the login prompt, so you can scroll through your boot messages.

* [Shift][PageDown] - scroll terminal output down

* [Ctrl][Alt][+] - switch to next X server resolution (if the server is set up for more than one resolution)

* [Ctrl][Alt][-] - change to previous X server resolution

* [Ctrl][Alt][BkSpc] - kill the current X server. Used when normal exit is not possible.

* [Ctrl][Alt][Del] - shut down the system and reboot

* [Ctrl]c - kill the current process

* [Ctrl]d - logout from the current terminal

* [Ctrl]s - stop transfer to current terminal

* [Ctrl]q - resume transfer to current terminal. This should be tried if the terminal stops responding.

* [Ctrl]z - send current process to the background

* reset - restore a terminal to its default settings

* [Leftmousebutton] - Hold down left mouse button and drag to highlight text. Releasing the button copies the region to the text buffer under X and (if gpm is installed) in console mode.

* [Middlemousebutton] - Copies text from the text buffer and inserts it at the cursor location. With a two-button mouse, click on both buttons simultaneously. It is necessary for three-button emulation to be enabled, either under gpm or in XF86Config.

Shorthand at the Linux Command Prompt

0 comments
Some of these are specific to the bash shell. I have not experimented enough with other shells to know which are common to all shells. See also the ``Bash Reference Card'', SSC (2000), available online.

* / - root directory

* ./ - current directory

* ./command_name - run a command in the current directory when the current directory is not on the path

* ../ - parent directory

* ~ - home directory

* $ - typical prompt when logged in as ordinary user

* # - typical prompt when logged in as root or superuser

* ! - repeat specified command

* !! - repeat previous command

* ^^ - repeat previous command with substitution

* & - run a program in background mode

* [Tab][Tab] - prints a list of all available commands. This is just an example of autocomplete with no restriction on the first letter.

* x[Tab][Tab] - prints a list of all available completions for a command, where the beginning is ``x''

* [Alt][Ctrl][F1] - switch to the first virtual text console

* [Alt][Ctrl][Fn] - switch to the nth virtual text console. Typically, there are six on a Linux PC system.

* [Alt][Ctrl][F7] - switch to the first GUI console, if there is one running. If the graphical console freezes, one can switch to a nongraphical console, kill the process that is giving problems, and switch back to the graphical console using this shortcut.

* [ArrowUp] - scroll through the command history (in bash)

* [Shift][PageUp] - scroll terminal output up. This also works at the login prompt, so you can scroll through your boot messages.

* [Shift][PageDown] - scroll terminal output down

* [Ctrl][Alt][+] - switch to next X server resolution (if the server is set up for more than one resolution)

* [Ctrl][Alt][-] - change to previous X server resolution

* [Ctrl][Alt][BkSpc] - kill the current X server. Used when normal exit is not possible.

* [Ctrl][Alt][Del] - shut down the system and reboot

* [Ctrl]c - kill the current process

* [Ctrl]d - logout from the current terminal

* [Ctrl]s - stop transfer to current terminal

* [Ctrl]q - resume transfer to current terminal. This should be tried if the terminal stops responding.

* [Ctrl]z - send current process to the background

* reset - restore a terminal to its default settings

* [Leftmousebutton] - Hold down left mouse button and drag to highlight text. Releasing the button copies the region to the text buffer under X and (if gpm is installed) in console mode.

* [Middlemousebutton] - Copies text from the text buffer and inserts it at the cursor location. With a two-button mouse, click on both buttons simultaneously. It is necessary for three-button emulation to be enabled, either under gpm or in XF86Config.

Here are the some of usefull IPTABLES Commands

1 comments
How To open or close ports

Before using commands for opening the port please make sure the specific port is already opened and what is the use of that port.

you can verify the port with

#  netstat -nap | grep :

1.you can open OR block TCp port with following syntax

iptables -A INPUT -p tcp –dport -j ACCEPT
iptables -A INPUT -p tcp –dport -j DROP - to block the port


2. You can open UDP port with

iptables -A INPUT -p udp –sport -j ACCEPT
iptables -A INPUT -p udp –sport -j DROP - to block the port


after that

3 service iptables save

To allow or block IPs:

iptables -A INPUT -s <> -j ACCEPT
iptables -A INPUT -s <> -j DROP - to block the IP


Make sure to save IPtables if you did changes in IPtables

Usefull Options
Either long or short options are allowed.
--append -A chain Append to chain
--delete -D chain Delete matching rule from chain
--delete -D chain rulenum
Delete rule rulenum (1 = first) from chain
--insert -I chain [rulenum]
Insert in chain as rulenum (default 1=first)
--replace -R chain rulenum
Replace rule rulenum (1 = first) in chain
--list -L [chain] List the rules in a chain or all chains
--flush -F [chain] Delete all rules in chain or all chains
--zero -Z [chain] Zero counters in chain or all chains
--new -N chain Create a new user-defined chain
--delete-chain
-X [chain] Delete a user-defined chain
--policy -P chain target
Change policy on chain to target

service iptables save - To save IPtables
service iptables restart - To restart the IPtables firew
all.
Go_GrEen^ThiNk_GReeN~LoVE_GreEn - Pushkar

Go_GrEen^ThiNk_GReeN~LoVE_GreEn - Pushkar

Here are the some of usefull IPTABLES Commands

1 comments
How To open or close ports

Before using commands for opening the port please make sure the specific port is already opened and what is the use of that port.

you can verify the port with

#  netstat -nap | grep :

1.you can open OR block TCp port with following syntax

iptables -A INPUT -p tcp –dport -j ACCEPT
iptables -A INPUT -p tcp –dport -j DROP - to block the port


2. You can open UDP port with

iptables -A INPUT -p udp –sport -j ACCEPT
iptables -A INPUT -p udp –sport -j DROP - to block the port


after that

3 service iptables save

To allow or block IPs:

iptables -A INPUT -s <> -j ACCEPT
iptables -A INPUT -s <> -j DROP - to block the IP


Make sure to save IPtables if you did changes in IPtables

Usefull Options
Either long or short options are allowed.
--append -A chain Append to chain
--delete -D chain Delete matching rule from chain
--delete -D chain rulenum
Delete rule rulenum (1 = first) from chain
--insert -I chain [rulenum]
Insert in chain as rulenum (default 1=first)
--replace -R chain rulenum
Replace rule rulenum (1 = first) in chain
--list -L [chain] List the rules in a chain or all chains
--flush -F [chain] Delete all rules in chain or all chains
--zero -Z [chain] Zero counters in chain or all chains
--new -N chain Create a new user-defined chain
--delete-chain
-X [chain] Delete a user-defined chain
--policy -P chain target
Change policy on chain to target

service iptables save - To save IPtables
service iptables restart - To restart the IPtables firew
all.
Go_GrEen^ThiNk_GReeN~LoVE_GreEn - Pushkar

Go_GrEen^ThiNk_GReeN~LoVE_GreEn - Pushkar

xargs: unmatched single quote

0 comments
OK… Here is a short tip that might help others in the same situation: here i was running a simple find/grep command that I have always used to search for files matching some string; this was something simple like:

find . -type f | xargs grep string

And bum… After a while the command failed with the error: “xargs: unmatched single quote“. This happened because one of the files returned by the find command had a quote character inside its file name. xargs was not able to distinguish between the quote part of the file name and the quote used to quote names.

If you encounter a similar problems the solutions is to add -printf ‘”%p”\n’ to the find command line that will enclose all file names into double quotes:

find . -type f -printf '"%p"\n' | xargs grep string

if your find command does not have the -printf operand, you can try to use the -print0 operand and the command will look like:

find . -type f -print0 | xargs -0 grep string

How to hide your shell commands

0 comments

Today I came across a neat, but pointless shell command. By running the following in shell, it will hide any commands you run.



root@server2 [/]# stty -echo

In order to disable this mode, simply remove the “-” before echo.



root@server2 [/]# stty echo

I guess there really is no point to the command, though you could always mess with your coworkers if they leave their shell prompt open

Disk usage on cPanel server

0 comments
On a Linux system for a system administrator it is necessary to check disk usage on the server and make sure that the disk space does not get 100% and cause problem for the users, so as a routine you should always check for disk space.

The command to check disk space on the complete server is:

root@server# df –h


If a particular partition is consuming too much disk space and you need to find which folder under that partition is using it, for example the partition is /var you can use the command:

root@server# cd /var

root@server# du –sh *

This will display the size of each directory under the /var partition.

So, be proactive and keep your server always healthy.

Backing Up/Restoring Mysql Databases using SSH/Shell

50 comments

This is really the most handy tool for mysql databases. A built in mysqldump can be used via shell to dump mysql databases within a few minutes. Sometimes dumping backups using phpmyadmin is too hazardous. So it’s really a necessary tool and fast too. I have listed this commands and i believe this should be useful to lots of system admins



Taking Database Backup
mysqldump -uuser -pmysqluserpassword database_name > database_name.sql

Restoring a Database
mysql -uuser -pmysqluserpassword database_name < database_name.sql

Here, you need to replace the user with the proper database user who has access to that specific database and the mysqluserpassword directs the password of that specific user. Here, one important thing is database_name.sql file can be replaced with the location of the sql file, suppose if you want to save it or retrieve from /home/backup then you can put /home/backup/database_name.sql to do that.

Netstat Command [Linux/Unix]

0 comments
Informations:

Netstat command Shows network status.







Syntax
netstat [-a] [-n] [-v]

netstat [-g | -m | -p | -s | -f address_family ] [-n] [-P protocol]


netstat [ -i ] [ -I interface ] [ interval ]


netstat -r [-a] [-n] [-v ]


netstat -M [-n] [-s ]


netstat -D [ -I interface ]


































































-a



Show the state of all sockets and all routing table entries; normally, sockets used by server processes are not shown and only interface, host, network, and default routes are shown.



-n



Show network addresses as numbers. netstat normally displays addresses as symbols. This option may be used with any of the display formats.



-v



Verbose. Show additional information for the sockets and the routing table.



-g



Show the multicast group memberships for all interfaces.



-m



Show the STREAMS statistics.



-p



Show the address resolution (ARP) tables.



-s



Show per-protocol statistics. When used with the -M option, show multicast routing statistics instead.



-i



Show the state of the interfaces that are used for TCP/IP traffic.



-r



Show the routing tables.



-M



Show the multicast routing tables. When used with the -s option, show multicast routing statistics instead.



-d



Show the state of all interfaces that are under Dynamic Host Configuration Protocol (DHCP) control.



-D



Show the status of DHCP configured interfaces.



-f address_family



imit statistics or address control block reports to those of the specified address_family, which can be one of:




inet For the AF_INET address family
unix For the AF_Unix address family



-P protocol



Limit display of statistics or state of all sockets to those applicable to protocol.



- I interface



Show the state of a particular interface. interface can be any valid interface such as ie0 or
le0.




Examples:


netstat


Displays generic net statistics of the host you are currently connected to.



netstat -an


Shows all connections to the server including the source and destination ips and ports if you have proper permissions.



netstat -rn


Displays routing table for all ips bound to the server.



netstat -an |grep :80 |wc -l


Display all active connections on port 80.



Not found yet.