{"id":747,"date":"2018-06-22T10:16:21","date_gmt":"2018-06-22T09:16:21","guid":{"rendered":"https:\/\/blogs.ncl.ac.uk\/igmit\/?p=747"},"modified":"2024-07-06T21:55:58","modified_gmt":"2024-07-06T20:55:58","slug":"linux-handy-one-liners","status":"publish","type":"post","link":"https:\/\/blogs.ncl.ac.uk\/igmit\/?p=747","title":{"rendered":"linux handy one liners"},"content":{"rendered":"<p>Anything that doesn&#8217;t warrant a War &amp; Peace explanation goes in here&#8230;<\/p>\n<p>The command and a brief what it does and why would you want to.<\/p>\n<p>First up querying what a package brings to the party &#8211; excess baggage that may require further exploration&#8230;<\/p>\n<h5>repoquery<\/h5>\n<pre>repoquery --requires --resolve<\/pre>\n<p>Good for rpmfusion or other repo&#8217;s that may add in things that change base packages. It does require that the repo is in the yum configuration for it to query. The yum settings can be switched on and off so that future yum updates wont check that particular repo and install things without your knowledge. This requires that yum-utils is installed.<\/p>\n<h5>yum-config-manager<\/h5>\n<p>The &#8211;enablerepo option overides the permanent option set in the .repo file for only the current command. &#8211;disablerepo does the opposite for enabled repos.<\/p>\n<p>If you install (or have installed) the yum-utils package then you can use yum-config-manager to permanently enable\/disable repos without editing the file:<\/p>\n<pre>yum-config-manager --enable remi<\/pre>\n<p>will permanently enable the remi repo.<\/p>\n<h5>yum repolist all<\/h5>\n<p>will list all the repo id which you use with the &#8211;enable or &#8211;disable option.<\/p>\n<h5>one-off install from disabled repositories<\/h5>\n<p>By default yum installs only from the enabled repositories. For some reason if you like to install a package from a disabled repositories, use \u2013enablerepo option in the \u2018yum install\u2019 as shown below.<\/p>\n<pre>yum --enablerepo=fedora-source install vim-X11.x86_64<\/pre>\n<h5>RedHat Centos 7 firewall quickies<\/h5>\n<pre>firewall-cmd --get-active-zones - Shows which zones you have and which interfaces\r\n\r\nfirewall-cmd --zone=public --add-port=2049\/tcp --permanent - Adds nfs4 port 2049 to the firewall permanently\r\n\r\nfirewall-cmd --reload - Reload the firewall for the changes to take effect<\/pre>\n<pre>firewall-cmd --zone=public --list-all - shows all the current rules, interfaces, ports etc<\/pre>\n<pre>firewall-cmd --permanent --zone=public --add-port=80\/tcp - add a port permanently web and tcp in this instance<\/pre>\n<pre>firewall-cmd --zone=public --remove-port=80\/tcp - remove a port 'The firewall giveth and the firewall taketh away!'<\/pre>\n<pre>firewall-cmd --panic-on - exactly as advertised, shuts up shop<\/pre>\n<pre>firewall-cmd --query-panic - what state is panic in? on or off<\/pre>\n<pre>firewall-cmd --panic-off - open for business again<\/pre>\n<p>&nbsp;<\/p>\n<h5>RedHat Centos 7 services quickies<\/h5>\n<pre>systemctl start name.service - Starts a service\r\nsystemctl stop name.service - Stops a service\r\nsystemctl restart name.service - Restarts a service\r\nsystemctl reload name.service - Reloads configuration\r\nsystemctl status name.service - Checks if a service is running\r\nsystemctl is-active name.service - Checks if a service is running\r\nsystemctl list-units --type service --all - Displays the status of all services\r\n\r\nsystemctl enable name.service - Enables a service.\r\nsystemctl disable name.service - Disables a service.\r\nsystemctl status name.service - Checks if a service is enabled.\r\nsystemctl is-enabled name.service - Checks if a service is enabled.\r\nsystemctl list-unit-files --type service - Lists all services and checks if they are enabled.\r\nsystemctl list-dependencies --after - Lists services that are ordered to start before the specified unit.\r\nchkconfig --list systemctl list-dependencies --before - Lists services that are ordered to start after\r\n\r\n<\/pre>\n<h5>RedHat Centos 7 xrdp<\/h5>\n<pre>yum install epel-release\r\nyum install xrdp\r\nsystemctl enable xrdp.service\r\nsystemctl start xrdp.service\r\nfirewall-cmd --zone=public --add-port=3389\/tcp --permanent\r\nfirewall-cmd --reload\r\nrestorecon -v \/usr\/sbin\/xrdp\r\nrestorecon -v \/usr\/sbin\/xrdp-sesman\r\nreboot\r\n\r\n<\/pre>\n<h5>Screen command<\/h5>\n<pre>Delete a rogue\u00a0screen session\r\nscreen -ls\r\nscreen -S &lt;pid&gt; -p 0 -X quit<\/pre>\n<h5><strong>rpm install by date query<\/strong><\/h5>\n<p><code>rpm -qa --queryformat '%{installtime} (%{installtime:date}) %{name}\\n' | sort -n | tail -5<br \/>\n<\/code><\/p>\n<p>miss off the tail to get a complete list \ud83d\ude42<\/p>\n<h5>samba firewall<\/h5>\n<p>firewall-cmd &#8211;permanent &#8211;add-port=137\/tcp<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-port=138\/tcp<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-port=139\/tcp<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-port=445\/tcp<br \/>\nfirewall-cmd &#8211;permanent &#8211;add-port=901\/tcp<\/p>\n<p>firewall-cmd &#8211;reload<\/p>\n<h5>Man page to nicely formatted PDF<\/h5>\n<p>For when you absolutely have to have a nicely printed Man page to scribble all over at the machine in question..<\/p>\n<pre>man -t &lt;man page you want in here&gt; | ps2pdf - man-page-name.pdf<\/pre>\n<p>&nbsp;<\/p>\n<h5>List disk usage\/folder sizes in order<\/h5>\n<pre>du -xh * | sort -rn | head -20<\/pre>\n<h5>fsck check<\/h5>\n<p>The dreaded &#8216;non shall pass&#8217; when a system hasn&#8217;t been shutdown correctly or a drive is failing.<\/p>\n<p>Run fsck without -a or -P<\/p>\n<p>Look at the file system it is complaining about &#8211; probably one that is in device-mapper and write down the path. Then: &#8211;<\/p>\n<p>fsck \/dev\/mapper\/device\/in\/the\/warning\/message<\/p>\n<p>and follow the prompts as they come up on the screen to repair the affected system.<\/p>\n<p><strong>run process as other user to see &#8216;their&#8217; issues<\/strong><\/p>\n<p>as root: &#8211;<br \/>\nsu &lt;uid&gt;<\/p>\n<h4>ls and see different date format<\/h4>\n<p>ls -l &#8211;time-style=full-iso<\/p>\n\n\n<p><strong>Find your external I.P address<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl ifconfig.me<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Anything that doesn&#8217;t warrant a War &amp; Peace explanation goes in here&#8230; The command and a brief what it does and why would you want to. First up querying what a package brings to the party &#8211; excess baggage that may require further exploration&#8230; repoquery repoquery &#8211;requires &#8211;resolve Good for rpmfusion or other repo&#8217;s that <a href='https:\/\/blogs.ncl.ac.uk\/igmit\/?p=747' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":4848,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-747","post","type-post","status-publish","format-standard","hentry","category-uncategorized","category-1-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/blogs.ncl.ac.uk\/igmit\/index.php?rest_route=\/wp\/v2\/posts\/747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ncl.ac.uk\/igmit\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ncl.ac.uk\/igmit\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ncl.ac.uk\/igmit\/index.php?rest_route=\/wp\/v2\/users\/4848"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ncl.ac.uk\/igmit\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=747"}],"version-history":[{"count":18,"href":"https:\/\/blogs.ncl.ac.uk\/igmit\/index.php?rest_route=\/wp\/v2\/posts\/747\/revisions"}],"predecessor-version":[{"id":1763,"href":"https:\/\/blogs.ncl.ac.uk\/igmit\/index.php?rest_route=\/wp\/v2\/posts\/747\/revisions\/1763"}],"wp:attachment":[{"href":"https:\/\/blogs.ncl.ac.uk\/igmit\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ncl.ac.uk\/igmit\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ncl.ac.uk\/igmit\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}