Yahoo
Advertisement
Advertisement
Advertisement
Advertisement

Stop memorizing two sets of commands—these 7 work on Windows and Linux

Monitor showing i3 tiled terminal layout with xprop confirming window manager is i3.
Dibakar Ghosh | How-To Geek

If you want to use the Linux command line after using PowerShell or vice versa, you'll find many commands are the same between the two. From file management to networking , you can find many commands in common.

cd

Change directories

The "cd" command , for "change directory," isn't particularly exciting, either in Linux or Windows. It just does its job, which is to change the working directory, or the directory that you're currently in.

On Linux, you can supply the cd command with the absolute or relative pathname you want to go to.

Advertisement
Advertisement

Suppose you wanted to go to the /usr/share/doc directory, you'd type:

If you were in your home directory and wanted to go to the docs directory that was a subdirectory of your home directory, you would type:

You can go up a subdirectory relative to the current working directory by adding using ".." (two periods) as the argument:

You can go to your home directory by just using the cd command by itself.

The cd command in PowerShell is similar. You can use cd followed by the pathname:

You can also use "cd .." to go up a subdirectory, as with the Linux cd command. cd is actually an alias of the PowerShell "Set-Location" function. PowerShell defines a lot of aliases like this to be familiar to Linux users as well as MS-DOS and Command Prompt users. Commands like this that were already used in Unix and Linux helped me use my knowledge from my MS-DOS days to successfully learn the Linux command line.

mkdir

Create directories

The mkdir command is also another command that's useful but not very exciting.

Advertisement
Advertisement

To create a new directory in Linux, use the mkdir command. To create a directory called "test" as a subdirectory of the current working directory:

The mkdir command on Linux has more options. While cd was a built-in command on zsh, my shell of choice, it's a regular program in Linux.

You can use the -p option to set the directory permissions . If you wanted a directory to, readable, writable, and searchable by its owner and off-limits to anyone else:

mkdir takes arguments similar to that of chmod for file permissions. The "7" means that the owner has read, write, and execute permissions, which for directories means that the owner can list files in the directory, while other users, even those in the same group, have no access at all.

Advertisement
Advertisement

To do the same using symbolic permission values:

The PowerShell version is similar:

rm

Delete files, forever

You can also delete files with the same rm command in Linux and Windows.

You can use the Linux command to get rid of a single file:

Or you can use a wildcard character to generate a list of files. To remove all .zip files in the current directory:

When you delete files using rm, you can't get them back. They are permanently deleted, so be careful with the rm command, particularly as root and in system directories.

PowerShell also has an rm command, and it's aliased to Remove-Item

While Windows is usually forgiving with deleted files, you should be careful deleting files on the command line as you would be in Linux. Files deleted using rm don't go to the Recycle bin, but are deleted directly.

Advertisement
Advertisement

One difference between the Linux and Windows rm commands is that the latter works on directories as well as files, while in Linux, to delete directories, you need to use the rmdir command.

ping

Is that site up or down?

Output of Windows Powershell ping command from google.com.

If you want to check whether a remote site is responding or see if your internet connection is working, you can use the ping command.

To check if Google is responding on both Linux and Windows:

The two utilities behave differently on Linux and Windows. On Linux, the ping will run forever until you press Ctrl+c, and then print some summary statistics.

You can set the number of times that ping will run with the -c option. To ping four times:

The Windows version will run four times by default.

nslookup

Who owns that domain name?

If you want to see who owns a domain name, the nslookup command will let you do so. It exists on both Linux and Windows, and the command is exactly the same, though the output looks slightly different between the two:

cURL

Download files from the command line

cURL is a useful tool for downloading files from the command line . It's already popular on Linux for installation scripts, but it's now installed by default on Windows PowerShell as well.

Advertisement
Advertisement

To download a file on either system:

ssh

Connect to remote servers in the terminal

SSH is another networking tool that's ubiquitous in system administration. It's already installed on most Linux distributions. Previously, Windows users had to install third-party tools such as PuTTY to use SSH, but PowerShell has the same OpenSSH as on Linux systems built into PowerShell.

SSH into my home server using Tailscale

If you have an account on a remote server, you can just run the SSH command:

You can set up a remote key pair so you can log in without a password.


It's easy to convert between the Linux and Windows command lines. You don't have to spend time remembering commands. If you're used to Linux, but dabble in PowerShell once in a while, you can use your favorite Linux commands.

Advertisement
Advertisement
Mobilize your Website
View Site in Mobile | Classic
Share by: