PowerShell for Linux admins

During the Cloud Expo convention in the Netherlands last month, I spoke to someone who said that learning all the PowerShell commands as a Linux admin was difficult. PowerShell was built to make it easier for Linux admins to transition to it. In this blog post, I will show you how aliases work and how they help Linux Admins get started with basic PowerShell tasks…

Aliases

From the start, PowerShell would let you use aliases for specific commands. There are many built-in ones, and you can add your own if you want to. To get a list of aliases, you can use the Get-Alias cmdlet, which will return the list of the currently configured aliases:

As shown above, the list will also show if a particular alias was added by installing a specific module. Az.Accounts, for example, add these:

Linux aliases

As you can see in the first screenshot, specific aliases that are available by default in Powershell are used in Linux. From the available aliases, these are similar to Linux commands:

Linux commandPowerShell cmdletDescription
catGet-ContentShow the contents of a file
cdSet-LocationChange directory
clearClear-HostClear contents of the terminal screen
cpCopy-ItemCopy a file to another file
dirGet-ChildItemShow the files and folders in current folder
echoWrite-OutputOutput text to screen
historyGet-HistoryRetrieve the list of previously uses commands
killStop-ProcessTerminate a process
lsGet-ChildItemShow the files and folders in the current folder
manhelpGet help for a specific command
mdmkdir / New-ItemCreate a folder, mkdir
mountNew-PSDriveMount a temporary or persistent drive or folder
mvMove-ItemMove a file or folder to another location or rename it
popdPop-LocationChange current working directory
psGet-ProcessRetrieve running processes
pushdPush-LocationSave the current directory and move to another
pwdGet-LocationShow current location
rmRemove-ItemRemove file
rmdirRemove-ItemRemove directory
sleepStart-SleepSleep for x seconds
sortSort-ObjectSort output
teeTee-ObjectWrite output to file from pipe

It could be that I missed one, but these are the ones I know and also use in Linux myself 🙂

Best practices in using aliases

While aliases are excellent, typing fewer characters, you should always use the full PowerShell cmdlet in scripts, making it more readable. I wrote a blog post in the past with examples here.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.