Site Tools


generic_linux_commands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
generic_linux_commands [2023/01/18 13:33] – created admingeneric_linux_commands [2026/03/25 14:01] (current) admin
Line 1: Line 1:
 ====== GENERIC LINUX COMMANDS ====== ====== GENERIC LINUX COMMANDS ======
  
 +===== RENAME 'The' ROMS =====
 +1. Dry-run preview (generates rename list without executing):
 +<code>
 +  find /mnt/DOCS1/ROMs/Library/roms -type f -name "*, The*" | sort | while IFS= read -r filepath; do
 +      dir=$(dirname "$filepath")
 +      filename=$(basename "$filepath")
 +      if echo "$filename" | grep -qP '^\w.*\+.*[,] The '; then
 +          newname=$(echo "$filename" | sed 's/\(+ \)\(.*\), The \(.*\)/\1The \2 \3/')
 +      else
 +          newname=$(echo "$filename" | sed 's/^\(.*\), The \(.*\)$/The \1 \2/')
 +      fi
 +      echo "$dir | '$filename' -> '$newname'"
 +  done
 +</code>
  
-===== LMS PROD OPEN NEW TERMINAL =====+2. Execute renames: 
 +<code> 
 +  find /mnt/DOCS1/ROMs/Library/roms -type f -name "*, The*" | sort -u | while IFSread -r filepath; do 
 +      dir=$(dirname "$filepath"
 +      filename=$(basename "$filepath"
 +      # Special case: combo pack where ", The" belongs to a subtitle within the combo 
 +      if echo "$filename" | grep -qP '^\w.*\+.*[,] The '; then 
 +          newname=$(echo "$filename" | sed 's/\(+ \)\(.*\), The \(.*\)/\1The \2 \3/'
 +      else 
 +          newname=$(echo "$filename" | sed 's/^\(.*\), The \(.*\)$/The \1 \2/'
 +      fi 
 +      if [ "$filename" !"$newname" ]; then 
 +          mv -- "$filepath" "$dir/$newname" 
 +          echo "Renamed: $filename" 
 +      fi 
 +  done 
 +</code>
  
-gnome-terminal --geometry=157x54+0+0 --tab --command="ssh lms05.lms.ecu.edu.au" --tab --command="ssh lms07.lms.ecu.edu.au" --tab --command="ssh lms08.lms.ecu.edu.au" --tab --command="ssh lms10.lms.ecu.edu.au" --tab --command="ssh lms14.lms.ecu.edu.au" &+Key sed patterns:
  
 +  - Standard: s/^\(.*\), The \(.*\)$/The \1 \2/ — captures everything before , The  as \1 and everything after as \2, then prepends The
 +  - Combo pack: s/\(+ \)\(.*\), The \(.*\)/\1The \2 \3/ — moves The to before the subtitle within a +-delimited combo title
 +
 +===== RENAME 'A', 'An' ROMS =====
 +Dry-run preview:
 +<code>
 +  find /mnt/DOCS1/ROMs/Library/roms -type f \( -name "*, A *" -o -name "*, An *" \) | sort | while IFS= read -r filepath; do
 +      dir=$(dirname "$filepath")
 +      filename=$(basename "$filepath")
 +      newname=$(echo "$filename" | sed 's/^\(.*\), \(An\{0,1\}\) \(.*\)$/\2 \1 \3/')
 +      echo "'$filename'"
 +      echo "  -> '$newname'"
 +  done
 +</code>
 +
 +Execute renames:
 +<code>
 +  find /mnt/DOCS1/ROMs/Library/roms -type f \( -name "*, A *" -o -name "*, An *" \) | sort | while IFS= read -r filepath; do
 +      dir=$(dirname "$filepath")
 +      filename=$(basename "$filepath")
 +      newname=$(echo "$filename" | sed 's/^\(.*\), \(An\{0,1\}\) \(.*\)$/\2 \1 \3/')
 +      if [ "$filename" != "$newname" ]; then
 +          mv -- "$filepath" "$dir/$newname"
 +          echo "Renamed: '$filename' -> '$newname'"
 +      fi
 +  done
 +</code>
 +
 +Key sed pattern:
 +  - s/^\(.*\), \(An\{0,1\}\) \(.*\)$/\2 \1 \3/ — \(An\{0,1\}\) matches either A or An, captures it as \2, then reconstructs as \2 \1 \3
 +
 +
 +===== LMS PROD OPEN NEW TERMINAL =====
 +<code>
 +gnome-terminal --geometry=157x54+0+0 --tab --command="ssh lms05.lms.ecu.edu.au" --tab --command="ssh lms07.lms.ecu.edu.au" --tab --command="ssh lms08.lms.ecu.edu.au" --tab --command="ssh lms10.lms.ecu.edu.au" --tab --command="ssh lms14.lms.ecu.edu.au" &
 +</code>
  
 ===== RUN COMMAND AS ANOTHER USER ===== ===== RUN COMMAND AS ANOTHER USER =====
 +<code>
 # sudo -u zabbix /app/wcms/bin/webmonitor homepage_nocache # sudo -u zabbix /app/wcms/bin/webmonitor homepage_nocache
 +</code>
  
 ===== LIST LAST 5 RPMS INSTALLED ===== ===== LIST LAST 5 RPMS INSTALLED =====
 +<code>
 # rpm -qa --queryformat '%{installtime} (%{installtime:date}) %{name}\n' | sort -n | tail -5 # rpm -qa --queryformat '%{installtime} (%{installtime:date}) %{name}\n' | sort -n | tail -5
 +</code>
  
 ===== STRIP NON-DIRECTIVES FROM CONFIG ===== ===== STRIP NON-DIRECTIVES FROM CONFIG =====
 +<code>
 # egrep -v "^#|^$|[ ]*#" /etc/httpd.alt/conf/httpd.conf | less # egrep -v "^#|^$|[ ]*#" /etc/httpd.alt/conf/httpd.conf | less
 +</code>
  
 ===== FIND SEGFAULTS IN APACHE ERRORS SORTED BY DATE ===== ===== FIND SEGFAULTS IN APACHE ERRORS SORTED BY DATE =====
 +<code>
 # zcat /var/log/httpd/error_log.*.gz |grep Seg|sort -k2|less # zcat /var/log/httpd/error_log.*.gz |grep Seg|sort -k2|less
 # cat /var/log/httpd/error_log |grep Seg|sort -k2|less # cat /var/log/httpd/error_log |grep Seg|sort -k2|less
 +</code>
  
 ===== DISPLAY LIST OF LAST REBOOT ENTIRES ===== ===== DISPLAY LIST OF LAST REBOOT ENTIRES =====
 +<code>
 # last reboot | less # last reboot | less
 +</code>
  
 ===== CREATE SYMBOLIC LINKS ===== ===== CREATE SYMBOLIC LINKS =====
 +<code>
 # ln -s /app/wcms/bin/findroots /usr/local/bin/ # ln -s /app/wcms/bin/findroots /usr/local/bin/
 +</code>
  
 ===== LOGIN TO INTERNAL FIREWALL (from 139.230.244.) ===== ===== LOGIN TO INTERNAL FIREWALL (from 139.230.244.) =====
- +<code> 
-# telnet jogwint.net.ecu.edu.au 259+# telnet jogwint.net.ecu.edu.au 259</code>
  
 ===== READ SSH KEY PROPERTIES ===== ===== READ SSH KEY PROPERTIES =====
- +<code> 
-$ ssh-keygen -lf .ssh/id_rsa.pub+$ ssh-keygen -lf .ssh/id_rsa.pub</code>
  
 ===== SET PEAR TO USE PROXY ===== ===== SET PEAR TO USE PROXY =====
- +<code> 
-# pear config-set http_proxy http://bpm_applications:CRamge05@proxy.ecu.edu.au:80+# pear config-set http_proxy http://bpm_applications:CRamge05@proxy.ecu.edu.au:80</code>
  
 ===== SET PROXY ENV ===== ===== SET PROXY ENV =====
 +<code>
 # export http_proxy="http://bpm_applications:CRamge05@proxy.ecu.edu.au:80" # export http_proxy="http://bpm_applications:CRamge05@proxy.ecu.edu.au:80"
 +</code>
  
 ===== TAR CHECK ===== ===== TAR CHECK =====
- +<code> 
-# tar -ztvf ../../wcms.ecu/bak/ecu_3_20_3-2009-08-25_10-08-backup.tar.gz|grep .dump+# tar -ztvf ../../wcms.ecu/bak/ecu_3_20_3-2009-08-25_10-08-backup.tar.gz|grep .dump</code>
  
 ===== EXTRACT SINGLE FILE FROM TAR ===== ===== EXTRACT SINGLE FILE FROM TAR =====
- +<code> 
-$ tar -zxvf ../../wcms.ecu/bak/ecu_3_20_3-2009-08-25_13-56-backup.tar.gz ecu_3_20_3/wcmsqa-2009-08-25_13-56.dump+$ tar -zxvf ../../wcms.ecu/bak/ecu_3_20_3-2009-08-25_13-56-backup.tar.gz ecu_3_20_3/wcmsqa-2009-08-25_13-56.dump</code>
  
 ===== TAR WITH EXCLUDE ===== ===== TAR WITH EXCLUDE =====
 +<code>
 +cd /var/lib/docker/volumes/
 +tar --exclude='fw_stack_postgres-data/_data/backups/*.gz' -cvzf fw_stack_postgres-data_`date +%Y-%m-%dT%H-%M-%S`.tgz fw_stack_postgres-data/
 +rsync -av *.tgz /workspace/backups.kargath/volumes/
  
 $ tar cvzf filename.tar.gz /dir1/dir2 --exclude "/dir1/dir2/direxcluded" $ tar cvzf filename.tar.gz /dir1/dir2 --exclude "/dir1/dir2/direxcluded"
 +</code>
  
 ===== MOVE FOLDER INTO ANOTHER FOLDER ===== ===== MOVE FOLDER INTO ANOTHER FOLDER =====
- +<code> 
-# rsync -av CLT webarchive/+# rsync -av CLT webarchive/</code>
  
 ===== RSYNC to local desktop ===== ===== RSYNC to local desktop =====
 +<code>
 # rsync -avze ssh weekly/StaffDirLINUX sspaldin@10.31.66.91:/cygdrive/c/Users/sspaldin/Desktop # rsync -avze ssh weekly/StaffDirLINUX sspaldin@10.31.66.91:/cygdrive/c/Users/sspaldin/Desktop
-rsync -avze ssh  sspaldin@10.31.66.91:/cygdrive/c/Users/sspaldin/Desktop+rsync -avze ssh  sspaldin@10.31.66.91:/cygdrive/c/Users/sspaldin/Desktop</code>
  
 ===== RSYNC EXCLUDE ===== ===== RSYNC EXCLUDE =====
- +<code> 
-$ rsync -avze ssh --exclude 'cache' --exclude 'data' root@webcms-jo-app-prod01.cit.ecu.edu.au:/app/wcms/ecu_3_22_3/ .+$ rsync -avze ssh --exclude 'cache' --exclude 'data' root@webcms-jo-app-prod01.cit.ecu.edu.au:/app/wcms/ecu_3_22_3/ .</code>
  
 ===== RESTORE FILES FROM BACKUP ===== ===== RESTORE FILES FROM BACKUP =====
    
-# dsmc restore -inactive -pick /s02/vhosts/web01.ads.ecu.edu.au/htdocs/server/code/+# dsmc restore -inactive -pick /s02/vhosts/web01.ads.ecu.edu.au/htdocs/server/code/</code>
  
 ===== RESTORE FILES TO A DIFFERENT LOCATION ===== ===== RESTORE FILES TO A DIFFERENT LOCATION =====
 +<code>
 # dsmc restore -pick -inactive -todate=29-09-2009 "/s01/wcms/ecu_3_22_3/data/private/logs/*.lo*" /tmp/restore/ -preser=none # dsmc restore -pick -inactive -todate=29-09-2009 "/s01/wcms/ecu_3_22_3/data/private/logs/*.lo*" /tmp/restore/ -preser=none
  
 Note: symbolic links don't work Note: symbolic links don't work
 +</code>
  
 ===== SOSREPORT ===== ===== SOSREPORT =====
 +<code>
 # sosreport -k apache.log=on,cluster.gfslockdump=on,cluster.lockdump=on,devicemapper.lvmdump=on,general.syslogsize=on,kernel.modinfo=on,networking.traceroute=on,rpm.rpmva=on,yum.yumlist=on, # sosreport -k apache.log=on,cluster.gfslockdump=on,cluster.lockdump=on,devicemapper.lvmdump=on,general.syslogsize=on,kernel.modinfo=on,networking.traceroute=on,rpm.rpmva=on,yum.yumlist=on,
 +</code>
  
 ===== LIST PHP.INI ===== ===== LIST PHP.INI =====
 +<code>
 # grep -v "^;" /etc/php.ini | grep -v "^$" | less # grep -v "^;" /etc/php.ini | grep -v "^$" | less
 +</code>
  
 ===== LIST PACKAGES ===== ===== LIST PACKAGES =====
- +<code> 
-# rpm -qa |sort > /app/wcms.ecu/`hostname`-rpms.txt+# rpm -qa |sort > /app/wcms.ecu/`hostname`-rpms.txt</code>
  
 ===== LIST FILES IN PACKAGE ===== ===== LIST FILES IN PACKAGE =====
- +<code> 
-# rpm -ql httpd+# rpm -ql httpd</code>
  
 ===== LIST OPEN FILES, SORTED BY SIZE, OUTPUT TO DATED FILE ===== ===== LIST OPEN FILES, SORTED BY SIZE, OUTPUT TO DATED FILE =====
- +<code> 
-# lsof /s02 |sort -nr --key=7 |awk '{print $1,$2,$3,$7,$9}' >/tmp/lsof_s02_`date +%Y-%m-%dT%H-%M-%S`.txt+# lsof /s02 |sort -nr --key=7 |awk '{print $1,$2,$3,$7,$9}' >/tmp/lsof_s02_`date +%Y-%m-%dT%H-%M-%S`.txt</code>
  
 ===== WGET A PAGE SPECIFYING A HEADER AND OUTPUT FILE AND DISPLAYING HEADERS ===== ===== WGET A PAGE SPECIFYING A HEADER AND OUTPUT FILE AND DISPLAYING HEADERS =====
 +<code>
 # wget -S --no-cache --header "Host: www.ecu.edu.au" http://www.ecu.edu.au/ -O index.html # wget -S --no-cache --header "Host: www.ecu.edu.au" http://www.ecu.edu.au/ -O index.html
 +</code>
  
 ===== WATCH APACHE LOG FOR WARNINGS ===== ===== WATCH APACHE LOG FOR WARNINGS =====
- +<code> 
-# tail -f -n0 /var/log/httpd/error_log|grep warning+# tail -f -n0 /var/log/httpd/error_log|grep warning</code>
  
 ===== UNTAR SINGLE FILE/DIRECTORY ===== ===== UNTAR SINGLE FILE/DIRECTORY =====
 +<code>
 # tar -x ecu_3_28_5/data/private/conf/* -vzf ecu_3_28_5-2011-08-11_11-23-backup.tar.gz # tar -x ecu_3_28_5/data/private/conf/* -vzf ecu_3_28_5-2011-08-11_11-23-backup.tar.gz
 # tar -x ecu_3_28_5/core/lib/web/images/icons/asset_map/matrix_logo.gif -vzf ecu_3_28_5-2011-08-11_11-23-backup.tar.gz # tar -x ecu_3_28_5/core/lib/web/images/icons/asset_map/matrix_logo.gif -vzf ecu_3_28_5-2011-08-11_11-23-backup.tar.gz
 +</code>
 +
  
 +===== Source =====
 +commands.txt on Seagate 3TB (H:\Personal\BAK\WHD71610013\Documents\Documentation\commands.txt)
  
generic_linux_commands.1674020028.txt.gz · Last modified: by admin