Skip to content

Instantly share code, notes, and snippets.

@tserj
Last active May 30, 2024 10:13
Show Gist options
  • Select an option

  • Save tserj/4500bd35137629a4f17f1a2b978a0df4 to your computer and use it in GitHub Desktop.

Select an option

Save tserj/4500bd35137629a4f17f1a2b978a0df4 to your computer and use it in GitHub Desktop.
Linux help
Show file in HEX and text view (as old dos navigator, norton commander, etc..)
hexdump -C file.name
Simple local server running on port 8000 within home dir:
python -m SimpleHTTPServer
Check graphic driver info: inxi -Gx
IP addres parsing: /sbin/ifconfig wlp2s0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'
Check difference on 2 text files:
diff newfiles oldfiles | grep \< | awk '{print $2}' > insertedfiles
diff newfiles oldfiles | grep \> | awk '{print $2}' > deletedfiles
Perform operation for each file in directory:
for f in utils_files/*; do echo $f;
Convert site source files from cp1251 to UTF-8:
for f in $(find . -type f \( -iname "*.php" -o -iname "*.pda" -o -iname "*.sql" -o -iname "*.js" -o -iname "*.css" -o -iname "*.inc" -o -iname "*.txt" \)); \
do iconv -f cp1251 -t UTF8 $f -o tmpfile && mv tmpfile $f; done
delete all CVS directories recursive:
find . -depth -type d -name "CVS" -prune -exec rm -rf {} ';'
ag searcher:
sudo apt install silversearcher-ag
It works closely with Git and other VCS. So you won't get anything in a .git or .ignore directory.
ag -ia "Search query"
Show DNS requests:
tcpdump -i eth0 arp
or
tcpdump -vvv -n -i eth0 dst port 53
треды процесса: top -H -p 29717
/usr/java/jdk1.5.0_12/bin/jstack -m 29738
cat /etc/redhat-release
cat /proc/cpuinfo | grep processor | wc -l
nohup rsync -av /CT/content/ [email protected]:/CT/content . &
scp unpack.sh [email protected]:/apps/path
sftp -oPort=443 [email protected] (cd, put, get)
check init script:
more /etc/rc.d/startup.sh
more /etc/init.d/apache2
просмотр имен в архиве:
cd /CT;
tar -ztvf 2013i07_20130731.tar.gz | grep "00861608"
просмотр имен в архивах папки:
cd /CT; for f in ./*.tar.gz; do tar -ztvf $f 2>/dev/null | grep "010664"; done
просмотр имен в архивах папки и вывод названия архива:
cd /CT; for f in ./*.tar.gz; do tar -ztvf $f 2>/dev/null | grep -q "002067" && echo $f; done
вывод кол-ва файлов в архивах папки:
cd /CT; for f in ./*.tar.gz; do tar -ztvf $f 2>/dev/null | grep -c ^- && printf "into: $f\n\n"; done
просмотр содержимого архива, без распаковки:
tar -tzf filename.tar.gz
найти текст во всех xml в папке:
grep --include=\*.xml -rnw '.' -e "TAGWITH=\"NEW\""
найти текст в файле по маске в папке:
grep --include=\*.{c,h} -rnw 'directory' -e "pattern" где -r is recursive, -n is line number and -w stands match the whole word.
grep --include=\*.txt -rnw '/CT' -e "00906795"
// найти текст во всех xml в папке - поиск clStatus отличных от языка en:
grep --include=\*.xml -rnw '.' -e "title xml:lang=\"..\" type=\"clStatus\"" | grep -v "en"
подсчитать кол-во определенного тега в XML в tar.gz:
распаковать архив только для конкретных файлов tar -zxvf 20170320.tar.gz --wildcards --no-anchored '*.xml'
составить список файлов из тега grep --include=\*.xml -rnw '/CT' -e "<span type=\"citationLinkGroup\">" > find.txt
найти уники cat find.txt | sed 's#\:.\+##' | sort -u > result.txt
показать только файлы и линки:
ls -p | grep -v /
показать только линки:
ls -la | grep ^l
показать кол-во директорий:
ls -d */ | wc -l
поиск файла в папках превиусов:
find /CT -path "*/rel000*/some/*?/000521.xml"
Запаковка всех файлов в текущей директории в tar.gz (без удаления исходных файлов):
tar cvf - * | gzip > backup_2014_10_31.tar.gz
Сбор картинок с сайта по маске:
for (( i = 2016; i <= 9999 ; i++ ))
do
wget http://somesite.com/img1/$i.jpg
done
********************** или с учетом 404 от wget
threshold=0
for x in {90..110}; do
wget 'http://www.iqandreas.com/sample-images/100-100-color/'$x'.jpg'
wgetreturn=$?
if [[ $wgetreturn -ne 0 ]]; then
threshold=$(($threshold+$wgetreturn))
if [[ $threshold -eq 16 ]]; then
break
fi
fi
done
добавление сертификата в Java keystore для https связи:
-Djavax.net.debug=all flag to enable debugging of the SSL connection
1. зайти по ссылке на https сервис с скачать сертификат
2. положить его на {JAVA_HOME}/jre/lib/security/ и перейти в папку
3. {JAVA_HOME}/bin/ keytool -import -v -trustcacerts -keystore truststore.ks -alias ALIASNAME -file CERT [password is abc123]
4. проверить: keytool -list -keystore truststore.ks находясь в папке {JAVA_HOME}/jre/lib/security/
5. удалить старый: keytool -delete -v -trustcacerts -keystore truststore.ks -alias ALIASNAME находясь в папке {JAVA_HOME}/jre/lib/security/
Replace substrings in file and keep original file with .bak extension:
sed -i.bak "s/<label>/<title>/g ; s/<\/label>/<\/title>/g" 0001544X.xml
-- auth with keys *************** :
Don't use a password. Generate a passphraseless SSH key and push it to your VM.
If you already have an SSH key, you can skip this step… Just hit Enter for the key and both passphrases:
$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
Copy your keys to the target server:
$ ssh-copy-id -i id@server
id@server's password:
ssh-add - магия)
Now try logging into the machine, with ssh 'id@server', and check in:
.ssh/authorized_keys
to make sure we haven’t added extra keys that you weren’t expecting.
Finally check logging in…
$ ssh id@server
id@server:~$
You may also want to look into using ssh-agent if you want to try keeping your keys protected with a passphrase.
*********************************************
локальный туннель (проброс портов с сервера на локальную машину):
ssh [email protected] -L 1463:localhost:9090 -N
постоянный прокси (исполнять на сервере):
ssh -D 9000 localhost -g (socks 5 proxy - окно сессии не должно закрываться)
распаковка бекапа в текущую папку без удаления архива: gzip -dc 20140128_1390909386426.tar.gz | tar xf -
кол-во артиклов в папке: find . -type d -name 'CN-*' |wc -l
# Remove if file exist
if [ -f /etc/yum.repos.d/plesk.repo ] ; then
rm -f /etc/yum.repos.d/plesk.repo
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment