ls
コマンドは echo
で代用できます。
# ls
$ echo *
# ls -a
$ echo .* *
ただし、ファイル名に区切り文字 (space:\x20
) が含まれる場合を考慮する必要があります。
$ echo "foo" > "bar baz.txt"
# NG
$ echo *.txt | xargs cat
cat: bar: No such file or directory
cat: baz.txt: No such file or directory
# OK
$ printf "%s\n" *.txt | while read x; do cat "$x"; done
foo
stat
コマンドを使うと出力フォーマットを細かく調整できますが、ls
コマンド同様、GNU/BSD で実装が異なる点に注意が必要です。
# GNU stat
$ stat -c "%A %n" .* *
# BSD stat
$ stat -f "%Sp %N" .* *
単にOS判定で切り替えると、macOS (BSD) ユーザが、Homebrew で GNU coreutils を入れて alias を定義しているケース等でうまく動きません。
alias ls="gls --color"
alias stat="gstat"