Difference between pages "Powershell" and "Miscellaneous Linux Commands"

From TheBestLinux.com
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
 +
= <h3>Shell Commands</h3> =
 +
<br />
 +
Display all network interface names on any Linux system from the shell:
 +
<pre style="color:blue">/sbin/ifconfig | grep BROADCAST | cut -d " " -f1 | sed 's/.$//' </pre>
 +
<br />
 +
Most Linux machines will only display one network interface, such as shown on my Slackware 14.1 Virtual Machine Server:
 +
<pre style="color:blue">eth0 </pre>
 +
<br />
 +
Other systems may have more than one, such as those with virtual machine software or with more than one physical [http://en.wikipedia.org/wiki/Network_interface_controller NIC].
 +
<br />
 +
Also, some systems use non-standared network interface names, other than the usual eth0.
 +
<br /><br />
 +
Here are some samples of those types of systems.  In these examples, the first network interface name is the main one used, and the following ones are used for the virtual machine software.
 +
<br /><br />
 +
Sample output from my Fedora 20 (Heisenbug) VirtualBox server:
 +
<pre style="color:blue">em1
 +
virbr0</pre>
 +
<br />
 +
And here is a sample output from my Fedora 17 (Beefy Miracle) laptop running VMWare:
 +
<pre style="color:blue">p5p1                                                                         
 +
vmnet1                                                                       
 +
vmnet8</pre>
 +
<br />
 +
<br />
 +
== <h3>The "ps" Process Command Syntax</h3> ==
 +
To show all executing processes:
 +
<pre style="color:blue">$ ps ax</pre>
 +
<br />
 +
To show all processed running by a specific user(This example shows all processes running by the Apache WebServer):
 +
<pre style="color:blue">$ ps -U apache</pre>
 +
<br />
 +
<br />
  
== Windows PowerShell Information ==
+
== <h3>How to find the 10 largest files in the current directory</h3> ==
[http://www.dawgland.com/Enable_PowerShell/ Enabling PowerShell Script Execution]
+
<pre style="color:blue">
 +
ls -XS | head -n 10
 +
</pre>
 +
<br />
 +
<br />
 +
OR
 +
<br /><br />
 +
<pre style="color:blue">
 +
du -a /directory_name | sort -n -r | head -n 10
 +
</pre>
 +
<br /><br />
 +
Many other examples with more advanced options can be found at this URL:<br />
 +
https://www.tutorialspoint.com/find-the-largest-top-10-files-and-directories-on-a-linux
 
<br /><br />
 
<br /><br />
  
 +
== <h3>How to grep from files that have been compressed with Gzip using zgrep</h3> ==
 +
Unix and Linux systems come with a modified version of grep named zgrep. The Linux zgrep command works just like the grep command, except it works on text files that have been compressed with gzip.
 +
<br /><br />
 +
The zgrep command does not support recursive usage, however, the following command line string does allow you to zgrep recursively through multiple directory levels:
 +
<pre style="color:blue">
 +
find . -name *.gz -exec zgrep -- string_searching_for {} +
 +
</pre>
 +
<br />
 +
<br />
  
=== Miscellaneous PowerShell Commands ===
+
== <h3>Change Time Zone of Linux Server from Command Line</h3> ==
Here are some of the PowerShell commands I use regularily to to manage Windows machines:
+
To manually and permanently change the time zone of a Linux system, it's a very simple matter of copying the time zone file you want over the localtime file of the system, as follows(Using U.S. Pacific Standard Time):
 +
<br />
 +
MUST be done as root user!  System must be rebooted for changes to take effect!
 +
<br />
 
<pre style="color:blue">
 
<pre style="color:blue">
Create NEW Active Directory Domain Controller/AD DS:
+
[root@server ~]# cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime 
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
 
Install-ADDSForest -DomainName thebestlinux.net -DomainNetbiosName THEBESTLINUX -InstallDNS
 
OTHER COMMANDS:
 
Disable IPv6 on ALL NIC’s:
 
Disable-NetAdapterBinding -Name Ethernet* -ComponentID ms_tcpip6
 
Get-NetTCPConnection
 
Get-NetConnectionProfile
 
Get-NetAdapter
 
Set-DnsClientServerAddress -InterfaceIndex 3 -ServerAddresses ("192.168.200.103","192.168.200.121","75.75.76.76")
 
Install-Module PSWindowsUpdate
 
Set-PSRepository
 
Add-WUServiceManager -MicrosoftUpdate
 
Get-WindowsUpdate
 
Get-Service | findstr Admin
 
sc queryex type=service state=all
 
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -AutoSize
 
Get-WindowsFeature
 
Get-package | Select-Object Name,Version
 
Get-WindowsUpdate -v
 
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -AutoSize
 
New-ADUser /?
 
get-localuser
 
get-roles
 
Get-DnsServerResourceRecord dawgland.com
 
Get-DnsServerQueryResolutionPolicy
 
dcdiag /a
 
CONFIRM ALL 5 Roles of Active Directory Servers are up and running!!!:
 
Get-ADDomain dawgland.com | Format-Table PDCEmulator,RIDMaster,InfrastructureMaster
 
Get-ADForest dawgland.com | Format-Table SchemaMaster,DomainNamingMaster
 
Get-DnsServerResourceRecord -ZoneName dawgland.com
 
Get-NetConnectionProfile
 
Get-NetTCPConnection
 
Get-CimInstance -Class CIM_LogicalDisk
 
Get-DiskFreeSpace
 
Get-GPRegistryValue -Key HKEY_LOCAL_MACHINE
 
Get-GPRegistryValue -Guid 31b2f340-016d-11d2-945f-00c04fb984f9 -Key HKEY_LOCAL_MACHINE
 
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
 
Import-Module GroupPolicy -verbose
 
 
 
 
</pre>
 
</pre>
 +
<br /><br />
  
 +
== <h3>Customizing Your Shell & Environment</h3>==
 +
Most people use the default Linux shell Bash, the Bourne Again SHell, which is basically the Bourne shell with lots of cool add-ons and extra features, such as command completion.  There are two main configuration files for your shell, and they are "hidden" files, starting with a dot, so they aren't shown during a normal directory listing unless specified.
 +
The configuration files are .bashrc and .bash_profile
 +
The .bashrc file contains aliases, which are custom commands used often.  For instance, I like having an alias called "cls" to run the shell "clear" command to clear the contents of the currently visible screen.
 +
More bash shell configuration info to come when I have the time.
  
=== More PowerShell Commands with Some Examples ===
+
== <h3>Convert Computer Epoch Date & Time Codes to Human Readable Dates & Times</h3> ==
Here are some more commands I use when working on headless Windows Server hardware and virual machines, such as
+
From the Linux command line shell:
 
+
<pre style="color:blue">
Windows Server Core:
+
date -d @1449129600
 +
</pre>
 +
<br />
 +
Gives the output of:
 +
<pre style="color:blue">
 +
Thu Dec  3 00:00:00 PST 2015
 +
</pre>
 +
<br /><br />
 +
Using perl:
 +
<pre style="color:blue">
 +
perl -le 'print scalar localtime $ARGV[0]' 1449129600
 +
</pre>
 +
<br />
 +
Gives the output of:
 +
<pre style="color:blue">
 +
Thu Dec  3 00:00:00 2015
 +
</pre>
 +
<br /><br />
 +
== <h3>Display the Full Calendars of the Last 20 Years with a One-Liner Command!</h3> ==
 +
For example, say it is the year 2015, and you want to display all of the full calendars for the last 20 years, you can you this one line command to spit it out to the terminal console, or redirect it into a text file for later use.
 +
<br /><br />
 +
This is how to do it with what is  known as a "One-Liner" command, which is actually a set of commands strung together on one line:
 
<pre style="color:blue">
 
<pre style="color:blue">
 +
$ for ((year=1996;year<=2015;year++)); do cal $year; done
 +
</pre>
 +
<br />
 +
This simple example can be applied to thousands of scenarios where you want to iterate through some data a specific number of times, or until a specific target is reached.  Use your imagination to apply this to any repetitive command line tools you use!
 +
<br /><br />
  
Open a Windows command prompt as Administrator:
+
== <h3>E-Mail Info</h3> ==
runas /user:administrator CMD.exe
+
To redirect email sent to an alias address to another email address on the Linux email server, edit the /etc/aliases file, and then be sure to '''IMMEDIATELY''' run the <b>newaliases</b> command to rebuild the actual database the MTA uses!
 +
<br /><br />
  
Install Failover Cluster Tools:
+
== <h3>Miscellaneous CD/DVD & USB Command Line Commands</h3> ==
Install-WindowsFeature -Name Failover-Clustering –IncludeManagementTools
+
To show all mounted drives, both the "mount" and "df" commands are useful and helful, as seen here(Example using one of my servers):
Include command line management tools:
+
<pre style="color:blue">$ mount
Install-WindowsFeature RSAT-Clustering-CmdInterface
+
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
 +
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
 +
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=8104892k,nr_inodes=2026223,mode=755)
 +
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
 +
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
 +
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
 +
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
 +
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,seclabel,mode=755)
 +
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
 +
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
 +
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
 +
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
 +
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
 +
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
 +
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
 +
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
 +
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
 +
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
 +
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
 +
/dev/mapper/fedora-root on / type ext4 (rw,relatime,seclabel,data=ordered)
 +
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
 +
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=41,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
 +
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
 +
tmpfs on /tmp type tmpfs (rw,seclabel)
 +
configfs on /sys/kernel/config type configfs (rw,relatime)
 +
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
 +
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
 +
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
 +
sunrpc on /proc/fs/nfsd type nfsd (rw,relatime)
 +
/dev/md126p1 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
 +
/dev/mapper/data-home on /home type ext4 (rw,relatime,seclabel,data=ordered)
 +
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
 +
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
 +
</pre>
 +
<br />
 +
Output of the "df" command on one of my servers:
 +
(I added the -h switch to show sizes in "Human Readable" format, meaning it shows an M or G for Megabytes & Gigabytes)
 +
<pre style="color:blue">
 +
$ df -h
 +
Filesystem                    Size  Used Avail Use% Mounted on
 +
/dev/mapper/fedora-root        58G  47G  8.0G  86% /
 +
devtmpfs                      7.8G    0  7.8G  0% /dev
 +
tmpfs                        7.8G  88M  7.7G  2% /dev/shm
 +
tmpfs                        7.8G  1.2M  7.8G  1% /run
 +
tmpfs                        7.8G    0  7.8G  0% /sys/fs/cgroup
 +
tmpfs                        7.8G  92M  7.7G  2% /tmp
 +
/dev/mapper/extra-extra1      197G  93G  95G  50% /mnt/extra1
 +
/dev/mapper/more-morespace1  586G  371G  186G  67% /mnt/more1
 +
/dev/md126p1                  969M  116M  787M  13% /boot
 +
/dev/mapper/fedora-save      197G  60M  187G  1% /mnt/save
 +
/dev/mapper/data-vms2        296G  180G  102G  64% /mnt/vms2
 +
/dev/mapper/backup-vms        197G  184G  3.7G  99% /mnt/vms
 +
/dev/mapper/archive-archive1  501G  399G  77G  84% /mnt/archive
 +
/dev/mapper/data-data1        99G  79G  15G  84% /mnt/data1
 +
/dev/mapper/data-home        197G  172G  16G  92% /home
 +
</pre>
 +
<br /><br />
 +
== <h2>'''***** VERY IMPORTANT INFO!!! *****'''</h2> ==
 +
In order to "SAFELY" remove a CD, DVD, USB, Removable Hard Drive, or any type of removable media or drive,
 +
YOU MUST FIRST UNMOUNT the removable media or drive, and also possibly detatch and/or eject the media or drive.
 +
Here are the command line commands to perform these functions:
 +
<br />
 +
The first step applies to all situations and types of drives or medium, which is to "UNMOUNT" the drive, using the "umount" command.
 +
NOTICE the "N" is dropped in the actual unmount command, so "umount" is NOT a typo!
  
Find out if package is installed. This example uses GIT:
+
For example, here is how to unount a mounted CD ROM disk inserted into the drive.
PS C:\Users\Administrator> Get-Package | Select-Object Name | findstr -i git
+
Also, instead of pushing the little push button on the front of CD & DVD drives, I prefer to use command line commands to both open and close the
Git
+
drive tray, if it is the type that has a tray that opens/ejects to insert a disk.
  
Find out if package is installed.  This exampled uses WAC(Windows Admin Center):
+
To open and close the CD/DVD drive tray, use the eject command as follows:
PS C:\Users\Administrator> get-package | select-object Name | findstr -i Admin
+
<pre style="color:blue">$ eject</pre>
Windows Admin Center
+
This should open the disk tray.  If you have more than one CD/DVD ROM drive, you need to specify the device name of the unit you want to use,
 +
as shown here:
 +
<pre style="color:blue">$ eject /dev/sdb </pre>
 +
or
 +
<pre style="color:blue">$ eject /dev/sdc </pre>
 +
<br />
 +
The actual device name depends on how it is installed in your computerTo get an idea of the actual device name your computer uses for it's
 +
CD/DVD ROM drives, I like to use the "dmesg" command, as show here:
 +
<pre style="color:blue">$ dmesg | grep -i cd-rom
 +
[    0.666858] scsi 4:0:0:0: CD-ROM            ASUS    DRW-24F1ST  a  1.00 PQ: 0 ANSI: 5
 +
[    0.670145] cdrom: Uniform CD-ROM driver Revision: 3.20
 +
[    0.670287] sr 4:0:0:0: Attached scsi CD-ROM sr0
 +
</pre>
 +
<br />
 +
As you can see from above, the CD/DVD ROM burner I have is an Asus DRW-24F1ST, attached to scsi CD-ROM device "sr0".
 +
<br />
 +
This is the important device name: sr0 which you can then use to eject/open and close the CD-ROM drive tray.
 +
<br />FYI, "sr0" stands for "SCSI Recorder 0", in case you were wondering...
  
Another way to do same as above, but more “Precise”.  Can USE WILD-CARDS!!!:
+
So, the actual working example on my server to open/eject the tray is:
PS C:\Users\Administrator> get-package | Where-Object {$_.Name -like "*Windows Admin Center*"}
+
<pre style="color:blue">$ eject /dev/sr0 </pre>
 
+
<br />
Name                          Version          Source                          ProviderName
+
The actual working command to close the CD-ROM tray after I've inserted a disk into the tray on my server is:
----                          -------          ------                          ------------
+
<pre style="color:blue">$ eject -t /dev/sr0 </pre>
Windows Admin Center          1.3.53858.0      C:\Program Files\Windows Admi... msi
+
<br /><br />
 
 
 
 
Display ALL services installed and their status:
 
Get-Service | Select-Object Name,Status,DisplayName
 
 
 
Check Status of Windows Admin Center(IF Installed – Otherwise will not find it!
 
Get-Service | Select-Object Name,Status,DisplayName | findstr Admin
 
FINDS:
 
“ServerManagementGateway”, the ACTUAL name of WAC!
 
ServerManagementGateway                  Running Windows Admin Center Service
 
ServerManagementGatewayAccount          Stopped Windows Admin Center Account Service
 
 
 
Configure DNS Servers:
 
Set-DnsClientServerAddress -InterfaceIndex 3 -ServerAddresses ("192.168.200.103","192.168.200.121","75.75.76.76")
 
 
 
Disable ALL Firewall Zones:
 
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
 
 
 
Enable a port through firewall:
 
netsh advfirewall firewall add rule name="WinRM-HTTP" dir=in localport=5985 protocol=TCP action=allow
 
 
 
Check if Windows Admin Center has been installed:
 
Get-WmiObject -Class win32_service | Where-Object {$_.name -like "WinRM"}
 
 
 
Download a file using PowerShell:
 
$WebClient = New-Object System.Net.WebClient
 
$WebClient.DownloadFile("http://192.168.200.125/WindowsAdminCenter2110.2.msi","C:\Users\Administrator\WindowsAdminCenter2110.2.msi")
 
 
 
Check EvenLogs for logins, failures, apps, etc:
 
get-eventlog -list
 
get-eventlog Application -after (get-date).addhours(-1)
 
get-eventlog Application -after (get-date).addhours(-8)
 
 
 
USE Security log for checking logins:
 
get-eventlog Security -after (get-date).addhours(-1)
 
 
 
FORMATTING Example of explicit log index number:
 
Get-EventLog Security | where index -eq 3704 | format-list *
 
 
 
DOWNLOAD & Install MS SQL Server:
 
$wc=new-object system.net.webclient
 
$wc.downloadfile("https://go.microsoft.com/fwlink/?linkid=866662","SQL2019-SSEI-Dev.exe")
 
 
 
GIT Download:
 
$wc.downloadfile("https://github.com/git-for-windows/git/releases/download/v2.36.0.windows.1/Git-2.36.0-64-bit.exe","Git-2.36.0-64-bit.exe")
 
 
 
Get-Service -Name vds
 
get-service | Where-Object {$_.status -eq "stopped"}
 
get-service -name wisvc
 
 
 
PS C:\Users\Administrator> get-service | grep -i admin
 
Stopped  sacsvr            Special Administration Console Helper
 
Running  ServerManagemen... Windows Admin Center Service
 
Stopped  ServerManagemen... Windows Admin Center Account Service
 
PS C:\Users\Administrator>
 
 
 
Get-Item WSMan:\localhost\Client\TrustedHosts
 
 
 
Get-CimInstance -Class CIM_LogicalDisk
 
 
 
DeviceID DriveType ProviderName VolumeName Size        FreeSpace
 
-------- --------- ------------ ---------- ----        ---------
 
C:      3                                53109321728 44553736192
 
D:      5
 
 
 
 
 
Get-NetTCPConnection
 
 
 
LocalAddress                        LocalPort RemoteAddress                      RemotePort State      AppliedSetting
 
------------                        --------- -------------                      ---------- -----      --------------
 
::                                  56357    ::                                  0          Bound
 
::                                  56268    ::                                  0          Bound
 
::                                  54693    ::                                  0          Bound
 
::                                  54690    ::                                  0          Bound
 
::                                  54689    ::                                  0          Bound
 
::                                  54688    ::                                  0          Bound
 
::                                  54687    ::                                  0          Bound
 
::                                  54671    ::                                  0          Bound
 
::                                  54667    ::                                  0          Bound
 
::                                  54665    ::                                  0          Bound
 
::                                  54663    ::                                  0          Bound
 
::                                  49712    ::                                  0          Bound
 
::                                  49706    ::                                  0          Bound
 
::                                  49695    ::                                  0          Bound
 
::                                  49680    ::                                  0          Bound
 
::                                  49679    ::                                  0          Bound
 
::1                                56357    ::1                                49666      Established Datacenter
 
fe80::b586:d0e3:8c2b:2229%5        56268    fe80::b586:d0e3:8c2b:2229%5        49666      Established Datacenter
 
fe80::b586:d0e3:8c2b:2229%5        54815    fe80::b586:d0e3:8c2b:2229%5        135        TimeWait
 
fe80::b586:d0e3:8c2b:2229%5        54671    fe80::b586:d0e3:8c2b:2229%5        389        Established Datacenter
 
fe80::b586:d0e3:8c2b:2229%5        54667    fe80::b586:d0e3:8c2b:2229%5        389        Established Datacenter
 
::1                                54665    ::1                                389        Established Datacenter
 
fe80::b586:d0e3:8c2b:2229%5        54663    fe80::b586:d0e3:8c2b:2229%5        389        Established Datacenter
 
::                                  49715    ::                                  0          Listen
 
fe80::b586:d0e3:8c2b:2229%5        49712    fe80::b586:d0e3:8c2b:2229%5        49666      Established Datacenter
 
fe80::b586:d0e3:8c2b:2229%5        49695    fe80::b586:d0e3:8c2b:2229%5        49666      Established Datacenter
 
::                                  49692    ::                                  0          Listen
 
::                                  49686    ::                                  0          Listen
 
::1                                49680    ::1                                389        Established Internet
 
::1                                49679    ::1                                389        Established Datacenter
 
::                                  49676    ::                                  0          Listen
 
::                                  49675    ::                                  0          Listen
 
::                                  49668    ::                                  0          Listen
 
fe80::b586:d0e3:8c2b:2229%5        49666    fe80::b586:d0e3:8c2b:2229%5        56268      Established Datacenter
 
fe80::b586:d0e3:8c2b:2229%5        49666    fe80::b586:d0e3:8c2b:2229%5        49712      Established Datacenter
 
fe80::b586:d0e3:8c2b:2229%5        49666    fe80::b586:d0e3:8c2b:2229%5        49695      Established Datacenter
 
::1                                49666    ::1                                56357      Established Datacenter
 
::                                  49666    ::                                  0          Listen
 
::                                  49665    ::                                  0          Listen
 
::                                  49664    ::                                  0          Listen
 
::                                  47001    ::                                  0          Listen
 
::                                  9389      ::                                  0          Listen
 
::                                  5985      ::                                  0          Listen
 
::                                  3389      ::                                  0          Listen
 
::                                  3269      ::                                  0          Listen
 
::                                  3268      ::                                  0          Listen
 
::                                  636      ::                                  0          Listen
 
::                                  593      ::                                  0          Listen
 
::                                  464      ::                                  0          Listen
 
::                                  445      ::                                  0          Listen
 
fe80::b586:d0e3:8c2b:2229%5        389      fe80::b586:d0e3:8c2b:2229%5        54671      Established Datacenter
 
fe80::b586:d0e3:8c2b:2229%5        389      fe80::b586:d0e3:8c2b:2229%5        54667      Established Datacenter
 
fe80::b586:d0e3:8c2b:2229%5        389      fe80::b586:d0e3:8c2b:2229%5        54663      Established Datacenter
 
::1                                389      ::1                                54665      Established Datacenter
 
::1                                389      ::1                                49680      Established Datacenter
 
::1                                389      ::1                                49679      Established Datacenter
 
::                                  389      ::                                  0          Listen
 
::                                  135      ::                                  0          Listen
 
::                                  88        ::                                  0          Listen
 
fe80::b586:d0e3:8c2b:2229%5        53        ::                                  0          Listen
 
::1                                53        ::                                  0          Listen
 
0.0.0.0                            49715    0.0.0.0                            0          Listen
 
0.0.0.0                            49692    0.0.0.0                            0          Listen
 
0.0.0.0                            49686    0.0.0.0                            0          Listen
 
0.0.0.0                            49676    0.0.0.0                            0          Listen
 
0.0.0.0                            49675    0.0.0.0                            0          Listen
 
0.0.0.0                            49668    0.0.0.0                            0          Listen
 
192.168.200.129                    49666    192.168.200.216                    60179      Established Datacenter
 
0.0.0.0                            49666    0.0.0.0                            0          Listen
 
0.0.0.0                            49665    0.0.0.0                            0          Listen
 
0.0.0.0                            49664    0.0.0.0                            0          Listen
 
0.0.0.0                            9389      0.0.0.0                            0          Listen
 
192.168.200.121                    3389      192.168.200.223                    64821      Established Datacenter
 
0.0.0.0                            3389      0.0.0.0                            0          Listen
 
0.0.0.0                            3269      0.0.0.0                            0          Listen
 
0.0.0.0                            3268      0.0.0.0                            0          Listen
 
0.0.0.0                            636      0.0.0.0                            0          Listen
 
0.0.0.0                            593      0.0.0.0                            0          Listen
 
0.0.0.0                            389      0.0.0.0                            0          Listen
 
192.168.200.121                    139      0.0.0.0                            0          Listen
 
0.0.0.0                            135      0.0.0.0                            0          Listen
 
192.168.200.129                    53        0.0.0.0                            0          Listen
 
192.168.200.121                    53        0.0.0.0                            0          Listen
 
127.0.0.1                          53        0.0.0.0                            0          Listen
 
 
 
 
 
Get-NetConnectionProfile:
 
Name            : Unidentified network
 
InterfaceAlias  : Ethernet
 
InterfaceIndex  : 5
 
NetworkCategory  : Public
 
IPv4Connectivity : NoTraffic
 
IPv6Connectivity : NoTraffic
 
 
 
 
 
Get-DnsServerResourceRecord -ZoneName dawgland.com
 
 
 
HostName                  RecordType Type      Timestamp            TimeToLive      RecordData
 
--------                  ---------- ----      ---------            ----------      ----------
 
@                        A          1          2/21/2022 4:00:00 PM 00:10:00        192.168.200.129
 
@                        A          1          2/21/2022 4:00:00 PM 00:10:00        192.168.200.121
 
@                        NS        2          0                    01:00:00        win19vm10.dawgland.com.
 
@                        SOA        6          0                    01:00:00        [33][win19vm10.dawgland.com.][h...
 
_msdcs                    NS        2          0                    01:00:00        win19vm10.dawgland.com.
 
_gc._tcp.Default-First... SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][3268][win19vm10.dawgla...
 
_kerberos._tcp.Default... SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][88][win19vm10.dawgland...
 
_ldap._tcp.Default-Fir... SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][389][win19vm10.dawglan...
 
_gc._tcp                  SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][3268][win19vm10.dawgla...
 
_kerberos._tcp            SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][88][win19vm10.dawgland...
 
_kpasswd._tcp            SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][464][win19vm10.dawglan...
 
_ldap._tcp                SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][389][win19vm10.dawglan...
 
_kerberos._udp            SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][88][win19vm10.dawgland...
 
_kpasswd._udp            SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][464][win19vm10.dawglan...
 
DomainDnsZones            A          1          2/21/2022 4:00:00 PM 00:10:00        192.168.200.121
 
DomainDnsZones            A          1          2/21/2022 4:00:00 PM 00:10:00        192.168.200.129
 
_ldap._tcp.Default-Fir... SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][389][win19vm10.dawglan...
 
_ldap._tcp.DomainDnsZones SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][389][win19vm10.dawglan...
 
ForestDnsZones            A          1          2/21/2022 4:00:00 PM 00:10:00        192.168.200.121
 
ForestDnsZones            A          1          2/21/2022 4:00:00 PM 00:10:00        192.168.200.129
 
_ldap._tcp.Default-Fir... SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][389][win19vm10.dawglan...
 
_ldap._tcp.ForestDnsZones SRV        33        2/21/2022 4:00:00 PM 00:10:00        [0][100][389][win19vm10.dawglan...
 
win10vm8                  A          1          2/21/2022 9:00:00 PM 00:20:00        192.168.200.216
 
win19vm10                A          1          0                    01:00:00        192.168.200.121
 
win19vm10                A          1          0                    01:00:00        192.168.200.129
 
  
 +
== <h4>USB Devices</h4> ==
 +
<br />
 +
To determine which device your USB thumb drive is connected to, use the "dmesg" command again, as follows:
 +
<pre style="color:blue">
 +
# dmesg | grep -i 'Attached SCSI'
 +
</pre>
 +
<br /><br />
 +
To manually check & fix a USB file system, use this example(As the root super user):
 +
<pre style="color:blue">
 +
# fsck.fat -atvV /dev/sde1
 +
fsck.fat 3.0.25 (2014-01-17)
 +
fsck.fat 3.0.25 (2014-01-17)
 +
Checking we can access the last sector of the filesystem
 +
0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
 +
Automatically removing dirty bit.
 +
Boot sector contents:
 +
System ID "MSDOS5.0"
 +
Media byte 0xf8 (hard disk)
 +
      512 bytes per logical sector
 +
    16384 bytes per cluster
 +
    10144 reserved sectors
 +
First FAT starts at byte 5193728 (sector 10144)
 +
        2 FATs, 32 bit entries
 +
  3784704 bytes per FAT (= 7392 sectors)
 +
Root directory start at cluster 2 (arbitrary size)
 +
Data area starts at byte 12763136 (sector 24928)
 +
    945313 data clusters (15488008192 bytes)
 +
63 sectors/track, 128 heads
 +
      8064 hidden sectors
 +
  30274944 sectors total
 +
Starting check/repair pass.
 +
Checking for bad clusters.
 +
Reclaiming unconnected clusters.
 +
Checking free cluster summary.
 +
Starting verification pass.
 +
Checking for unused clusters.
 +
Performing changes.
 +
/dev/sde1: 30111 files, 611080/945313 clusters
 +
</pre>
 +
<br /><br />
 +
Safest way to totally and completely disconnect a USB device from a Linux machine:<br />
 +
(Assuming your USB device is detected by the OS as /dev/sde - adjust command for your device name!)
 +
<pre style="color:blue">
 +
udisks --unmount /dev/sde && udisks --detach /dev/sde
 +
OR if already unmounted:
 +
udisks --detach /dev/sde
 +
</pre>
 +
<br />
 +
This safely powers down the USB device, causing any LED light on the USB device to turn off, indicating it is truly safe to unplug the USB thumb drive!
 +
<br /><br /><br />
 +
To format USB thumb type drive with original FAT file system, so it can be read by all computers,<br />
 +
<pre style="color:red">
 +
****************************************************************************************************************************
 +
***** FIRST:  SAVE ALL DATA you do not want to lose!!!  Otherwise, you WILL lose it after you follow this procedure!!! *****
 +
****************************************************************************************************************************
 +
</pre>
 +
<br /><br />
 +
Delete all existing partitions using fdisk(substituting x for the actual drive letter your USB drive is recognized as by the "dmesg" command:<br /><br />
 +
<pre style="color:blue">
 +
fdisk /dev/sdx
 +
</pre><br />
 +
Then, within fdisk, use the "D" key, lower case, not shifted upper case as I have typed here, to delete each partition that may exist.<br />
 +
Once all partitions have been deleted, create ONE(1) new partition by tapping the "N" key, again lower case, not shifted as in my example.<br />
 +
Then, hit the enter key to complete creation of the new partition, and then change the partition type by tapping the "T" key and then tapping the "B" key.<br />
 +
This should change the partition type from Linux type 82 to FAT 32 type b.  Confirm this by tapping the "P" key and hitting "ENTER".<br />
 +
Create ONE(1) new partition of b type(FAT 32, NOT LBA!).<br />
 +
<br /><br />
 +
Format new partition on USB drive using this command:<br />
 +
(replacing x with your USB key drive letter)<br />
 +
<pre style="color:blue">
 +
mkfs.vfat -F 32 /dev/sdx1
 
</pre>
 
</pre>
 
<br /><br />
 
<br /><br />

Latest revision as of 22:45, 9 November 2022

Shell Commands


Display all network interface names on any Linux system from the shell:

/sbin/ifconfig | grep BROADCAST | cut -d " " -f1 | sed 's/.$//' 


Most Linux machines will only display one network interface, such as shown on my Slackware 14.1 Virtual Machine Server:

eth0 


Other systems may have more than one, such as those with virtual machine software or with more than one physical NIC.
Also, some systems use non-standared network interface names, other than the usual eth0.

Here are some samples of those types of systems. In these examples, the first network interface name is the main one used, and the following ones are used for the virtual machine software.

Sample output from my Fedora 20 (Heisenbug) VirtualBox server:

em1
virbr0


And here is a sample output from my Fedora 17 (Beefy Miracle) laptop running VMWare:

p5p1                                                                           
vmnet1                                                                         
vmnet8



The "ps" Process Command Syntax

To show all executing processes:

$ ps ax


To show all processed running by a specific user(This example shows all processes running by the Apache WebServer):

$ ps -U apache



How to find the 10 largest files in the current directory

ls -XS | head -n 10



OR

du -a /directory_name | sort -n -r | head -n 10



Many other examples with more advanced options can be found at this URL:
https://www.tutorialspoint.com/find-the-largest-top-10-files-and-directories-on-a-linux

How to grep from files that have been compressed with Gzip using zgrep

Unix and Linux systems come with a modified version of grep named zgrep. The Linux zgrep command works just like the grep command, except it works on text files that have been compressed with gzip.

The zgrep command does not support recursive usage, however, the following command line string does allow you to zgrep recursively through multiple directory levels:

find . -name *.gz -exec zgrep -- string_searching_for {} +



Change Time Zone of Linux Server from Command Line

To manually and permanently change the time zone of a Linux system, it's a very simple matter of copying the time zone file you want over the localtime file of the system, as follows(Using U.S. Pacific Standard Time):
MUST be done as root user! System must be rebooted for changes to take effect!

[root@server ~]# cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime  



Customizing Your Shell & Environment

Most people use the default Linux shell Bash, the Bourne Again SHell, which is basically the Bourne shell with lots of cool add-ons and extra features, such as command completion. There are two main configuration files for your shell, and they are "hidden" files, starting with a dot, so they aren't shown during a normal directory listing unless specified. The configuration files are .bashrc and .bash_profile The .bashrc file contains aliases, which are custom commands used often. For instance, I like having an alias called "cls" to run the shell "clear" command to clear the contents of the currently visible screen. More bash shell configuration info to come when I have the time.

Convert Computer Epoch Date & Time Codes to Human Readable Dates & Times

From the Linux command line shell:

date -d @1449129600


Gives the output of:

Thu Dec  3 00:00:00 PST 2015



Using perl:

perl -le 'print scalar localtime $ARGV[0]' 1449129600


Gives the output of:

Thu Dec  3 00:00:00 2015



Display the Full Calendars of the Last 20 Years with a One-Liner Command!

For example, say it is the year 2015, and you want to display all of the full calendars for the last 20 years, you can you this one line command to spit it out to the terminal console, or redirect it into a text file for later use.

This is how to do it with what is known as a "One-Liner" command, which is actually a set of commands strung together on one line:

$ for ((year=1996;year<=2015;year++)); do cal $year; done


This simple example can be applied to thousands of scenarios where you want to iterate through some data a specific number of times, or until a specific target is reached. Use your imagination to apply this to any repetitive command line tools you use!

E-Mail Info

To redirect email sent to an alias address to another email address on the Linux email server, edit the /etc/aliases file, and then be sure to IMMEDIATELY run the newaliases command to rebuild the actual database the MTA uses!

Miscellaneous CD/DVD & USB Command Line Commands

To show all mounted drives, both the "mount" and "df" commands are useful and helful, as seen here(Example using one of my servers):

$ mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=8104892k,nr_inodes=2026223,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
/dev/mapper/fedora-root on / type ext4 (rw,relatime,seclabel,data=ordered)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=41,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
tmpfs on /tmp type tmpfs (rw,seclabel)
configfs on /sys/kernel/config type configfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
sunrpc on /proc/fs/nfsd type nfsd (rw,relatime)
/dev/md126p1 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
/dev/mapper/data-home on /home type ext4 (rw,relatime,seclabel,data=ordered)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)


Output of the "df" command on one of my servers: (I added the -h switch to show sizes in "Human Readable" format, meaning it shows an M or G for Megabytes & Gigabytes)

$ df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/fedora-root        58G   47G  8.0G  86% /
devtmpfs                      7.8G     0  7.8G   0% /dev
tmpfs                         7.8G   88M  7.7G   2% /dev/shm
tmpfs                         7.8G  1.2M  7.8G   1% /run
tmpfs                         7.8G     0  7.8G   0% /sys/fs/cgroup
tmpfs                         7.8G   92M  7.7G   2% /tmp
/dev/mapper/extra-extra1      197G   93G   95G  50% /mnt/extra1
/dev/mapper/more-morespace1   586G  371G  186G  67% /mnt/more1
/dev/md126p1                  969M  116M  787M  13% /boot
/dev/mapper/fedora-save       197G   60M  187G   1% /mnt/save
/dev/mapper/data-vms2         296G  180G  102G  64% /mnt/vms2
/dev/mapper/backup-vms        197G  184G  3.7G  99% /mnt/vms
/dev/mapper/archive-archive1  501G  399G   77G  84% /mnt/archive
/dev/mapper/data-data1         99G   79G   15G  84% /mnt/data1
/dev/mapper/data-home         197G  172G   16G  92% /home



***** VERY IMPORTANT INFO!!! *****

In order to "SAFELY" remove a CD, DVD, USB, Removable Hard Drive, or any type of removable media or drive, YOU MUST FIRST UNMOUNT the removable media or drive, and also possibly detatch and/or eject the media or drive. Here are the command line commands to perform these functions:
The first step applies to all situations and types of drives or medium, which is to "UNMOUNT" the drive, using the "umount" command. NOTICE the "N" is dropped in the actual unmount command, so "umount" is NOT a typo!

For example, here is how to unount a mounted CD ROM disk inserted into the drive. Also, instead of pushing the little push button on the front of CD & DVD drives, I prefer to use command line commands to both open and close the drive tray, if it is the type that has a tray that opens/ejects to insert a disk.

To open and close the CD/DVD drive tray, use the eject command as follows:

$ eject

This should open the disk tray. If you have more than one CD/DVD ROM drive, you need to specify the device name of the unit you want to use, as shown here:

$ eject /dev/sdb 

or

$ eject /dev/sdc 


The actual device name depends on how it is installed in your computer. To get an idea of the actual device name your computer uses for it's CD/DVD ROM drives, I like to use the "dmesg" command, as show here:

$ dmesg | grep -i cd-rom
[    0.666858] scsi 4:0:0:0: CD-ROM            ASUS     DRW-24F1ST   a   1.00 PQ: 0 ANSI: 5
[    0.670145] cdrom: Uniform CD-ROM driver Revision: 3.20
[    0.670287] sr 4:0:0:0: Attached scsi CD-ROM sr0


As you can see from above, the CD/DVD ROM burner I have is an Asus DRW-24F1ST, attached to scsi CD-ROM device "sr0".
This is the important device name: sr0 which you can then use to eject/open and close the CD-ROM drive tray.
FYI, "sr0" stands for "SCSI Recorder 0", in case you were wondering...

So, the actual working example on my server to open/eject the tray is:

$ eject /dev/sr0 


The actual working command to close the CD-ROM tray after I've inserted a disk into the tray on my server is:

$ eject -t /dev/sr0 



USB Devices


To determine which device your USB thumb drive is connected to, use the "dmesg" command again, as follows:

# dmesg | grep -i 'Attached SCSI'



To manually check & fix a USB file system, use this example(As the root super user):

# fsck.fat -atvV /dev/sde1
fsck.fat 3.0.25 (2014-01-17)
fsck.fat 3.0.25 (2014-01-17)
Checking we can access the last sector of the filesystem
0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
 Automatically removing dirty bit.
Boot sector contents:
System ID "MSDOS5.0"
Media byte 0xf8 (hard disk)
       512 bytes per logical sector
     16384 bytes per cluster
     10144 reserved sectors
First FAT starts at byte 5193728 (sector 10144)
         2 FATs, 32 bit entries
   3784704 bytes per FAT (= 7392 sectors)
Root directory start at cluster 2 (arbitrary size)
Data area starts at byte 12763136 (sector 24928)
    945313 data clusters (15488008192 bytes)
63 sectors/track, 128 heads
      8064 hidden sectors
  30274944 sectors total
Starting check/repair pass.
Checking for bad clusters.
Reclaiming unconnected clusters.
Checking free cluster summary.
Starting verification pass.
Checking for unused clusters.
Performing changes.
/dev/sde1: 30111 files, 611080/945313 clusters



Safest way to totally and completely disconnect a USB device from a Linux machine:
(Assuming your USB device is detected by the OS as /dev/sde - adjust command for your device name!)

udisks --unmount /dev/sde && udisks --detach /dev/sde
OR if already unmounted:
udisks --detach /dev/sde 


This safely powers down the USB device, causing any LED light on the USB device to turn off, indicating it is truly safe to unplug the USB thumb drive!


To format USB thumb type drive with original FAT file system, so it can be read by all computers,

****************************************************************************************************************************
***** FIRST:  SAVE ALL DATA you do not want to lose!!!  Otherwise, you WILL lose it after you follow this procedure!!! *****
****************************************************************************************************************************



Delete all existing partitions using fdisk(substituting x for the actual drive letter your USB drive is recognized as by the "dmesg" command:

fdisk /dev/sdx


Then, within fdisk, use the "D" key, lower case, not shifted upper case as I have typed here, to delete each partition that may exist.
Once all partitions have been deleted, create ONE(1) new partition by tapping the "N" key, again lower case, not shifted as in my example.
Then, hit the enter key to complete creation of the new partition, and then change the partition type by tapping the "T" key and then tapping the "B" key.
This should change the partition type from Linux type 82 to FAT 32 type b. Confirm this by tapping the "P" key and hitting "ENTER".
Create ONE(1) new partition of b type(FAT 32, NOT LBA!).


Format new partition on USB drive using this command:
(replacing x with your USB key drive letter)

mkfs.vfat -F 32 /dev/sdx1