% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  pdftitle={advanced-bash-techniques},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{advanced-bash-techniques}
\author{}
\date{}

\begin{document}
\maketitle

\hypertarget{advanced-bash-techniques}{%
\section{advanced-bash-techniques}\label{advanced-bash-techniques}}

\hypertarget{advanced-bash-techniques-1}{%
\section{advanced bash techniques}\label{advanced-bash-techniques-1}}

find and change all files

.. code-block:: bash

sudo find . -type f -print0 \textbar{} xargs -0 ls -hal

sudo find . -type f -print0 \textbar{} xargs -0 sudo chown
www-data:www-data

sudo find . -type f -print0 \textbar{} xargs -0 sudo chmod 0644

find and change all directories:

sudo find . -type d -print0 \textbar{} xargs -0 sudo chmod 0775

\hypertarget{remove-a-particular-line-from-all-files-in-a-directory}{%
\section{Remove a particular line from all files in a
directory}\label{remove-a-particular-line-from-all-files-in-a-directory}}

.. code-block:: bash

for file in /tmp/test/* do cp -p \$file \$file.tmp egrep -v
``RegexToRemove'' \$file.tmp \textgreater{} \$file rm -rf \$file.tmp
done

\hypertarget{apache-logs-count-unique-ip-addresses}{%
\section{apache logs count unique ip
addresses}\label{apache-logs-count-unique-ip-addresses}}

.. code-block:: bash

sudo cat access.log \textbar{} awk `\{ print \$1; \}' \textbar{} sort
\textbar{} uniq -c \textbar{} sort -n

\hypertarget{bash-perl-search-and-replace-multiple-files-one-liner}{%
\section{Bash Perl search and replace multiple files one
liner}\label{bash-perl-search-and-replace-multiple-files-one-liner}}

.. code-block:: perl

perl -pi -w -e `s/search/replace/g;' *.extension

explanation:

\textbf{-e} means execute the following line of code.

\textbf{-i} means edit in-place

\textbf{-w} write warnings

\textbf{-p} loop

\hypertarget{bash-sed-search-and-replace-multiple-files-one-liner}{%
\section{Bash sed search and replace multiple files one
liner}\label{bash-sed-search-and-replace-multiple-files-one-liner}}

.. code-block:: sed

sed -i'\,' -e `s/search/replace/g' *

\hypertarget{get-a-coma-separated-list-of-libvirt-guests}{%
\section{Get a coma separated list of libvirt
guests}\label{get-a-coma-separated-list-of-libvirt-guests}}

.. code-block:: bash

virsh list \textbar{} egrep -v
`Domain\textbar Name\textbar----\textbar\^{}\$' \textbar{} awk `\{printf
``\%s,'' , \$2\}' \textgreater{} /tmp/virthosts

\end{document}
