Jump to content

Linux

From Costa's Wiki
Revision as of 06:43, 6 December 2022 by 172.17.0.1 (talk)
Copy directories without content
rsync -av -f"+ */" -f"- *" "$source" "$target"
Find files
find /path/to/dir -type f -name "*" -newermt 2013-02-07 ! -newermt 2013-02-08
find $HOME/projects -type f -name "*.py" -newermt 2013-02-07 ! -newermt 2013-02-08 -print
find $HOME/projects -type f -name "*.py" -newermt 2013-02-07 ! -newermt 2013-02-08 -ls
Delete Files older Than
find /var/log -name "*.log" -type f -mtime +30 -delete 
find /var/log -type d -mtime +30 -exec rm -rf {} \;
How to print a file, excluding comments and blank lines, using grep
grep -v '^$\|^#\|^\s*\#' filename | grep -v "^[[:space:]]*$" | more
grep -v "^[[:space:]]*$\|^ *#" filename 
bash operations with file with spaces in name
IFS=$(echo -en "\n\b"); for i in $(ls -d */ | cut -f1 -d'/'); do echo $i; done
IFS=$(echo -en "\n\b"); for i in $(ls -d */ | cut -f1 -d'/'); do echo "$i;"| tr -d '\r\n'; find $i -type f | wc -l; done
ssh automation
ssh -i /usr/local/sbin/id_rsa -oStrictHostKeyChecking=no [email protected] 'upsc qnapups'
-i RSA key, -o add to known host automatically
ls with full path
ls -dl $PWD/*
Set date of directories by latest file inside
IFS=$(echo -en "\n\b"); for d in */ ; do T=`ls -alt --time-style="+%Y%m%d0101.10" $d | tail -1 | awk '{print $6}'`; touch -t $T $d; done
Audiofile operations
LVM operations
SSL Certificate with SAN