Posts

Showing posts from August, 2020

Linux Daily Uses & Advance Commands – Part 2

Image
  11. How to lock and unlock the user account? passwd -l (lock user account) passwd -u (unlock user account) 12. What is the command to view and change the expiry date for any user? chage -l username chage -E YYYY-MM-DD username 13. What are the field of /etc/passwd file?  7 filelds test:x:1000:1000:test:/home/test:/bin/bash (grep test /etc/passwd) username:password(encrypted stored in  etc/shadow):UID:GID:description:user-home-directory:default-login-shell 14. What is the difference between .bash_profile and .bashrc? Ans. When you log on the system .bash_profile is executed but if you already logged in or open any new terminal .bashrc is executed. 15. What are the details you get the finger command? Ans. It is not pre-install with OS, we are to install finger. It give the login and shell information of a user. 16. Name 3 files which automatically created inside any user’s home directory when a user is added? Ans. . bashrc   .bash_profile  Bash_history  17. What is the command to vi

Linux Daily Uses & Advance Commands – Part 1

Image
  1. How to remove files older than 7 days by creating a cron job to run every night? find /var/log/security -type f -mtime +7 -exec rm -rf {} \; Cron – /etc/crontab (show the cron format) To add the command in crontab file crontab -e 0 0 * * * /bin/find /var/log/security -type f -mtime +7 -exec rm -rf {} \; 2. Run a command that shows all the line except any lines starting with a character # in the file? cat filename | grep -v ^#  (character name you want to omit) 3. Which 2 files contain default values when creating a user with useradd command?  First File: /etc/default/useradd Second File: /etc/login.defs cat /etc/default/useradd grep -v ^# /etc/login.defs | grep -v ^$ [first # symbol for omit and second $ for omit space) Password max, min, warn days | password length | UID and GID min, max | umask | encryption method 4. What is the command to create user with a pre defined uid, shell and home directory? useradd -m -d /home/username -s /bin/bash -u 9000 username grep username /etc