{"id":703,"date":"2012-07-13T15:39:14","date_gmt":"2012-07-13T07:39:14","guid":{"rendered":"http:\/\/rmohan.com\/?p=703"},"modified":"2012-07-27T07:41:33","modified_gmt":"2012-07-26T23:41:33","slug":"linux-commands","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=703","title":{"rendered":"Linux Commands"},"content":{"rendered":"<div><strong>To view System Resource Information<\/strong><\/div>\n<div>uname &#8211;help<br \/>\nuname -r<br \/>\ngrep model \/proc\/cpuinfo<br \/>\ngrep MemFree \/proc\/meminfo<br \/>\nsudo -u root lastcomm -f \/var\/account\/pacct<br \/>\ncat \/proc\/version<br \/>\n# cat \/proc\/cpuinfo<br \/>\n# cat \/proc\/meminfo<br \/>\n# cat \/proc\/zoneinfo<br \/>\n# cat \/proc\/mounts<br \/>\ncat \/etc\/redhat-release<br \/>\ngrep MemTotal \/proc\/meminfo<br \/>\ngrep SwapTotal \/proc\/meminfo<br \/>\ndf -k \/tmp<br \/>\ngrep &#8220;model name&#8221; \/proc\/cpuinfo<br \/>\nifconfig (\/sbin\/ifconfig)<br \/>\nuaname -r<br \/>\nlshal:detected hardware<br \/>\nrpm -qa:\u00a0 display pakage<br \/>\nrpm -qa | less<br \/>\n<strong>Linux Kernel Information:<\/strong><\/div>\n<div>cat \/etc\/sysctl.conf<br \/>\ncat \/etc\/hosts<br \/>\n\/sbin\/ifconfig<br \/>\nUname -r<br \/>\ncat \/etc\/security\/limits.conf<br \/>\ncat \/proc\/sys\/kernel\/sem<br \/>\ncat \/proc\/sys\/kernel\/shmmax<br \/>\ncat \/proc\/sys\/kernel\/shmall<br \/>\ncat \/proc\/sys\/kernel\/shmmni<br \/>\ncat \/proc\/sys\/fs\/file-max<br \/>\ncat \/proc\/sys\/net\/ipv4\/ip_local_port_range<br \/>\n\/sbin\/lsmod<br \/>\ncat \/etc\/issue<br \/>\nsysctl -a | grep shm<br \/>\nsysctl -a | grep ip_local_port_range<br \/>\n\/etc\/inittab:\u00a0 init process determines which runlevel it should be<br \/>\nw, ps -a, ps -Alf, ps -AlFH, ps -AlLm<br \/>\nps -u oracle, ps -u anguyen<\/div>\n<div><strong>Commands to monitor bottlenecks such as Disk, Memory \/ CPU\/Network, or System Activity:<\/strong><\/div>\n<div>top ? t, m, A: top consumer, r: renice, o: interactively select<br \/>\nvmstat 3, vmstat -m:memority slab info, vmstat -a<br \/>\nw, ps -a, ps -Alf, ps -AlFH, ps -AlLm<br \/>\nps -u oracle, ps -u attunity<br \/>\nuptime<br \/>\nfree<br \/>\nfee -s 2<br \/>\nwatch -n 3 -d free<br \/>\nwatch -d cat \/proc\/meminfo<br \/>\nsar -B -f \/var\/log\/sa\/sa14<br \/>\nsar -W -f \/var\/log\/sa\/sa14<br \/>\nvmstat -m<br \/>\nvmstat -a<br \/>\nipcs -sm<br \/>\nipcs -lms<br \/>\nsar -n DEV | more<br \/>\nsar 4 5<br \/>\nmpstat -P ALL<br \/>\n<strong>MEMORY intensive process:<\/strong><\/div>\n<div>ps -e -o pmem,pid,user,tty,args | grep -i oracle | sort -n -k 1 -r | head<br \/>\nwatch -n 3 -d free<br \/>\nwatch -d cat \/proc\/meminfo<br \/>\n<strong>CPU intensive process<\/strong><\/div>\n<div>top<br \/>\nps -e -o pcpu,pid,user,tty,args | sort -n -k 1 -r | head<br \/>\nmpstat -P 0 2 20 (processor 0<br \/>\nmpstat -P ALL<br \/>\nsar -u -f<strong>Disk Storage<\/strong><strong><br \/>\n<\/strong><strong>************************************<\/strong><br \/>\niostat -d 3, iostat 2 15<br \/>\niostat -xd 10<strong>sorting files by size<\/strong><strong><br \/>\n<\/strong><strong>***********************<\/strong><br \/>\nls -alS | head -5<br \/>\nmpstat -P ALL<br \/>\nsar 4 5<br \/>\n<strong>****************************************************<\/strong><strong><br \/>\n<\/strong><strong>Network<\/strong><strong><br \/>\n<\/strong><strong>**************************************************<\/strong><br \/>\nlsmod | grep -i bonding<br \/>\ncat \/etc\/sysconfig\/network-scripts\/ifcfg-eth0 (check bonding)..the difference NETWORK, IPADDRESS, NETMASK<br \/>\nnetstat -s | less<br \/>\nnetstat &#8211;interfaces eth0<br \/>\nnetstat -ptc<br \/>\nsar -n DEV<br \/>\nnetstat -nat | awk &#8216;{ print $5}&#8217; | cut -d: -f1 | sed -e &#8216;\/^$\/d&#8217; | uniq<br \/>\ntcpdump -n -i eth1 -s 0 -w output.txt src or dst port 80<br \/>\niptraf &#8211; Real-time Network Statistics<br \/>\n<strong>Network traffic<\/strong><br \/>\nnetstat -ptc<br \/>\nsar -n DEV<br \/>\nsar &#8211; Collect and Report System Activity<br \/>\n<strong>*************************************************<\/strong><strong><br \/>\n<\/strong><strong>Oracle<\/strong><strong><br \/>\n<\/strong><strong>***************************************************<\/strong><br \/>\ncpio -idmv &lt; 10201_database_linux_x86_64.cpio<br \/>\nid oracle<br \/>\nid nobody<br \/>\npgrep sshd<br \/>\nenv | grep PATH<\/p>\n<\/div>\n<div><strong>detected hardware\u00a0<\/strong>lshal:<br \/>\n<strong>init process determines which runlevel it should be\u00a0<\/strong>\/etc\/inittab<\/div>\n<div><strong>shutdown<\/strong><br \/>\nshutdown -t3 -r now<br \/>\nmount \/dev\/hda4 \/data\/oracle\/bkup1:<br \/>\ngrep \u2018Ashley Nguyen\u2019 \/etc\/passwd<br \/>\nfind \/ -name install.log<br \/>\nsed \u2018s\/anguyen\/lvu\/\u2019 \/etc\/passwd &gt; \/tmp\/test<br \/>\nps aux | grep nfs<br \/>\nfree:<br \/>\nIfconfig -a<\/div>\n<div>To determine the amount of shared memory available, enter the following command:automatic memory management<br \/>\n# df -k \/dev\/shm\/<br \/>\nTo determine the distribution and version of Linux installed, enter the following command:<br \/>\n# cat \/proc\/version<br \/>\nTo determine whether the required packages are installed, enter commands similar to the following:<br \/>\n# rpm -q package_name<br \/>\n<strong>Add group<\/strong><br \/>\n# \/usr\/sbin\/groupadd oper<br \/>\n<strong>Modify user:\u00a0 <\/strong>usermod -g oinstall -G dba oracle<br \/>\n<strong>Create disks:<\/strong><br \/>\nfdisk -l<\/div>\n<div><strong>give password to oracle user<\/strong><br \/>\npasswd oracle<\/div>\n<div><strong>change ownership in linux<\/strong><br \/>\nchown<\/div>\n<div><strong>clear screen <\/strong><br \/>\nclear<br \/>\n<strong>TAR &#8211; backup \/ restore<\/strong><br \/>\ntar -cf myfiles.tar *.trc (create)<br \/>\ntar xvf myfiles.tar (extract)<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<p><strong>To create new directory<\/strong><\/p>\n<div>\n<div id=\"highlighter_657345\">\n<table width=\"188\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>mkdir target_director<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>To copy an entire folder (directory tree) in Linux<\/strong><\/p>\n<div>\n<div id=\"highlighter_790904\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>cp -ap \/var\/lib\/mysql \/mnt\/mysql -ap for same permission as source<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>For checking the size of current folder<\/strong><\/p>\n<div>\n<div id=\"highlighter_471884\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>du -ch | grep total<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>To find the size of the hdd<\/strong><\/p>\n<div>\n<div id=\"highlighter_219914\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>just enter df<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>To find out the size of the folder in the folder<\/strong><\/p>\n<div>\n<div id=\"highlighter_416400\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>du<\/code><\/div>\n<div><code>du -a to show all the file's size<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>See all files and their size<\/strong><\/p>\n<div>\n<div id=\"highlighter_140186\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>du -s * -h<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>To output the number of files in the current directory<\/strong><\/p>\n<div>\n<div id=\"highlighter_529538\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>ls | wc -l<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>See all the jobs<\/strong><\/p>\n<div>\n<div id=\"highlighter_823347\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div><\/div>\n<\/td>\n<td>\n<div>\n<div><code>ps -aux<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>To find out RAM size on Linux machine<\/strong><\/p>\n<div>\n<div id=\"highlighter_953451\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>free<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Rename folder\/filename<\/strong><\/p>\n<div>\n<div id=\"highlighter_225462\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>mv test hope<\/code><\/div>\n<div><code>mv *.rtf *.txt<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>To find which process is consuming how much RAM?<\/strong><\/p>\n<div>\n<div id=\"highlighter_581573\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>top<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>To see the free ram memory<\/strong><\/p>\n<div>\n<div id=\"highlighter_911967\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>free -m<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>To update yum using corn<\/strong><\/p>\n<div>\n<div id=\"highlighter_244719\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>\u00a021 *** usr\/bin\/yum -y update<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Create tar.gz file<\/strong><\/p>\n<div>\n<div id=\"highlighter_264809\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>tar czvf myfolder.tar.gz abcfolder\/<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Untar a tar file<\/strong><br \/>\ntar czvf myfolder.tar.gz abcfolder\/<br \/>\n[\/sourcecode]<\/p>\n<p><strong>Delete bash History<\/strong><br \/>\nTry to delete the content of ~\/.bash_history<\/p>\n<p><strong>To add new user<\/strong><br \/>\n* Adding a new user (useradd)<br \/>\n* Modifying an existing user (usermod)<\/p>\n<p>Options:<br \/>\n* -d home directory<br \/>\n* -s starting program (shell)<br \/>\n* -p password<br \/>\n* -g (primary group assigned to the users)<br \/>\n* -G (Other groups the user belongs to)<br \/>\n* -m (Create the user\u2019s home directory<\/p>\n<div>\n<div id=\"highlighter_321094\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div><\/div>\n<\/td>\n<td>\n<div>\n<div><code>useradd -gusers -Gmgmt -s\/bin\/shell -pass -d\/home\/jambura -m jambura<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>User\u2019s home directory should be 700. If you are operating a ~username type server, the public_html directory should be 777. You may also need to open up the home directory to 755.<\/p>\n<div>\n<div id=\"highlighter_446712\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>useradd -s\/bin\/bash -pass -d\/imp\/sysbsd -m sysbsd<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>For allowing sudo<\/strong><\/p>\n<div>\n<div id=\"highlighter_943500\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>sudo adduser jambura admin<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>To delete user<\/strong><\/p>\n<div>\n<div id=\"highlighter_543406\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>userdel user<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>To display your crontab file<\/strong><\/p>\n<div>\n<div id=\"highlighter_790340\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>crontab -l<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>root can view any users crontab file by adding \u201c-u username\u201d<\/strong><\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td><\/td>\n<td>\n<div>\n<div><code>crontab -u bappy -l\u00a0 # List bappy's crontab file.<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>tar tvf myfiles.tar (show the details)<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>To view System Resource Information uname &#8211;help uname -r grep model \/proc\/cpuinfo grep MemFree \/proc\/meminfo sudo -u root lastcomm -f \/var\/account\/pacct cat \/proc\/version # cat \/proc\/cpuinfo # cat \/proc\/meminfo # cat \/proc\/zoneinfo # cat \/proc\/mounts cat \/etc\/redhat-release grep MemTotal \/proc\/meminfo grep SwapTotal \/proc\/meminfo df -k \/tmp grep &#8220;model name&#8221; \/proc\/cpuinfo ifconfig (\/sbin\/ifconfig) uaname -r lshal:detected [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/703"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=703"}],"version-history":[{"count":4,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/703\/revisions"}],"predecessor-version":[{"id":822,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/703\/revisions\/822"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}