| show current directory |
pwd |
cd |
get-location |
powershell’s get-location shows full path |
| list files/folders |
ls -l |
dir |
get-childitem or ls |
powershell aliases ls to get-childitem |
| change directory |
cd folder |
cd folder |
set-location folder or cd folder |
cd .. goes up one level |
| create folder |
mkdir folder |
mkdir folder |
new-item -itemtype directory folder |
works in both cmd and powershell |
| create empty file |
touch file.txt |
type nul > file.txt |
new-item file.txt |
echo > file.txt also works |
| copy file |
cp file1 file2 |
copy file1 file2 |
copy-item file1 file2 |
use -recurse for folders in powershell |
| move / rename file |
mv file1 file2 |
move file1 file2 |
move-item file1 file2 |
can rename files with same command |
| delete file |
rm file |
del file |
remove-item file |
-recurse for folders in powershell |
| delete folder |
rm -r folder |
rmdir /s folder |
remove-item folder -recurse |
dangerous: deletes all contents |
| view file content |
cat file |
type file |
get-content file |
get-content can also stream large files |
| view first/last lines |
head file / tail file |
n/a |
get-content file -totalcount 10 / `get-content file |
select-object -last 10` |
| search inside files |
grep "text" file |
findstr "text" file |
select-string "text" file |
works recursively with -r in linux |
| find files/folders |
find . -name "*.txt" |
dir /s *.txt |
get-childitem -recurse -filter *.txt |
searches recursively in subfolders |
| environment variables |
echo $var |
echo %var% |
$env:var |
useful for paths, configs |
| run program |
./program |
program.exe |
.\program.exe |
linux executables may need chmod +x |
| clear screen |
clear |
cls |
clear-host |
keeps terminal tidy |
| history of commands |
history |
doskey /history |
get-history |
powershell allows re-running with invoke-history |
| redirect output to file |
command > file |
command > file |
command > file.txt |
appends with >> |
| pipe output |
`command1 |
command2` |
`command1 |
command2` |
| check system info |
uname -a |
systeminfo |
get-computerinfo |
linux shows kernel, architecture, etc. |