LoginSignup
0
0

More than 3 years have passed since last update.

[shell] 直下の全てのディレクトリの中身を取得し、リネームする

Posted at

達成したいこと

以下のようなディレクトリ構造がある時に、

├DirA
| ├-- fileA1.pdf
| └   fileA2.pdf 
└DirB
  ├-- fileB1.pdf
  └-- fileB2.pdf 

各ディレクトリの中身である4つのpdfファイルをリネームし、
以下の形にファイル移動を行う。
(各ディレクトリの中身を取り出して、リネームした上で、カレントディレクトリに移動させたい。)

├DirA
├DirB
├DirA_fileA1.pdf 
├DirA_fileA2.pdf 
├DirB_fileB1.pdf 
├DirB_fileB2.pdf 

コード

 for dir in `ls` 
 do 
   for file in `ls $dir` 
   do 
     mv $dir/$file $dir\_$file
   done 
 done

one liner

for dir in `ls`; do for file in `ls $dir`; do mv $dir/$file $dir\_$file; done ;done
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