************************************************************ *** WARNING ****** WARNING ****** WARNING ****** WARNING *** ************************************************************ * DO NOT USE ANY OF THESE COMMANDS UNLESS YOU UNDERSTAND * * WHAT THEY DO - SOME ARE/CAN BE DESTRUCTIVE * ************************************************************ ------------------ Linux Tips ------------------------ # change/fix permissions to for folder and files, so owner has full access and group has read access sudo find . -type d -exec chmod 755 {} \; sudo find . -type f -exec chmod 644 {} \; # Clean up / santanise log files find ./logs -type f -name "*" -print -exec sed -i 's/PBI..-...-PN./SERVER/g' {} \; -exec sed -i 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/xxx.xxx.xxx.xxx/g' {} \; -exec sed -i 's/local.domain/domain.name.au/g' {} \; -exec sed -i 's/pidm......\..../username/g' {} \; # Find files older than a specified time (mtime) and REMOVE them - suggest running command without -exec rm {} \; option first to check what files are found. find . -type f -mtime +30 -name '*.aud' -exec rm {} \; find . -type f -mtime +30 -exec rm {} \; find . -type f -mtime +7 -exec rm {} \; # find gzipped logs older than three days and DELETE them find /opt/bis/log -type f -mtime +3 -name "*.gz" -exec rm {} \; # Find and gzip old log files find . -type f -name "wms-cli-2024*.log" -exec gzip {} \; # Find files older than 7 days, type is file, mtime 7 days, name condition, rm to REMOVE find /tmp -type f -mtime +7 -name "1*" -exec rm {} \; find . -type f -mtime +7 -exec rm {} \; # Resize a logical volume (adds 2gb and resizes filesystem to suit) lvextend --resizefs --size +2G /dev/mapper/rootvg-configlv lvextend --resizefs --size +2G /dev/mapper/rootvg-rootlv # Set IP address using NMCLI nmcli con mod ens3f1 ipv4.method manual ipv4.addres XXX.XXX.XXX.XXX/24 nmcli con mod ens3f1 ipv4.gateway XXX.XXX.XXX.1 nmcli con mod ens3f1 dns-search domain.name nmcli con mod ens3f1 dns "XXX.XXX.XXX.XXX,XXX.XXX.XXX.XXX" nmcli con mod ens3f1 connection.autoconnect yes nmcli con up ens3f1 # Filtering in top command press O then type COMMAND=splunk press ENTER # Grep a file and remove comments and blank lines cat dovecot.conf | grep -v ^# | grep -v ^$ # Adding a rich firewall rule(s) - if firewall is not running, use firewall-offline-cmd firewall-cmd --add-rich-rule='rule family="ipv4" source address="XXX.XXX.XXX.XXX" accept' --perm # Add/allow a port/service to the firewall firewall-cmd --add-port 25/tcp --perm firewall-cmd --add-service ssh --perm # After adding a rich rule, port or service the firewall needs to be reloaded for the changes to take effect firewall-cmd --reload # To see if Firewall Loggin (of denied messages) is enabled sudo firewall-cmd --get-log-denied # Redirecting output command 2>&1 /dev/null or command 1> /dev/null 2> /dev/null or command > /dev/null 2>&1 # REMOVE old log files find /opt/bis/log -type f -mtime +7 -name "*2023*" -exec rm {} \; # Extract rpm file rpm2cpio| cpio -idmv # Using a for loop to repeat a command for i in{1..5}; do COMMAND; done # A more useful prompt PS1="[\u@\h:\w]\\$ " # Useful aliases to add to .bash_profile - echo "alias bis='sudo -i -u bis'" >> ~/.bash_profile alias dush='du -sh *' alias bis='sudo -i -u bis' ### Fix slow login (when using local credentials ) - vi /etc/ssh/sshd_config UseDNS no GSSAPIAuthentication no - service sshd restart ### Fix mRemote / puTTY to close window when disconnected. You need to change the putty options under tools->options->advanced. Relevant options are setting Session->"Close window on exit" to Always, enabling Connection->"Enable TCP keepalives" and setting Connection->"Seconds between keepalives" to more than 0. Remember to save the PuttyNG settings as "Default Settings" in Session->"Saved Sessions". # 'zip' a bunch of files into the one tar file, and remove the files as they are being archieved. tar cvf wfmcl-2023-11.tar wfmcl-2023-11-*.log --remove-files # Set a logback file to from INFO to DEBUG sed -i 's/INFO/DEBUG/g' /opt/bis/fes/etc/fes-logback.xml # Set a logback file to from DEBUG to INFO sed -i 's/DEBUG/INFO/g' /opt/bis/fes/etc/fes-logback.xml # Searching for a string in multiple log files in specific folders grep -r "string to search for " FOLDER1/*.log FOLDER2/*.log FOLDER3/*.log FOLDER4/*.log # Using GitHub with SSH Keys Generate key $ ssh-keygen -t ed25519 -C “your_email@example.com†View you new SSH Key $ cat ~/.ssh/id_ed25519.pub Open github, go to setting, SSH and GPG Keys, click add a new key, page contents of id_ed25519.pub into box. ----------------------- ANSIBLE TIPS ---------------------- # Specifying a username and password in the ansible hosts file [SERVERS] SERVERNAME ansible_connection=ansible_connection=ssh ansible_ssh_user=ansible ansible_ssh_pass=Password