ファイルパスの操作

拡張子(またはファイル名の本体)を取り出す

パラメータ展開を使う。パラメータ(file)からパターン(*.または.*)にマッチした箇所の左側(または右側)を取り除く。

#
パラメータの左側を取り除く。
%
パラメータの右側を取り除く。

##のように2つ続けると最長一致。

 file=1.2.txt
 
 echo ${file##*.} # 拡張子を取り出す
 echo ${file#*.}  
 echo ${file%%.*}
 echo ${file%.*}  # ファイル名の本体を取り出す

の実行結果↓

 txt
 2.txt
 1
 1.2

フルパスの取得

 find $(pwd) -name foo.txt
  => /home/bar/foo.txt
 find $PWD -name foo.txt
 readlink -f foo.txt

参考

http://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-absolute-path-in-linux


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS

Last-modified: 2015-04-01 (水) 10:40:05