-
Notifications
You must be signed in to change notification settings - Fork 2
/
0_scripts.r
3298 lines (2382 loc) · 99 KB
/
0_scripts.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## Script.r - Greats commands for day life ##
#
# Autor= João Batista Ribeiro
# Bugs, Agradecimentos, Críticas "construtivas"
# me envie um e-mail. Ficarei Grato!
# e-mail: joao42lbatista@gmail.com
#
# Last update: 30/10/2024
#
## Process with more CPU use
ps aux --sort=-pcpu | head -n 11
watch -n1 -e 'ps aux --sort=-pcpu | head -n 11'
## Process with more memory (RAM) use
ps aux --sort -rss | head -n 11
watch -n1 -e 'ps aux --sort -rss | head -n 11'
## Print a process tree
pstree
## Compile C with warning and extras
gcc -Wall -Wextra -Wpedantic -O3 -ansi -std=c99 prog.c -o prog.out
# O std pode ser c99 ou c11, para c17 e c18 vai precisar do GCC atual. Leia mais sobre:
# https://fig.if.usp.br/~esdobay/c/gcc.html
# https://linux.ime.usp.br/~lucasmmg/livecd/documentacao/documentos/terminal/Compilando_um_arquivo_em_C.html
## Generate assembly code from C/C++ code, helloworld.s
gcc -S helloworld.c
## See online
https://godbolt.org/
## Display assembly code form one executable C
objdump -S prog.out
## Disable KDE Wallet (KWALLET) Pop-ups in Chromium, Google Chrome and Opera
# for not pop-up every time you open them added in the end of file
nano ~/.kde/share/config/kwalletrc
[Auto Deny]
kdewallet=Chromium,Opera,Chrome
# Save and exit the file. Log out and back in again for the changes to take effect,
# or simply enter the following into the terminal:
killall -9 kwalletd
## Compactar/Descompactar arquivos/pastas para zip, rar, tar, tar.gz, tar.bz2 e bz2 pelo terminal
## zip
## Compactar
zip arquivo.zip arquivo
zip -r pasta.zip pasta/
## zip files with a size limit
zip -s 10m archive.zip archive
zip -r -s 400m archive.zip directory/
## Compress Speed
(-0, -1, -2, -3, -4, -5, -6, -7, -8, -9)
Regulate the speed of compression using the specified digit #,
where -0 indicates no compression (store all files),
-1 indicates the fastest compression speed (less compression)
and -9 indicates the slowest compression
speed (optimal compression, ignores the suffix list). The default compression level is -6
zip -1 -r -s 400m archive.zip directory/
## Convert a split archive to a single-file archive, first "unsplit"
zip -s 0 archive.zip --out unsplit.zip
## Then you unzip the unsplit file:
unzip unsplit.zip
## Descompactar
unzip arquivo.zip
## rar
## Compactar
rar a arquivo.rar arquivo
rar a pasta.rar pasta/
## Descompactar
unrar x arquivo.rar
## tar
## Compactar # c
tar -cf arquivo.tar arquivo
## f pasta/folder
tar -cvf pasta.tar pasta/
## Descompactar # x
tar -xvf arquivo.tar
## tar.gz # -z, --gzip
## Compactar
tar -zcf arquivo.tar.gz arquivo
tar -zcvf pasta.tar.gz pasta/
## Descompactar
tar -zxvf arquivo.tar.gz
## tar.bz2 e bz2 # -j, --bzip2
## Compactar
tar -jcv arquivo.tar.bz2 arquivo
tar -jcvf pasta.tar.bz2 pasta/
## Descompactar
tar -jxvf arquivo.tar.bz2
## echo shell commands as they are executed
set -x : expands variables and prints a little + sign before the line
set -v : does not expand the variables before printing
## To turn off use + instead -
set +x - set +v
## Simples online multicore CPU benchmarking service
https://silver.urih.com/
## Wi-Fi connect on terminal with NetworkManager
nmtui
## NetworkManager - files with config and passwords
/etc/NetworkManager/system-connections/
## man
man man - format and display the on-line manual pages
-f, --whatis
Equivalent to whatis - display one-line manual page descriptions
man -f ip
whatis ip
man -f gets - search in the manual pages gets
gets (3) - get a string from standard input (DEPRECATED)
gets (n) - Read a line from a channel
-k, --apropos
Equivalent to apropos - search the manual page names and descriptions
apropos ip
man -k ip
-K, --global-apropos
Search for text in all manual pages
man -K ip
man units - decimal and binary prefixes
man url - uniform resource identifier (URI)
man UTF-8 - an ASCII compatible multibyte Unicode encoding
man arp - manipulate the system ARP cache
man boot - System bootup process based on UNIX System V Release 4
man 7 ip - Linux IPv4 protocol implementation
man charsets - character set standards and internationalization
man gittutorial - A tutorial introduction to Git
man gittutorial-2 - A tutorial introduction to Git: part two
man gitglossary - A Git Glossary
man git-commit - Record changes to the repository
man git-status - Show the working tree status
man git-add - Add file contents to the index
man 7 glob - globbing pathnames
man hier - description of the filesystem hierarchy
man inode - file inode information
man 7 time - overview of time and timers
man tcp - TCP protocol
man udp - User Datagram Protocol for IPv4
man 1 printf - format and print data
man system - execute a shell command
man for - 'For' loop
man while - Execute script repeatedly as long as a condition is met
man if - "use" a Perl module if a condition holds (also can "no" a module)
man syscalls
## C Language
man ascii - ASCII character set encoded in octal, decimal, and hexadecimal
man 3 stdio - standard input/output library functions
man 3 string - stpcpy, strcat, strcmp, strcpy, strlen ... - string operations
man 3 printf - printf, fprintf ... - formatted output conversion
man 3 scanf - scanf, fscanf ... - input format conversion
man 3 gets - get a string from standard input (DEPRECATED)
## Never use this function.
man 7 standards
## Slackware update
Select a mirror in /etc/slackpkg/mirrors removing the "#" in the line
slackpkg update gpg # only once or when change mirror
slackpkg update
slackpkg install-new
slackpkg upgrade-all
## Convert rpm to txz with tags
rpm2txz -d -c -r program.rpm
## Argumentos em Shell Scripts
$0 - Identifica o comando emitido
$@ - O conjunto dos argumentos
$* - Relação dos argumentos fornecidos
$# - Número de argumentos fornecidos
$? - Código de retorno do último comando executado
$$ - Número (pid) de identificação do processo
$! - Identificação (pid) do último processo executado em background
## Start app and after kill the process
app &
PID_APP=$!
kill -9 $PID_APP
## Run chmod recursively only in directories
find /path/to/base/dir -type d -exec chmod 744 {} +
## Run chmod recursively only in files
find /path/to/base/dir -type f -exec chmod 644 {} +
## Reduce all PDF files in the folder, using usual_JBs.sh script
# All reduce types (1, 2 and 3) with links
IFS=$(echo -en "\n\b"); for file in $(ls *.pdf); do echo $file; usual_JBs.sh pdf-r $file 4 y; done
# All reduce types (1, 2 and 3) without links
IFS=$(echo -en "\n\b"); for file in $(ls *.pdf); do echo $file; usual_JBs.sh pdf-r $file 4 n; done
# Reduce type 1 with links
IFS=$(echo -en "\n\b"); for file in $(ls *.pdf); do echo $file; usual_JBs.sh pdf-r $file 1 y; done
## Rename the files - remove "_r2ly", "_r3ln" etc
IFS=$(echo -en "\n\b"); for file in $(ls *pdf); do echo $file; mv "$file" "${file::-9}.pdf"; done
## Delete all the "reduce files" generated
# To see
ls *_r?l?.pdf
## To delete
rm *_r?l?.pdf
## Manipulação de nomes e caminhos de arquivos
## Retorna o último nome após o último /
basename /usr/local/bin/gzip
gzip
basename ver/pdf/file.pdf
file.pdf
## Retorna como resultado o caminho inteiro fornecido
dirname /usr/local/bin/gzip
/usr/local/bin
dirname ver/pdf/file.pdf
ver/pdf
## Best way to unplug a USB external hard-drive after proper unmounting
udisks --detach /dev/sdX
## sed add text in begin of file
sed -i '1s/^/task goes here\n/' todo.txt
## Or
sed -i '1itask goes here' todo.txt
## sed add ' in the begin
echo "abc" | sed 's/^/'/'
'abc
## sed add .mp3 in the end
echo "abc" | sed 's/$/.mp3/'
abc.mp3
## sed duplicate text in a line
echo "abc d efg" | sed 's/.*/& &/'
abc d efg abc d efg
## Rename a Linux network interface without Udev/Reboot
## eth1 to eth0
ifconfig eth1 down
ip link set eth1 name eth0
ifconfig eth0 up
## wlan0 to wlan1
ifconfig wlan1 down
ip link set wlan1 name wlan0
ifconfig wlan0 up
## Utilizando caracteres e acentuação da língua portuguesa
#include <locale.h> // Necessário para usar setlocale
int main(){
setlocale(LC_ALL,""); // Alterando para o padrão do sistema operacional
...
}
## Default 64 bits configure
./configure --prefix=/usr --libdir=/usr/lib64 --sysconfdir=/etc
## Redireciona os erros para erros.txt
comando 2> erros.txt
## Redireciona a saída padrão para saida.txt
comando > saida.txt
comando 1> saida.txt
## Redireciona a saída padrão e os erros para o mesmo arquivo (saida_e_erros.log)
comando &> saida_e_erros.log
## Suprime a exibição de mensagens de erro. Útil quando as mensagens de erro não nos interessam
comando 2>&- saida.log
## Envia todas as mensagens de erro para a tela e a saída do comando para o arquivo saida.log
# Útil em shell scripts quando precisamos enviar os erros para a tela
comando 2>&1 saida.log
## Enviar a saída e erros para arquivos arquivos diferentes
comando 1> saida.log 2> erros.log
## Linux BIOS information
dmidecode
dmidecode --type bios
## Summary
for i in baseboard-manufacturer system-version system-product-name chassis-type \
system-serial-number bios-release-date bios-version; do
echo "$i : $(dmidecode -s $i)"
done
## memory info - RAM info
# Speed
dmidecode -t 17
# Maximum Capacity
dmidecode -t 16
# All
dmidecode -t memory
## Dolphin (re)enable warning message dialog before Empty Trash
nano ~/.config/kiorc
ConfirmEmptyTrash=false
> true
# Old location
nano ~/.kde/share/config/kiorc
## ASUS keyboard retro light
# https://forum.kde.org/viewtopic.php?f=63&t=121045
## Load the module (asus-nb-wmi) if not load
# lsmod | grep "asus"
echo "modprobe asus-nb-wmi" >> /etc/rc.d/rc.local
## With root - VALUE - 0 to 3 (0 off, 3 max)
echo VALUE > /sys/class/leds/asus\:\:kbd_backlight/brightness
## without root - VALUE - 0 to 3 (0 off, 3 max)
dbus-send --type=method_call --print-reply=literal --system --dest='org.freedesktop.UPower' \
'/org/freedesktop/UPower/KbdBacklight' 'org.freedesktop.UPower.KbdBacklight.SetBrightness' "int32:VALUE"
## Get current brightness
dbus-send --type=method_call --print-reply=literal --system --dest='org.freedesktop.UPower' \
'/org/freedesktop/UPower/KbdBacklight' 'org.freedesktop.UPower.KbdBacklight.GetBrightness'
## Or
cat /sys/class/leds/asus\:\:kbd_backlight/brightness
## If KDE not "found" the keyboard retro light, "start" UPower
echo "qdbus --system org.freedesktop.UPower" >> /etc/rc.d/rc.local
## And reload the shortcut keys
System Setting > Shortcuts and Gestures > Global Keyboard Shortcuts
KDE component: KDE Daemon
Reset the "Decrease Keyboard Brightness" and "Increase Keyboard Brightness"
## NTFS error
## mount exited with exit code 13: $MFTMirr does not match $MFT (record ..
## or mount NTFS as only read mode
ntfsfix /dev/sdXX
## Dolphin freezing when delete file and/or clean the trash (If you use VLC)
## 32 bits or distro with work only with /usr/lib/
/usr/lib/vlc/vlc-cache-gen -f /usr/lib/vlc/plugins
## 64 bits
/usr/lib64/vlc/vlc-cache-gen -f /usr/lib64/vlc/plugins
## Select URL from a text (or html file)
sed -n 's/.*href="\([^"]*\).*/\1/p'
grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*"
grep -o 'http[^"]*'
## How long ago a Linux system was installed? - Day that the system was installed
ls -alct / | tail -1
# or
ls -alct / | tail -1 | awk '{print $6, $7, $8}'
## Count occurrences of a char in a string
needle=","
var="text,text,text,text"
numberOccurrences=$(grep -o "$needle" <<< "$var" | wc -l)
## Shell script read value from pipe
tmpFile=`mktemp` # Temp file if was used a pipe (|)
cat > $tmpFile # Write the pipe content a tmp file
exec </dev/tty >/dev/tty # Set input back to default (keyboard)
sizeTmpFile=`ls -l $tmpFile | cut -d ' ' -f5` # tmpFile size
if [ "$sizeTmpFile" -gt '0' ]; then
fileName=$tmpFile
else
fileName=$1
fi
if [ "$fileName" == '' ]; then
echo "Error - need pass the file name to grep"
else
#...commands...
fi
# ...
# Don't forget of delete the tmp file
rm $tmpFile # Delete the tmpFile
## sboinstall with pkgtype txz instead tgz (Takes up less disk space)
PKGTYPE=txz sboinstall -i program
## Audio output in the HDMI
pavucontrol
> in the tab "Configuration"
> in "Profile" Select "HDMI Output"
## Clean-up movie.mkv file (remove name in the tracks and chapters)
## Remove the Name of movie, track audio a1, track video a1 and track subtitle s1
mkvpropedit -e info -s title= -e track:a1 -s name= -e track:v1 -s name= -e track:s1 -s language=en -s name= movie.mkv
## Remove chapters
mkvpropedit --chapters '' movie.mkv
## Set language English to track audio a1, video v1, and subtitle s1
mkvpropedit -e info -s title= -e track:a1 -s name= language=en -e track:v1 -s name= language=en -e track:s1 -s language=en movie.mkv
## Set audio (a2) as default (a1 flag-default=0), video (v1) with language jpn, subtitle (s1) with language pt and as default
mkvpropedit -e track:a1 -s flag-default=0 -e track:a2 -s flag-default=1 -e track:v1 -s language=jpn -e track:s1 -s language=pt -s flag-default=1 movie.mkv
## auto with one file mkv in the folder
i=$(ls *.mkv); mkvpropedit -e info -s title= -e track:a1 -s name= -e track:v1 -s name= -e track:s1 -s language=en -s name= $i
## Manual
https://mkvtoolnix.download/doc/mkvpropedit.html
## Use the Unofficial Bash Strict Mode (Unless You Love Debugging)
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
## Option instructs bash to immediately exit if any command has a non-zero exit status
set -e
## When set, a reference to any variable you haven't previously defined is an error, and causes the program to immediately exit
set -u
## If any command in a pipeline fails, that return code will be used as the return code of the whole pipeline
# By default, the pipeline's return code is that of the last command - even if it succeeds
set -o pipefail
## link: http://redsymbol.net/articles/unofficial-bash-strict-mode/
## File associations in KDE/Plasma
KDE stores its mimetype mappings in:
~/.local/share/applications/mimeapps.list
You can also change these associations with the kcmshell4 tool (see also):
kcmshell4 filetypes
## Senha do Kindle esquecida
Se você não se lembra da senha do seu Kindle, você precisará redefinir seu dispositivo,
o que removerá todas as suas informações pessoais e conteúdo baixado
Qualquer conteúdo que você tenha comprado na Amazon é automaticamente salvo na Nuvem e
pode ser novamente baixado da aba Tudo ao registrar seu Kindle na sua conta novamente
## Para redefinir seu dispositivo:
Toque no campo de senha para exibir o teclado virtual
Digite 111222777 e toque em OK. Seu Kindle será reiniciado
## GhostScript - Reduzindo o tamanho de arquivos PDF pelo terminal
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dNOPAUSE -dBATCH -sOutputFile=novo.pdf velho.pdf
# or
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -sOutputFile=novo.pdf velho.pdf
Onde novo.pdf é o novo arquivo que será criado e velho.pdf é o antigo, o grande
gs :: Ou GhostScript, um interpretador e visualizador de arquivos PS e PDF
-sDEVICE :: Determina o dispositivo de saída do comando
Como estamos gerando um arquivo PDF, usaremos o dispositivo built-in pdfwrite
-dCompatibilityLevel :: Determina o nível de compatibilidade do PDF
Neste caso o level 1.3 é compatível com o Acrobat Reader 3 ou superior
Level 1.4 por exemplo já seria compatível apenas com Acrobat Reader 5 ou superior
-dNOPAUSE :: Desabilita o prompt (pausa) ao final de cada página processada
-dBATCH :: Processamento em batch. Caso omita esta opção, após o processamento você cairá no interpretador gs
e precisará digitar "quit" para sair
## Get the users normal users
cat /etc/passwd | grep -vE "nologin|ftp" | grep home | awk -F':' '{ print $1}'
# or
cat /etc/passwd | awk -F: '$3 > 499 {print $1}'
# or
awk -F ':' '$3 > 499 {print $1}' /etc/passwd
# test
user_normal=`awk -F ':' '$3 > 499 {print $1}' /etc/passwd`
ls /home/$user_normal
## KDE link open as file:///var/tmp/kdecache...
Edit in the "System Settings" the "Default Applications" - "Web Browser" and set the path to the browser as "/usr/bin/firefox"
## Rename UPPERCASE to lowercase
## Only local folder
IFS=$(echo -en "\n\b"); for i in $( ls | grep [A-Z] ); do mv -i "$i" `echo "$i" | tr 'A-Z' 'a-z'`; done
## Recursive
IFS=$(echo -en "\n\b"); for i in $( find . | grep [A-Z] ); do mv -i "$i" `echo "$i" | tr 'A-Z' 'a-z'`; done
## Auto-logout do terminal
TMOUT=300
# Time in seconds
## Iniciar o Dropbox no KDE com ícone de notificações (system tray icon)
dbus-launch ../dropboxd
## Clean env | limpar variaveis setadas incialmente no ambiente
unset $(/usr/bin/env | egrep '^(\w+)=(.*)$' | egrep -vw 'PWD|USER|LANG' | /usr/bin/cut -d= -f1);
## or
unset $(env | grep -o '^[_[:alpha:]][_[:alnum:]]*' | grep -v -E '^PWD$|^USER$|^TERM$|^SSH_.*|^LC_.*')
## Video para mp3
mplayer -dumpaudio arquivo_video.mp4 -dumpfile arquivo_audio.mp3
## Run "usual_JBs.sh pdf-r file.pdf" for all file in a directory
IFS=$(echo -en "\n\b"); for file in $(ls -1); do echo "1 $file"; usual_JBs.sh pdf-r "$file" 4; done
## Assinar o PDF - Sign the PDF
1 Tire uma boa foto da sua assinatura (assine em um papel branco com uma caneta azul ou preta)
2 Remova o fundo branco da imagem (png e adicione o canal alpha no Gimp)
3 "Assine o PDF" inserindo a imagem onde deveria assinar utilizando Master PDF Editor (ou outro editor de PDF)
4 Abra o PDF com a assinatura no Opera (ou outro navegador com suporte) e imprima o arquivo como imagem
## Size of a directory/folder on the command line
du -sh
## Or
du -sh folder
# -s, --summarize display only a total for each argument
# -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
## Combinar dois arquivos de texto em duas colunas "arq1 arq2"
paste file1.txt file2.txt > fileFinal.txt
## Format USB to FAT 32
## Create the partition with the type FAT 32
# Change sdX to correct drive
cfdisk /dev/sdX
## Or
fdisk /dev/sdX
## Format the new partition to FAT 32
mkfs.fat -F 32 -I /dev/sdX1
## Run wget with download limit rate
wget -c link -O filename_save.extension --limit-rate=200000 # (195KB/s)
## wget show website in terminal
wget -O - slackware.com
## Descobrir a placa-mãe sem programa
## Windows - CMD
wmic baseboard get product,manufacturer
## Gnu/Linux - terminal as root
dmidecode | more
## Procure por "Base Board Information"
digite /Base
## man search
Use ctrl + f or /
n - next match or
shift + n - previous match
## To get an ASCII man page file, without the annoying backspace/underscore attempts at underlining,
# Weird sequences to do bolding:
# man comand_to_get | col -b > comand_to_get.txt
man ksh | col -b > ksh.txt
## Enable ssh X11 on Slackware
## The remote server need GUI and that GUI need to be up
## To connect
ssh -X user@ip
## Added in /etc/ssh/sshd_config
X11Forwarding yes
## Restart the ssh service
/etc/rc.d/rc.sshd restart
## Exit from this connection
## Before connect again, to enable the access to any user to GUI
xhost +
## To connect
ssh -X user@ip
## or
ssh -Y user@ip
ssh -Y root@192.168.0.42
## To see connections in the Konsole (look to the IP)
w
## To use the display remote
export DISPLAY=:0.0
## To use the display local
export DISPLAY=ip_local_host:0.0
export DISPLAY=192.168.0.13:0.0
## To test the display
xclock &
## Access ssh X11 on Windows
## Add in the remote server in /etc/ssh/sshd_config # To anothers OS /etc/ssh/sshd_config
X11Forwarding yes
## Download and Install full Xming-fonts and Xming
https://sourceforge.net/projects/xming/files/?source=navbar
## Change the shortcut to start Xming. Right click your mouse to go to properties.
Add -ac to your XMing shortcut:
"C:\Program Files\Xming\Xming.exe" :0 -clipboard -multiwindow -ac
## Start XMing
## Download putty
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
## Configure putty
In Session: Add the IP and port to remote server
In Connection >> SSH >> X11: Mark Enable X11 Forwarding, set the display to: localhost:0
and protocol to MTI-Magic-Cokie-1
## Connect on the putty - export the display
export DISPLAY=192.168.0.13:0.0
## Test the display
xclock &
## Warning packages removed Slackware
removepkg *z | grep -E "WARNING|Removing package"
TMPFILE=`mktemp`; removepkg *z | tee $TMPFILE; echo -e "\n\n\t$TMPFILE\n"; cat $TMPFILE | grep -E "WARNING|Removing package"
## Remove the file after?
rm $TMPFILE
## Searh for a file /var/log/packages/*
grep "/vlc$" /var/log/packages/*
## Count files in the folder
countFiles=`ls -la | cat -n | tail -n 1 | awk '{print $1}'`; echo "Count files in this folder: $countFiles"
## Count files of one type in the folder
fileType=mp3; countFiles=`ls -la *$fileType| cat -n | tail -n 1 | awk '{print $1}'`; echo "Count files in this folder: $countFiles"
## Extract audio from video file and convert to MP3
## audio 0
ffmpeg -i file.mkv -map 0:a:0 audio0.mp3
## audio 1
ffmpeg -i file.mkv -map 0:a:1 audio1.mp3
## Check file (convert), set correctly duration
lame audio0.mp3 audio01.mp3
## Reduce video size
ffmpeg -i inVideo.mp4 outVideo.mp4
## Convert video
ffmpeg -i inVideo.avi outVideo.mp4
## Convert inVideo.mkv to outVideo.mp4 - with copy of codec
ffmpeg -i inVideo.mkv -codec copy outVideo.mp4
## Convert all file .mp4 to .mkv - with copy of codec
for file in *.mp4; do ffmpeg -i "$file" -codec copy "${file::-2}kv"; done
## Convert entire playlist from flac, oog, flac to mp3
## 320 k
for f in *.flac , *.m4a , *.ogg ; do ffmpeg -i "$f" -ab 320k "${f%.m4a}.mp3"; done
## normal (small files)
for f in *.flac , *.m4a , *.ogg ; do ffmpeg -i "$f" "${f%.m4a}.mp3"; done
## Convert ogg to mp3 with ffmpeg
for file in $(ls *.ogg); do echo $file; ffmpeg -i ${file} -acodec libmp3lame ${file::-4}.mp3; done
## Rename several file adding some parte
# file_output.txt => f; ${f:2} => le_output.txt; ${f::-4} => file_output
## Test
for f in *"(128kbit_AAC).mp3" ; do echo "${f::-18}".mp3; done
## Run
for f in *"(128kbit_AAC).mp3" ; do mv "$f" "${f::-18}".mp3; done
## Remove part of the name of files
## To remove extra.test
rename "extra.test" "" *
## pdf to txt - need poppler package
pdftotext input.pdf output.txt
## Or with -layout to keep the layout
pdftotext -layout input.pdf output.txt
## sed - delete/remove and replace values
## Replace/remove multiple empty line with one empty line
sed '/^$/N;/^\n$/D' inputfile
## Remove all empty lines
sed -r '/^\s*$/d' inputfile
## Delete empty lines
sed '/^$/d' file
## Delete lines by line number
echo -e "a\nb\nc\nd\ne" | sed -e{1,3}d
## Change value for new line
sed 's/value/\n---\n/g'
## Remove the last n lines of a file - Print with the last 4 lines
#Need the - in > head -n -
head -n -4 file.txt
## Remove new line (\n) for one space
echo -e "\n\n\noi\n\n\ncomo\n\n\nv\nai" | sed ':a;N;$!ba;s/\n/ /g'
# or
tr '\r\n' ' '
## Remove new line (\n)
echo -e "\n\n\noi\n\n\ncomo\n\n\nv\nai" | sed ':a;N;$!ba;s/\n//g'
## Or
tr -d '\n'
## sed change value (TV) to (tv)
echo "TV" | sed 's/TV/tv/g'
## sed "grep" number
echo "awsafd 1.2.4" | sed 's/[^0-9]*//g'
## sed "grep" number and dot
echo "awsafd 1.2.4" | sed 's/[^0-9,.]*//g'
## sed troca \n por nova linha
sed 's/\\n/\n/g'
## RedShift GUI Error
sed -i 's/|/,/g' ~/.redshiftgrc
## Remove all possible spaces at the end of the line
sed 's/ *$//' file
## To write in the same file
sed -i 's/ *$//' file
## Using the [:blank:] class you are removing spaces and tabs
sed 's/[[:blank:]]*$//' file
## Removing all spaces
sed 's/ //g' file > file2.txt
## Remove spaces in the end of line
sed 's/\s*$//' file > file2.txt
## Remove '\r' (return)
## Useful in subtitles or text files to use with grep
tr -d '\r'
sed 's/\r$//' file
# grep ^1$ sub.srt
## String cut
## Print first 5 characters
echo -e "Hello_World" | cut -c1-5
## Print the first 3 characters
echo -e "Hello_World" | cut -c-3
## Print the 3 characters to end
echo -e "Hello_World" | cut -c3-
## Print the 1 field and the 7 based on the delimiter
echo " root:x:0:0:root:/root:/bin/bash" | cut -d: -f1,7
cut -d ';' -f2 tabela.txt
# -d delimiter
# -fX number X of the desired column
## Cut file after on char
echo "te.st 1.23" | cut -d '.' -f2
## until the end
echo "te.st 1.23" | cut -d '.' -f2-
## cut file name by extension
echo "file_name.txt" | cut -d '.' -f1
echo "file.name.2.txt" | rev | cut -d '.' -f2- | rev
## Change the default shell in Linux/Unix/MacOS?
## chsh -s shell-path user
chsh -s /bin/bash j
## Logout to test
## Print only some lines
b=3; f=18; cat -n file.txt | sed -n -e "$b,$f p" -e "$f q"
## Or
b=3; f=18; sed -n "$b, $f p" file.txt
## Localize arquivos grandes
find . -size +1000M
# b - blocos de 512-byte (este é o default, se não for utilizado nenhum sufixo)
# c - bytes
# w - palavras de dois bytes
# k - Kilobytes (unidades de 1024 bytes)
# M - Megabytes (unidades de 1048576 bytes)
# G - Gigabytes (unidades de 1073741824 bytes)
## Reset directories and files permission
## Set all folder to permission 755
find . -type d -exec chmod 0755 {} \;
## Remove execute permission from files without touching folders
find . -type f -exec chmod 0644 {} \;
## Or
find . -type f -exec chmod 0644 {} +
## Remove permission from other users, also permission to execute from current user
find . -type f -exec chmod 0600 {} \;
## Change owner user to root
chown root -R *
## Change files group to root
chgrp root -R *
## Expansão de urls encurtadas com curl
curl -sIL short-url | grep ^Location;
curl -sIL http://goo.gl/CwbmNk | grep ^Location;
# Location: http://www.shellhacks.com/en/HowTo-Extract-Archives-targzbz2rarzip7ztbz2tgzZ
## How to compare the content of two or more directories
diff -qr dir1/ dir2/
# -q, report only when files differ
# -s, report when two files are the same
# -r, recursively compare any sub directories found
## Extract the file name from a URL
url=http://pics.sitename.com/images/191211/mxKL17DdgUhcr.jpg
filename=$(basename "$url")
echo "file name: $filename"
## LiLo login/command boot without password
<label> single init=/bin/<shell>
<label> init=/bin/<shell>
## remount rw, update passwd and remount ro
## Set the new password
passwd
## Examples
linux single init=/bin/sh
linux init=/bin/sh
## Slackware
Slackware single init=/bin/bash rw
## or
Slackware init=/bin/bash
# System with minimal services and it is mounted read only
mount -o remount,rw /
passwd
## Be sure to finally remount your / as ro or something might screw up
mount -o remount,ro /
## Grub login/command boot without password
## In the Grub menu, select the entry and press "e" to edit
## Appending in the line "linux ....", after boot it with "Ctrl-x" of "F10"
rw init=/bin/bash
## Set the new password
passwd
## Show the Grub menu
nano /etc/default/grub
## Comment the line
#GRUB_HIDDEN_TIMEOUT=0
## OR
#GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT_STYLE=menu
## Set to false
GRUB_HIDDEN_TIMEOUT_QUIET=false
## Update
update-grub
## Remove Spotify pop-up notification when a song starts
## Exit Spotify
## Then edit
~/.config/spotify/Users/[Spotify user name]-user/prefs
## And set
ui.track_notifications_enabled=false
## Gmail list the archived emails
# https://support.google.com/mail/answer/7190
has:nouserlabels -in:Sent -in:Chat -in:Draft -in:Inbox
# Mais que 10m e mais de 1 ano
larger:10m older_than:1y
## Change size monitor
xrandr --output LVDS1 --mode 1024x768
xrandr --output LVDS1 --mode 1366x768
xrandr -s 1024x768
xrandr -s 1366x768
## Add
xrandr --output LVDS1 --mode 1024x768
xrandr --output VGA1 --mode 1024x768
xrandr --output LVDS1 --off
xrandr --output VGA1 --mode 1440x900
## Remove
xrandr --output VGA1 --mode 1024x768
xrandr --output LVDS1 --mode 1024x768
xrandr --output VGA1 --off
xrandr --output LVDS1 --mode 1366x768
## Comprimir zip em várias partes
7z a -v512m Large-file-separated-in-multi-parts.zip Large-Gigabytes-File.SQL
# Large-file-separated-in-multi-parts.zip.001, Large-file-separated-in-multi-parts.zip.002,
# Large-file-separated-in-multi-parts.zip.003, Large-file-separated-in-multi-parts.004 etc
## Smarty DNS
http://www.smartydns.com/
# trial 14 days
192.241.143.47