I'm basically looking for something like ls -alt
, but in Powershell (Windows 11). Currently I'm using
gci -fo | sort LastWriteTime -Descending
but it's a bit of a doozy, and definitely not easy to remember. Isn't there anything shorter, which achieves the same?
EDIT: the proposed solution using
Function ls-alt {Invoke-Expression "gci $Args -Force"} # | sort LastWriteTime -Descending}
doesn't work. Proof:
create an empty dir with
mkdir test
cd test
notepad foo
, write some string (I wrotestring
), save and closecopy some older file into
test
(I used an existing.gitconfig
, but I think any older file would work)PS C:\Users\xxx\test> gci | sort LastWriteTime -Descending
Directory: C:\Users\xxx\test
Mode LastWriteTime Length Name
-a---- 3/18/2024 10:04 PM 6 foo.txt -a---- 8/31/2023 9:13 AM 66 .gitconfig
PS C:\Users\xxx\test> ls-alt
Directory: C:\Users\xxx\test
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 8/31/2023 9:13 AM 66 .gitconfig
-a---- 3/18/2024 10:04 PM 6 foo.txt
The proposed solution doesn't correctly order files by LastWriteTime
. The content of the profile file is as expected:
notepad $PROFILE
Function ls-alt {Invoke-Expression "gci $Args -Force"} # | sort LastWriteTime -Descending}
Function ls-alt {gci -force | sort LastWriteTime -Descending}
.gci
, use:Function ls-alt {Invoke-expression "gci $Args -Force"} # | sort LastWriteTime -Descending}
. That will allowls-alt -s
(Recurse),ls-alt $HOME
, etc.