Tuesday, January 15, 2008

Linux Commands

Hi all... You can play through the linux shell with the following commands.

mpstat

  [linux@wordsworth ~]$ man -k mpstat
mpstat (1) - Report processors related statistics
snmpstatus (1) - Retrieves important information from a network entity
[linux@wordsworth ~]$

[linux@wordsworth ~]$ mpstat 5
Linux 2.6.9-55.0.2.ELsmp (wordsworth.armialocal.com) 08/12/2007

09:59:51 PM CPU nice iowait soft %idle intr/s
09:59:56 PM all 18.70 0.10 42.50 0.00 0.10 0.00 38.60 1290.60
10:00:01 PM all 15.30 0.00 41.80 0.00 0.10 0.00 42.80 1276.00
10:00:06 PM all 19.98 0.00 42.36 0.20 0.00 0.00 37.46 1273.35

vmstat

   [linux@wordsworth ~]$ man -k vmstat
vmstat (8) - Report virtual memory statistics
linux@wordsworth ~]$

[linux@wordsworth ~]$ vmstat 2
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
2 0 355084 20888 10736 84396 1 1 37 29 11 13 10 22 67 1
1 0 355084 20936 10736 84396 0 0 0 0 1284 1191 10 42 48 0
3 0 355084 19848 10736 84396 0 0 0 0 1246 1123 9 44 47 0

Linux Server Monitoring Commands-How Do I Monitor A Linux Server

How to Monitor the services using up most for the cpu and memory on a server.

ps auxfw|sort -nr|grep -v 0.0


[root@wordsworth ~]# ps auxfw|sort -nr|grep -v 0.0
USER PID MEM VSZ RSS TTY STAT START TIME COMMAND
linux 613 0.4 3.2 21844 15896 ? S 15:01 0:10 wish /usr/bin/amsn
linux 4085 0.1 1.7 28384 8240 ? S Mar01 13:45 /usr/libexec/wnck-applet --oaf-
linux 32728 1.8 7.5 67216 36196 ? S 14:54 0:50 /usr/lib/opera/9.10-20061214.5/
linux 31458 0.1 1.0 48068 5088 ? Sl 12:26 0:15 xmms -e
linux 30276 0.6 4.4 79656 21488 ? Sl 07:55 3:09 skype
linux 30261 3.0 18.8 221380 90792 ? Sl 07:54 14:15 \_ /home/linux/firefox/firefox-
linux 30099 0.1 4.5 123240 21776 ? Sl 07:25 0:54 \_ /usr/lib/
linux 2285 0.1 2.6 35504 12560 ? S Mar06 3:06 gaim


root@server [~]# ps auxfw|grep -vE '0.0|0.1'

To find the CPU process taking the most load

root@server [~]ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

Create Password Encrypted File


[root@manchester ~]# vi -x test.txt

Then Enter the password twice. You done it man. No one can open that file without password.

Command To Find OS type in Linux

[root@manchester ~]# uname
Linux
[root@manchester ~]# uname -a
Linux manchester.armia.com 2.6.9-22.ELsmp #1 SMP Sat Oct 8 19:11:43 CDT 2005 i686 i686 i386 GNU/Linux

Command To Find CPU Info in Linux

[root@server1 ~]# cat /proc/cpuinfo

Command To Find whether DMA enabled

[root@web-04 httpd]# hdparm -d /dev/sda1

Command To Transfer files and folders between servers

rsync -avz -e ssh source_folder username@serverIP:destinationfolder

OR
root@sw1 [~]# scp filename root@IP:destination_folder

If you want to transfer folders,

root@sw1 [~]# scp -r folder_name root@IP:destination_folder

Command To Find the number of http connections from IPs to the server.

netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

lsof -i TCP:80

mkdir - make directories

Usage

mkdir [OPTION] DIRECTORY

Options

Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.

-m, mode=MODE set permission mode (as in chmod), not rwxrwxrwx - umask

-p, parents no error if existing, make parent directories as needed

-v, verbose print a message for each created directory

-help display this help and exit

-version output version information and exit

cd - change directories

Use cd to change directories. Type cd followed by the name of a directory to access that directory.Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below.

mv- change the name of a directory

Type mv followed by the current name of a directory and the new name of the directory.

Ex: mv testdir newnamedir

pwd - print working directory

will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page

rmdir - Remove an existing directory

rm -r

Removes directories and files within the directories recursively.

chown - change file owner and group

Usage

chown [OPTION] OWNER[:[GROUP]] FILE

chown [OPTION] :GROUP FILE

chown [OPTION] --reference=RFILE FILE

Options

Change the owner and/or group of each FILE to OWNER and/or GROUP. With --reference, change the owner and group of each FILE to those of RFILE.

-c, changes like verbose but report only when a change is made

-dereference affect the referent of each symbolic link, rather than the symbolic link itself

-h, no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can change the ownership of a symlink)

-from=CURRENT_OWNER:CURRENT_GROUP

change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omitted, in which case a match is not required for the omitted attribute.

-no-preserve-root do not treat `/' specially (the default)

-preserve-root fail to operate recursively on `/'

-f, -silent, -quiet suppress most error messages

-reference=RFILE use RFILE's owner and group rather than the specifying OWNER:GROUP values

-R, -recursive operate on files and directories recursively

-v, -verbose output a diagnostic for every file processed

The following options modify how a hierarchy is traversed when the -R option is also specified. If more than one is specified, only the final one takes effect.

-H if a command line argument is a symbolic link to a directory, traverse it

-L traverse every symbolic link to a directory encountered

-P do not traverse any symbolic links (default)

chmod - change file access permissions

Usage

chmod [-r] permissions filenames

r Change the permission on files that are in the subdirectories of the directory that you are currently in. permission Specifies the rights that are being granted. Below is the different rights that you can grant in an alpha numeric format.filenames File or directory that you are associating the rights with Permissions

u - User who owns the file.

g - Group that owns the file.

o - Other.

a - All.

r - Read the file.

w - Write or edit the file.

x - Execute or run the file as a program.

Numeric Permissions:

CHMOD can also to attributed by using Numeric Permissions:

400 read by owner

040 read by group

004 read by anybody (other)

200 write by owner

020 write by group

002 write by anybody

100 execute by owner

010 execute by group

001 execute by anybody

ls - Short listing of directory contents

-a list hidden files

-d list the name of the current directory

-F show directories with a trailing '/'

executable files with a trailing '*'

-g show group ownership of file in long listing

-i print the inode number of each file

-l long listing giving details about files and directories

-R list all subdirectories encountered

-t sort by time modified instead of name

cp - Copy files

cp myfile yourfile

Copy the files "myfile" to the file "yourfile" in the current working directory. This command will create the file "yourfile" if it doesn't exist. It will normally overwrite it without warning if it exists.

cp -i myfile yourfile

With the "-i" option, if the file "yourfile" exists, you will be prompted before it is overwritten.

cp -i /data/myfile

Copy the file "/data/myfile" to the current working directory and name it "myfile". Prompt before overwriting the file.

cp -dpr srcdir destdir

Copy all files from the directory "srcdir" to the directory "destdir" preserving links (-poption), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another dir

ln - Creates a symbolic link to a file.

ln -s test symlink

Creates a symbolic link named symlink that points to the file test Typing "ls -i test symlink" will show the two files are different with different inodes. Typing "ls -l test symlink" will show that symlink points to the file test.

locate - A fast database driven file locator.

slocate -u

This command builds the slocate database. It will take several minutes to complete this command.This command must be used before searching for files, however cron runs this command periodically on most systems.locate whereis Lists all files whose names contain the string "whereis". directory.

more - Allows file contents or piped output to be sent to the screen one page at a time

less - Opposite of the more command

cat - Sends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.

whereis - Report all known instances of a command
wc - Print byte, word, and line counts

bg

bg jobs Places the current job (or, by using the alternative form, the specified jobs) in the background, suspending its execution so that a new user prompt appears immediately. Use the jobs command to discover the identities of background jobs.

cal month year - Prints a calendar for the specified month of the specified year.

cat files - Prints the contents of the specified files.

clear - Clears the terminal screen.

cmp file1 file2 - Compares two files, reporting all discrepancies. Similar to the diff command, though the output format differs.

diff file1 file2 - Compares two files, reporting all discrepancies. Similar to the cmp command, though the output format differs.

dmesg - Prints the messages resulting from the most recent system boot.

fg

fg jobs - Brings the current job (or the specified jobs) to the foreground.

file files - Determines and prints a description of the type of each specified file.

find path -name pattern -print

Searches the specified path for files with names matching the specified pattern (usually enclosed in single quotes) and prints their names. The find command has many other arguments and functions; see the online documentation.

finger users - Prints descriptions of the specified users.

free - Displays the amount of used and free system memory.

ftp hostname

Opens an FTP connection to the specified host, allowing files to be transferred. The FTP program provides subcommands for accomplishing file transfers; see the online documentation.

head files - Prints the first several lines of each specified file.

ispell files - Checks the spelling of the contents of the specified files.

kill process_ids

kill - signal process_ids

kill -l

Kills the specified processes, sends the specified processes the specified signal (given as a number or name), or prints a list of available signals.

killall program

killall - signal program

Kills all processes that are instances of the specified program or sends the specified signal to all processes that are instances of the specified program.

mail - Launches a simple mail client that permits sending and receiving email messages.

man title

man section title - Prints the specified man page.

ping host - Sends an echo request via TCP/IP to the specified host. A response confirms that the host is operational.

reboot - Reboots the system (requires root privileges).

shutdown minutes

shutdown -r minutes

Shuts down the system after the specified number of minutes elapses (requires root privileges). The -r option causes the system to be rebooted once it has shut down.

sleep time - Causes the command interpreter to pause for the specified number of seconds.

sort files - Sorts the specified files. The command has many useful arguments; see the online documentation.

split file - Splits a file into several smaller files. The command has many arguments; see the online documentation

sync - Completes all pending input/output operations (requires root privileges).

telnet host - Opens a login session on the specified host.

top - Prints a display of system processes that's continually updated until the user presses the q key.

traceroute host - Uses echo requests to determine and print a network path to the host.

uptime - Prints the system uptime.

w - Prints the current system users.

wall - Prints a message to each user except those who've disabled message reception. Type Ctrl-D to end the message.







No comments: