Friday 24 May 2013

Command ShortCuts




==================================
Linux command line ShortCuts
==================================
Ctrl+l
-clear the terminal
-same as clear command
----------------------------------
Ctrl+c
-kill the current process (if command is executed)
-cancel command (if command is not executed)
----------------------------------
Ctrl+z
-send the current process into background
-use fg command to bring back the background process
----------------------------------
Ctrl+d
-log out if pressed at the beginning of an empty line
----------------------------------
Ctrl+r
-find the last command that contained the letters we type.
----------------------------------
Ctrl+s
-suspends the output
----------------------------------
Ctrl+q
-resume output
----------------------------------
Shift+pageUp
-scroll terminal output up
----------------------------------
Shift+pageDown
-scroll terminal output down
----------------------------------
Ctrl+u
-delete from cursor position to beginning of line
----------------------------------
Ctrl+k
-delete from cursor position to the end of line.
----------------------------------
Esc+t
-Swap words between the cursor position
----------------------------------
Ctrl+t
-swap characters 
----------------------------------
Ctrl+w
-Delete the word before the cursor.
----------------------------------
Ctrl+a [or Home]
-move cursor to beginning of line
----------------------------------
Ctrl+e [or End]
-move cursor to end of line
----------------------------------
Alt+.
-recall last argument from the previous command
----------------------------------
Tab
-auto completes command/files/folder names
----------------------------------
UpArrow/DownArrow
-move into the command history
----------------------------------

Thursday 9 May 2013

Top Command



top

Top command Details
-Line1 (same as cmd 'uptime')
-current time
-up time of the machine
-number of users logged in
-Load average on system at 1, 5, 15 min interval.
-other commands
-uptime
-w
-takes the value from /proc/loadavg
-A load average of 1 means your cpu is being fully utilized and processes are not having to wait to use a CPU.
-A load average above 1 indicates that processes need to wait and your system will be less responsive.
-If your load average is consistently above 3 and your system is running slow you may want to upgrade to more CPU’s or a faster CPU.
Line2
-total number of tasks/process on the machine,
-number of running process,
-number of sleeping process,
-number of stopped process,
-number of Zombie process.
Line3
-Show CPU utilization details
-%us - % of user processes utilized
-%sy - % of system processes
-%id - % of available cpu (it should be greater than 90%)
-%wa - % of time CPU is waiting for IO. ( it should be 0 or 1 or 3)
-When analyzing the Cpu(s) look at the %id to see how much cpu is available.
-If %id is low then focus on %us, %sy, and %wa to determine what is using the CPU.
Line4
-Gives RAM details
Line5
-Gives SWAP details.
Line6
-PID – process ID of the process
-USER – User who is running the process
-PR – The priority of the process
-NI – Nice value of the process (higher value indicates lower priority)
-VIRT – The total amount of virtual memory used
-RES – Resident task size
-SHR – Amount of shared memory used
-S – State of the task.
-S (sleeping)
-D (uninterruptible sleep)
-R (running)
-Z (zombies)
-T (stopped or traced)
-%CPU – Percentage of CPU used
-%MEM – Percentage of Memory used
-TIME+ – Total CPU time used
-COMMAND – Command issued
==========================================
Top commands shortcuts
l --To display or to hide load average line
t --To display or to hide task/cpu line
1 --To display or hide all other CPU's
m --to display or to hide RAM and SWAP details
s --To change the time interval for updating top results(value is in sec's)
R --To sort by PID number
u -- Press u then username to get only that user process details
P --To sort by CPU utilization
M --To sort by RAM utilization
c --To display or hide command full path
r --To renice a process, press r then the PID no then the renice value to renice a process.
k --To kill a process, press k then PID number then enter to kill a process
w --To save the modified configuration permanently.
q --To quit the top command.
h --for getting help on top command
==========================================
List processes owned by user u1
-top -u u1
List the Stuck process
-top -b -n 1 | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}'


Saturday 4 May 2013

RPM Command




RPM
-rpm -qa --last | less
-list rpm installation history with date n time
-rpm -qa --qf '%{name}.%{arch}\n' | grep 'i[36]86$' | grep firefox
-rpm -qf /usr/filename
-file owned/used by which package
-rpm -Uvh --oldpackage [filename]
-rpm -qi <package-name>
-installed package details( i = information)
-rpm -ql <package-name>
-package associated with files.
-rpm -qpR <package-name>
-packages with all dependancy
-rpm -qd <package-name>
-list doc file of the package
-rpm -qc <package-name>
-list config liles
-rpm -qa |grep -i "virtual"
-rpm -ivh --nodeps --force <package>
-install package without dependencies and forcefully.
-/var/lib/rpm
-database of currently installed rpms
-/var/log/rpmpkgs
-list of all rpms on system

Find Command




Find
Find files using name
-find / -xdev -iname "*.ldif"
-i= ignore case
-/= find all directory under /
-xdev= dont search mounted direcoties,dont include other filesystem
Find all of the files which have been modified within the last 10 days
-find * -mtime -10
Find list of all pdf files that were accessed in last 60 days
-find / -iname *.pdf -atime -60
File with size over 1GB
-find / -size +1024000k -exec du -h '{}' \; -print
Find 10 largest files in /
-find / -xdev -type f -exec ls -s {} \; |sort -n -r |head -10
-s=size
-n= numeric value
-r= reverse
Find files/directory which has full permission
-find / -perm -777 -type f -exec ls -l {} \;
-perm= for permission
-f= for file
-d= for directory
Find files that are owned by user user1
-find / -xdev -user user1
Find tatal how many files are there in the machine.
-find / -xdev |wc -l

==========================================================
To delete all .LOG files older than 7 days
    -find /data01/logs -name "*.LOG" -mtime +7 -exec ls -lrt {} \; >> /data01/logs/filetodelete.txt
    -find /data01/logs -name "*.LOG" -mtime +7 -exec rm -f {} \;

==========================================================