3
0

More than 3 years have passed since last update.

shell やlinuxでファイル名の特殊文字をエスケープしたい!

Last updated at Posted at 2019-11-26

タイトルそのままlinuxコマンドで

問題

wc -l  /var/tmp/20191126-(2,135,397個)テストファイル.csv

のように「20191126-(2,135,397個)ファイル.csv」ファイルの行数を取得しようとしたらエラー


-bash: syntax error near unexpected token `('

シンタックスエラーだと。。。

解決策

どうやら「(」が特殊文字でエスケープする必要があるとのこと

ファイル名をシングルクォートで囲めばOK!


wc -l  '/var/tmp/20191126-(2,135,397個)テストファイル.csv'

PHPであれば、、

$filePath = '/var/tmp/20191126-(2,135,397個)テストファイル.csv'

$totalRows = exec("wc -l '${filePath}'");

これで正常にできるはず

かんたん

参考
https://qiita.com/cocodrips/items/bb3640a9834c8978d48a

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