IT이야기
linux - Hide "No such file or directory" when 'cat' nonexistent file
준호씨
2018. 1. 23. 21:34
반응형
You can see stderr "No such file or directory" when you 'cat' none exists file
$ cat nonexistent_file
cat: nonexistent_file: No such file or directory
If you want to hide stderr, attach 2>/dev/null after command
cat nonexistent_file 2>/dev/null
Tip
'grep' command has '-s' option to hide error message about nonexistent or unreadable files.
-s, --no-messages
Suppress error messages about nonexistent or unreadable files. Portability note: unlike GNU grep, 7th Edition Unix grep did not conform to POSIX,
because it lacked -q and its -s option behaved like GNU grep’s -q option. USG-style grep also lacked -q but its -s option behaved like GNU grep.
Portable shell scripts should avoid both -q and -s and should redirect standard and error output to /dev/null instead. (-s is specified by POSIX.)
$ grep nonexistent_file something
grep: something: No such file or directory
$ grep nonexistent_file something -s
References
반응형