Advertisement
D0cEvil

Bash - Checking for existence

Jan 4th, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.40 KB | Software | 0 0
  1. Проверка существования файла:
  2. if ! [ -f /path/to/file ]; then
  3. echo 'No file'
  4. fi
  5.  
  6. Проверка существования директории:
  7. if ! [ -d /path/directory/ ]; then
  8. echo 'No directory'
  9. fi
  10.  
  11.  
  12. Проверка существования пользователя:
  13. grep "username:" /etc/passwd >/dev/null
  14. if [ $? -ne 0 ]; then
  15. echo 'No username found'
  16. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement