1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Linuxの.bashrcをWindowsのPowerShellで

1
Last updated at Posted at 2026-05-22

BashとPowerShell

LinuxBash を使い慣れている人が、WindowsPowerShell に乗り換えるための記事です。

Home Directory

ホームディレクトリは ~ で表現されます。仮にユーザ名が pell2401 だとして、それぞれのOSのホームディレクトリは次の通り。

OS Home Directory
Linux /home/pell2401
Windows C:\Users\pell2401

Linuxでディレクトリ階層を表すときは、スラッシュ (/) を利用し、Windowsではバックスラッシュ (\) を利用します。

プロファイルの場所

ターミナル起動時に呼ばれるスクリプトは、~/.bashrcでしたが、それに対応するものがWindowsにもあります。

  • Linux

    • フォルダ: ~
    • ファイル名: ~/.bashrc
  • Windows

    • フォルダ: ~\Documents\PowerShell
    • ファイル名: Microsoft.PowerShell_profile.ps1

Windowsのプロファイルの場所は、デフォルトでは作成されていないため、手動で作成してファイルを置く必要があります。

Home Directoryの確認方法の違い

Bash & PowerShell
# Bash上で
echo ~
# 実行結果
/home/pell2401

# PowerShell上で
echo $HOME
# 実行結果
C:\Users\pell2401

プロファイル

Windowsはデフォルトで、$PROFILEに示されるフォルダとファイルはないため、手動で作成します。その後、Microsoft.PowerShell_profile.ps1 を次のように作成し保存します。拡張子 .ps1 は PowerShell 用のバッチファイル (シェルスクリプト) のようなものです。

Microsoft.PowerShell_profile.ps1
# このファイルを即時有効にするには . $PROFILE を実行します。

#####################
###   エイリアス   ###
#####################

# Linuxコマンド名を PowerShell のコマンドで登録

# clear
Set-Alias clear cls

# ll (= 'ls -alF')
Set-Alias ll ls

# grep
Set-Alias grep Set-String

# コマンド `notepad`, `edit` で `VS code` を開くようにする (任意)
Set-Alias notepad code
Set-Alias edit code

#####################
### 関数エイリアス ###
#####################

# which
function which {
	param($name)
	(Get-Command $name).Source
}

# 既存エイリアスがあれば削除
if (Test-Path Alias:history) {
	Remove-Item Alias:history -Force
}

# history
function history {
	$i = 1
	Get-Content (Get-PSReadLineOption).HistorySavePath | ForEach-Object {
		"{0,5} {1}" -f $i, $_
		$i++
	}
}

# `notepad` で notepad++ を開くようにする (任意)
function notepad {
	& "C:\Program Files\Notepad++\notepad++.exe" $args
}

# Linux の nl コマンド
function nl {
	param([Parameter(ValueFromPipeline=$true)]$line)
	begin { $i = 1}
	process { "{0,4} $line" -f $i; $i++ }
}


PowerShell
# Linux の場合
# . ~/.bashrc

# PowerShell の場合
. $PROFILE
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?