{"id":579,"date":"2016-01-08T09:33:10","date_gmt":"2016-01-08T09:33:10","guid":{"rendered":"http:\/\/www.dbafox.com\/?page_id=579"},"modified":"2017-08-17T11:35:21","modified_gmt":"2017-08-17T11:35:21","slug":"linux-useful-commands","status":"publish","type":"page","link":"https:\/\/dbafox.com\/?page_id=579","title":{"rendered":"Linux &#8211; Useful Commands"},"content":{"rendered":"\n<pre class=\"toolbar-overlay:false lang:sh decode:true \" >#Linux Logging\r\n\/var\/log\/messages\r\n\/var\/log\/syslog\r\n\/var\/log\/kernlog\r\n\r\nfor num in `seq 1 1 10`; do free -m; sleep 10; done\r\n\r\nfree -m\r\n##################################################################################\r\n             total       used       free     shared    buffers     cached\r\nMem:         28203      20010       8193        683        156       3850\r\n-\/+ buffers\/cache:      16002      12200\r\nSwap:         8159        156       8003\r\n##################################################################################\r\n# buffers\" and \"cached\" - amount of memory that the kernel is using for filesystem buffers\r\n#                       - freed\/released by kernel if required\r\n# \"-\/+ buffers\/cache    - the most important line - (=free+buffers+cache from Mem line)\r\n#\t\t\t\t\t\t- free on second line is the most important number\r\n# and look at used swap to see if system is swapping\r\n\r\n\r\n# some ed stuff that may be useful sometime\r\n# using the old ed because can't create temp file on \/etc (sed wants to create a temp file)\r\n# sed -i '\/^ORCL\/s\/:N\/:Y\/' \/etc\/oratab # would have been nice but can't create temporary file in \/etc\r\n# printf \"%s\\n\" '\/^ORCL\/s\/:N\/:Y\/' wq  | ed -s \/etc\/oratab\r\n\r\n# who is logged in\r\nw                    # Show who is logged on and what they are doing.\r\n\r\nw|sort -k3b         # show show is logged in and sort on 3rd column\r\n\r\n# disk usage\r\n\r\n# print line if first column is greater than 500000 \r\ndu|awk '$1&gt;500000 {print $0}'\r\n\r\ndu -k -x .\/ | sort -rn|more   -- disk usage - size in K\r\n\r\ndu -m -x .\/ | sort -rn|more   -- disk usage - size in M\r\n\r\ndu -h \/ | grep '[0-9]G'\r\n\r\ndu -h \/ | grep '[0-9]G'          - look for big files\r\n\r\ndf \/opt   - find out what mount point\/file system it is on\r\n\r\ndu -sh \/opt  -- monitor the size of \/opt\r\n \r\ndf $PWD - df current directory\r\n\r\ndu -sh .\r\n\r\ndu -sm * | sort -n\r\n\r\n#--------------------------------------------\r\n#Processes and memory:\r\n\r\nmpstat -P ALL\r\n\r\nps auxww |grep tnslsnr\r\nps -ef |grep tnslsnr\r\n\r\ncat \/proc\/meminfo\r\n\r\negrep --color 'Mem|Cache|Swap' \/proc\/meminfo\r\n\r\n# cpu available\r\ntop -bn1 | grep \"Cpu(s)\" |sed \"s\/.*, *\\([0-9.]*\\)%* id.*\/\\1\/\" |awk '{print 100 - $1\"%\"}'\r\n\r\n# Displays a line containing the totals memory in MB\r\nfree -t -m\r\n\r\n\r\n# run vmstat outputting MB (m) (note, this assumes 1000K = 1M (not 1024K = 1M)\r\nvmstat -S m 5\r\n\r\n# run vmstat outputting MB (M) (note, 1024K = 1M)\r\nvmstat -S M 5\r\n\r\n# Output\r\nprocs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------\r\n r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st\r\n 0  0     48    212    222   1253    0    0     1    32    0    1  1  0 99  0  0\r\n 0  0     48    212    222   1253    0    0     0    22  112  201  0  0 100  0  0\r\n 0  0     48    212    222   1253    0    0     0    13  126  212  0  0 100  0  0\r\n\r\n # memory section has meaning same as free -m below\r\n\r\n# Memory usage free -m\r\noracle@vmlinux1: free -m\r\n             total       used       free     shared    buffers     cached\r\nMem:          3949       3737        211          0        222       1253\r\n-\/+ buffers\/cache:       2261       1687\r\nSwap:         8191         48       8143\r\n\r\nMost important Used figure is buffers\/cache used - this is how much RAM apps are using - must be less than total Mem\r\n(Out of a total 3949 megabytes of memory (RAM), the system is using 3737 megabytes, and has 211 megabytes free - this\r\nis not actually correct because Linux uses spare memory to cache disk blocks) - so \"Used Mem\" usually nearly equals \"total Mem\"\r\n\r\nSimply adding memory by increasing SGA_TARGET gives Linux the possibility to use this memory - unless HugePages are used\r\nso that the memory is really allocated to Oracle SGA, Linux will steal the memory to use for caching\r\nCheck difference between HugePages and Transaparent HugePages\r\nMy understanding at present is that the SGA gets locked into HugePages, essentially caching at Linux level, the SGA\r\nSo it seems logical that Huge Pages must at least equal the SGA.\r\nNote pages and AMM are NOT compatible (but ASMM OK)\r\nShould also put minima on Oracle buffer cache and shared pool\r\n\r\n\r\n#Huge Pages\r\n----------\r\nHuge pages are locked in physical memory\r\nmemlock  (ulimit parameter) - how much memory oracle user can lock into address space - \r\nmemlock should match memory size of the number of Huge pages (Hugepagesize*nr_hugepages  --&gt; cat \/proc\/sys\/vm\/nr_hugepages)\r\ngrep HugePages \/proc\/meminfo to check Huge Page measures\r\n\r\n# huge pages checks\r\n\/proc\/meminfo |grep -i huge\r\ncat \/proc\/sys\/vm\/nr_hugepages\r\n\r\n------------------------------------------------------------------------------\r\n[root@vmlinux~]# free -m\r\n                total       used       free     shared    buffers     cached\r\nMem:         12011       9825       2186          0        243       5829\r\n-\/+ buffers\/cache:       3752       8259\r\nSwap:        16378        313      16065\r\n\r\nAdd buffers and cache together, you get: 6072. \r\nIf you subtract 6072 from used you get 3752 used \r\nIf you add it to free you get 8259 free\r\n\r\nUsed1 - (buffers + cached) = used2 \r\n9825 - (243 + 5829) = 3753 (3752 on second row)\r\n \r\nfree1 + (buffers + cache) = free2\r\n2186 + (243 + 5829) =  8285 (8259 on second row)\r\n\r\ncompare to:\r\nvmstat -s -S M | grep mem \r\n\r\nfree -glt (show mem in GB, and show totals)\r\n\r\n#update every 5 seconds\r\nfree -glt -s 5\r\n\r\n# Huge pages\r\n#(AMM must be disabled, memory_target=0)\r\nipcs -ma\r\n\r\ncat \/etc\/sysctl.conf| grep -i huge\r\n\r\ngrep ^Huge \/proc\/meminfo\r\n\r\nexample HugePages\r\n[oracle@vmlinux1 ~]$ grep ^Huge \/proc\/meminfo\r\nHugePages_Total:    7684\r\nHugePages_Free:     2672\r\nHugePages_Rsvd:     2669\r\nHugePages_Surp:        0\r\nHugepagesize:       2048 kB\r\n\r\nHugePages_Total * Hugepagesize = size of HugePage memeory\r\n\r\n-----------------------------------------------------------------------------\r\n\r\n#-------------------------------------------------------------\r\n#---- user stuff\r\n#-- cut the id string at first bracket, then at second bracket\r\n#-- e.g uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)\r\n#-- extracts root from above string\r\nid |cut -d\"(\" -f2 | cut -d \")\" -f1\r\n\r\n# list of all users on the system\r\ncat \/etc\/passwd |cut -d: -f1\r\n\r\n# list users having \/home as home directories\r\ncat \/etc\/passwd |grep \"\/home\" |cut -d: -f1\r\n\r\n# determine current user\r\necho $LOGNAME\r\necho $USER\r\nid\r\nid -u -n                   # username\r\nid -u                      # userid\r\n\r\n\r\n#!\/bin\/bash\r\n_user=\"$(id -u -n)\"\r\n_uid=\"$(id -u)\"\r\necho \"User name : $_user\"\r\necho \"User name ID (UID) : $_uid\"\r\n\r\n# make sure only root can execute the script\r\n#!\/bin\/bash\r\n## get UID \r\nuid=$(id -u)\r\n## Check for it\r\n[ $uid -ne 0 ] &amp;&amp; { echo \"Only root may enable the nginx-chroot environment to the system.\"; exit 1; }\r\n\r\n# grep\r\n\r\n# grep OR  (Mem or Active or Swap)\r\ncat \/proc\/meminfo|grep 'Mem\\|Active\\|Swap'\r\ncat \/proc\/meminfo|grep -E 'Mem|Active'\r\ncat \/proc\/meminfo|egrep 'Mem|Active'\r\ncat \/proc\/meminfo|grep -e Mem -e Active -e Swap\r\n\r\n#----------------------------------------------------------------\r\n#mounting and unmounting\r\n\r\n# for the problem of stale NFS handle: df: \/opt\/NetApp\/smo\/mnt\/-oracle-ORCL: Stale NFS file handle\r\numount \/opt\/NetApp\/smo\/mnt\/-oracle-ORCL\r\n\r\n\r\n#-----------------------------------------------------------------\r\n#sed and environment variables\r\n\r\nREPOS=\/foxrepos\/software\/Oracle\r\n\r\n# globally replace XXX in file ${REPOS}\/scripts\/.bash_profile with ORCL, YYY with ORCL2, output to file \"tmpprofile\"\r\nsed -e \"s:XXX:ORCL:g\" -e \"s:YYY:ORCL2:g\" &lt; ${REPOS}\/scripts\/.bash_profile &gt; .\/tmpprofile\r\n\r\n# copying files around\r\nscp oracle@vmlinux1:\/oracle\/tmp\/export1.DMP oracle@vmlinux2:\/oracle\/tmp\/export1.DMP\r\n\r\n#copy a file with a timestamp appended\r\n\r\n cp grub.conf grub.conf.$(date +\"%Y%m%d%H%M%S\")\r\n\r\n #------------------------------------------------------------\r\n#  delete hidden files - be careful!\r\nfind . -iname \".*\"  -exec rm {} \\;\r\n\r\n-- generate a list of files and grep through each of them\r\nls -ltr alert*| awk '{print $9}'|xargs grep cdmp -A1\r\n\r\ngrep 'cdmp' $(ls -ltr alert*)\r\n\r\nls -ltr alert* -exec grep 'cdmp' {} \\;\r\n\r\n# top\r\n# when executing top, type Z at the command line and the colour of the elements can be changed. For example\r\n# type S, 4, [RET] and the Summary data headings turn green \r\n\r\n# see crontab of all users:\r\nfor user in $(cut -f1 -d: \/etc\/passwd); do echo $user; crontab -u $user -l; done\r\nawk -F: '{print $1}' \/etc\/passwd | xargs -l1 crontab -lu 2&gt;\/dev\/null\r\n\r\n# df and sort by the 4th column (%Used)\r\ndf -h|grep \"\\\/oracle\\\/\" | ( sort -rn -k 4)\r\n\r\ndf -h |grep ORCL|sort -k5\r\n----------------------------------------------------------------------------\r\n\r\ngrep -i \"dictionary objn\" *.trc|awk '{print $5}' | sort|uniq\r\n\r\n----------------------------------------------------------------------------\r\n\r\n# deleting files older than 30 days example.\r\nfind . -name \"*.trc\"  -mtime +30 -exec rm -rf {} \\;\r\n\r\nfind . -name \"*.aud\"  -mtime +35 -exec rm -rf {} \\;\r\n\r\n\r\n---------------------------------------------------------------------------\r\n# execute command and see output differences\r\nwatch -d=cumulative free -m<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#Linux Logging \/var\/log\/messages \/var\/log\/syslog \/var\/log\/kernlog for num in `seq 1 1 10`; do free -m; sleep 10; done free -m ################################################################################## total used free shared buffers cached Mem: 28203 20010 8193 683 156 3850 -\/+ buffers\/cache: 16002 12200 Swap: 8159 &hellip; <a href=\"https:\/\/dbafox.com\/?page_id=579\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"class_list":["post-579","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux - Useful Commands - dbafox<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dbafox.com\/?page_id=579\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux - Useful Commands - dbafox\" \/>\n<meta property=\"og:description\" content=\"#Linux Logging \/var\/log\/messages \/var\/log\/syslog \/var\/log\/kernlog for num in `seq 1 1 10`; do free -m; sleep 10; done free -m ################################################################################## total used free shared buffers cached Mem: 28203 20010 8193 683 156 3850 -\/+ buffers\/cache: 16002 12200 Swap: 8159 &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dbafox.com\/?page_id=579\" \/>\n<meta property=\"og:site_name\" content=\"dbafox\" \/>\n<meta property=\"article:modified_time\" content=\"2017-08-17T11:35:21+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dbafox.com\/?page_id=579\",\"url\":\"https:\/\/dbafox.com\/?page_id=579\",\"name\":\"Linux - Useful Commands - dbafox\",\"isPartOf\":{\"@id\":\"https:\/\/dbafox.com\/#website\"},\"datePublished\":\"2016-01-08T09:33:10+00:00\",\"dateModified\":\"2017-08-17T11:35:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/dbafox.com\/?page_id=579#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dbafox.com\/?page_id=579\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dbafox.com\/?page_id=579#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dbafox.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux &#8211; Useful Commands\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dbafox.com\/#website\",\"url\":\"https:\/\/dbafox.com\/\",\"name\":\"dbafox\",\"description\":\"DBA Technical Information\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dbafox.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linux - Useful Commands - dbafox","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dbafox.com\/?page_id=579","og_locale":"en_GB","og_type":"article","og_title":"Linux - Useful Commands - dbafox","og_description":"#Linux Logging \/var\/log\/messages \/var\/log\/syslog \/var\/log\/kernlog for num in `seq 1 1 10`; do free -m; sleep 10; done free -m ################################################################################## total used free shared buffers cached Mem: 28203 20010 8193 683 156 3850 -\/+ buffers\/cache: 16002 12200 Swap: 8159 &hellip; Continue reading &rarr;","og_url":"https:\/\/dbafox.com\/?page_id=579","og_site_name":"dbafox","article_modified_time":"2017-08-17T11:35:21+00:00","twitter_misc":{"Estimated reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dbafox.com\/?page_id=579","url":"https:\/\/dbafox.com\/?page_id=579","name":"Linux - Useful Commands - dbafox","isPartOf":{"@id":"https:\/\/dbafox.com\/#website"},"datePublished":"2016-01-08T09:33:10+00:00","dateModified":"2017-08-17T11:35:21+00:00","breadcrumb":{"@id":"https:\/\/dbafox.com\/?page_id=579#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dbafox.com\/?page_id=579"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/dbafox.com\/?page_id=579#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dbafox.com\/"},{"@type":"ListItem","position":2,"name":"Linux &#8211; Useful Commands"}]},{"@type":"WebSite","@id":"https:\/\/dbafox.com\/#website","url":"https:\/\/dbafox.com\/","name":"dbafox","description":"DBA Technical Information","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dbafox.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"}]}},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/P3ecMb-9l","_links":{"self":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/pages\/579","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dbafox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=579"}],"version-history":[{"count":6,"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/pages\/579\/revisions"}],"predecessor-version":[{"id":868,"href":"https:\/\/dbafox.com\/index.php?rest_route=\/wp\/v2\/pages\/579\/revisions\/868"}],"wp:attachment":[{"href":"https:\/\/dbafox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}