0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

shellで受け取ったフルパスを使用したファイルリネーム

Posted at

概要

shellにファイルのフルパスを引数として渡したときに、もともとのファイルネームを利用しつつ名前を変えたい
例:
引数→ /home/desk/a.txt
出力→ /home/desk/bc_a.txt

ソース

a=/home/desk/a.txt
echo $(dirname ${a})/bc_$(basename ${a})

実行結果

/home/desk/bc_a.txt

コマンド詳細

dirnameコマンドは引数のディレクトリ部分を抜き出してくれる
basenameはファイルネーム部分を抜き出してくれる
抜き出し条件も細かく決めることが可能なため、必要に応じて要調査
(拡張子なしで抜き出すなど)

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?