Linux Daily Uses & Advance Commands – Part 1
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 -e0 0 * * * /bin/find /var/log/security -type f -mtime +7 -exec rm -rf {} \;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
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 method4. 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 usernamegrep username /etc/passwduserdel -r usernameuseradd -g test -G wheel username [small g for primary group and capital G for secondary group)id username [to check user information]usermod -g primarygroupname usernameThe file path is /etc/sudoers (But we never change the sudoer file directly, we edit the file with visudo command)
visudoChange the file line # # Allow root to run any command anywhereroot ALL=(ALL) ALL
gautam ALL=(ALL) ALL (Add this line below the root line)visudoAdd the line below – # # Same thing without a password [we need to add user in wheel group)# %wheel ALL(ALL) NOPASSWD: ALL
linux ALL(ALL) NOPASSWD: ALLlast last username (particular user detail)