Herramientas de usuario

Herramientas del sitio


wiki2:linux_howto

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:linux_howto [2020/08/25 15:39]
alfred [Find lasts changes files in folder]
wiki2:linux_howto [2022/05/09 09:41] (actual)
Línea 1: Línea 1:
 ====== Linux how tos ====== ====== Linux how tos ======
  
-===== Understand free output ​===== +===== Find and prepare new hard-disks ​=====
-  * Free memory is the amount of memory which is currently not used for anything. This number should be small, because memory which is not used is simply wasted. +
-  * Available memory is the amount of memory which is available for allocation to a new process or to existing processes.+
  
-Available does include free and buff/cache columns. These (free and buff/cache) can be reused for current needs immediately. +On modern udev installations,​ there are symbolic links to storage media in subdirectories of /dev/diskthat let you look up disk or a partition by serial number ​(/​dev/​disk/​by-id/​), by UUID (/​dev/​disk/​by-uuid), by filesystem label (/​dev/​disk/​by-label/​) or by hardware connectivity (/​dev/​disk/​by-path/​).
-===== How to enable root ===== +
-Sorirst execute in a terminal: ''​sudo passwd root''​. ​you will prompted for new Unix password. Write it twice(second for confirmation). Then execute: ''​sudo passwd ​-u root ''​. to unlock the account+
  
-If you want to disable root account in Ubuntu you need to lock the root account by using the following command ''​sudo passwd -l root''​+Linux also provides ​the lsblk utility which displays a nice tree view of the storage volume.
  
-===== Change kernel variables =====+To prepare: 
 +<​code>​ 
 +mkdir -p /mnt/vdb 
 +mkfs.ext4 /dev/vdb 
 +mount /dev/vdb /mnt/vdb 
 +</​code>​
  
-Kernel variables are changed with ''​sysctl''​. +===== Services ===== 
- +==== List services ====
-Set a serie of variables:+
 <​code>​ <​code>​
-sysctl net.ipv4.ip_forward=1 +pstree 
-sysctl net.ipv4.conf.all.accept_redirects=0 +service --status-all
-sysctl net.ipv4.conf.all.send_redirects=0+
 </​code>​ </​code>​
 +===== Navigate on files =====
  
-You can watch set variables currently in memory with ''​sysctl -p''​ 
  
-Or all of them with: ''​sysctl -a''​+==== Find concrete files ====
  
-To make permanent those values write them at ''​/​etc/​sysctl.conf''​.+=== Find lasts changes files in folder === 
 + 
 +To find all files that file status was last changed N minutes ago: ''​find -cmin -N''​. ​ 
 + 
 +For example: ''​find -cmin -5''​ 
 + 
 + 
 +=== Find those files that contain "​X"​ ===
  
-===== Detect which process is using which ports ===== 
-All open network connections:​ 
 <​code>​ <​code>​
-sudo netstat ​-nlp+grep -rnw '/​path/​to/​somewhere/'​ -e '​pattern'​
 </​code>​ </​code>​
 +  * -r or -R is recursive,
 +  * -n is line number, and
 +  * -w stands for match the whole word.
 +  * -l (lower-case L) can be added to just give the file name of matching files.
 +
 +Others:
 +  * -i for ignore the case
  
-List of processes using tcp port 43796: 
 <​code>​ <​code>​
-lsof -i tcp:43796 +grep -Ril "​text-to-find-here"​ / 
-# or + 
-lsof -:9200+This will only search through those files which have .c or .h extensions: 
 +grep --include=\*.{c,​h} -rnw '/​path/​to/​somewhere/'​ -e "​pattern"​ 
 + 
 +# This will exclude searching all the files ending with .o extension: 
 +grep --exclude=\*.o -rnw '/​path/​to/​somewhere/'​ -e "​pattern"​ 
 + 
 +# This will exclude the dirs dir1/, dir2/ and all of them matching *.dst/: 
 +grep --exclude-dir={dir1,​dir2,​*.dst} -rnw '/​path/​to/​somewhere/'​ -e "​pattern"​
 </​code>​ </​code>​
 +=== Find those files that contain "​X"​ and "​Y"​ ===
  
-List of pids using tcp port 43796: 
 <​code>​ <​code>​
-sudo fuser 43796/tcp+# Being X = "'​pending':​ False,"​ 
 +# Being Y = "'​program_id':​ '​sps_lease'"​ 
 +grep -rl '​.'​ -e "'​pending':​ False,"​ | xargs grep -l -e "'​program_id':​ '​sps_lease'"​
 </​code>​ </​code>​
-===== Know info about the system ===== 
  
-''​cat /​etc/​*-release''​ will give you info about the Linux distribution version.+=== Search only in some files with extension... ===
  
-''​uname -r'' ​will give you info about the kernel.+<​code>​ 
 +grep -rn '/​home/​alfred/​Workspaces' --include \*.py --include \*.pyc -e 'bcrypt' 
 +</​code>​
  
-''​uname -a''​ will give you info about the Unix system. 
  
 +===== Environment variables =====
  
-===== Create an iso from a folder =====+Puedes definirlas en el ''​.profile''​ para toda la sesión o en el ''​.bashrc''​. Una definicións será:
 <​code>​ <​code>​
-genisoimage -o ~/​backup.iso -V BACKUP -R -J ~/Documents+export PRUEVAR=PRUEBA
 </​code>​ </​code>​
-===== Graphic tablet ===== + 
-To see all registered inputs:+Luego para usarla:
 <​code>​ <​code>​
-xinput+echo ${USER} 
 +ls /​home/​${USER}
 </​code>​ </​code>​
-To map a xinput with a display (''​xrandr''​ will give you the display id):+ 
 +Para borrarla:
 <​code>​ <​code>​
- ​xinput map-to-output <​registered input id> <display id> +unset PRUEVAR
- ​xinput map-to-output 22 HDMI-1-1+
 </​code>​ </​code>​
  
-===== Copy and paste from console ===== +Otra forma:
-With the ''​xclip''​ command, adding these lines to ''​.bashrc''​ file:+
 <​code>​ <​code>​
-alias pbcopy='xclip -selection clipboard'​ +set NAME=Value 
-alias pbpaste='xclip -selection clipboard -o'+setenv NAME=Value
 </​code>​ </​code>​
  
-You can do the next:+Para usarla para un comando:
 <​code>​ <​code>​
-echo "​Welcome To OSTechNix!"​ | pbcopy +export PGPASSWORD=mysecretpassword && psql -h 127.0.0.1 -U postgres
-echo `pbpaste` +
-pbcopy < /etc/resolv.conf+
 </​code>​ </​code>​
-===== Generate random string ===== 
-<​code>​ 
-# Allow "​tr"​ to process non-utf8 byte sequences 
-export LC_CTYPE=C 
  
-# read random bytes and keep only alphanumerics +Puedes ejecutar un comando con variables de entorno temporales:​ 
-< /dev/urandom tr -dc A-Za-z0-9 | head -c32+<​code>​ 
 +env NAME=Value echo $NAME 
 +</code> 
 +Por ejemplo un ''​a.sh''​ que podrías ejecutar como ''​env PT=123 PP=33 ./a.sh''​ 
 +<​code>​ 
 +echo $PT 
 +echo $PP
 </​code>​ </​code>​
-===== Install Java ===== 
  
 +''​printenv''​ es otro comando que permite mostrar el valor de una variable de entorno.
 <​code>​ <​code>​
-sudo apt-get install python-software-properties +printenv WATCHEXEC_META_CHANGED_PATH
-sudo add-apt-repository ppa:​webupd8team/​java +
-sudo apt-get update +
-sudo apt-get install oracle-java7-installer+
 </​code>​ </​code>​
  
-If you want to check:+''​env''​ también te sirve para listar las variables de entorno definidas en esta sesión. 
  
-<​code> ​ 
-sudo update-alternatives --config java 
-</​code>​ 
 ===== How to create a ram disk ===== ===== How to create a ram disk =====
  
Línea 133: Línea 148:
  !! And choose java in ram !! !! Finish !! !! Make it permanant on startup !! Edit /etc/fstab add line: /​home/​nancom/​jdk6.sqsh /​media/​ramdisk squashfs ro,​defaults,​loop 0 0  !! And choose java in ram !! !! Finish !! !! Make it permanant on startup !! Edit /etc/fstab add line: /​home/​nancom/​jdk6.sqsh /​media/​ramdisk squashfs ro,​defaults,​loop 0 0
  
-===== Environment variables ===== 
  
-Puedes definirlas en el ''​.profile''​ para toda la sesión o en el ''​.bashrc''​. Una definicións será:+===== MessageBox ===== 
 + 
 +==== Yes and no questions ====
 <​code>​ <​code>​
-export PRUEVAR=PRUEBA+if zenity --question --text="What do you choose?";​ then 
 +    zenity --info --text="​You pressed \"​Yes\"​!"​ 
 +else 
 +    zenity --info --text="​You pressed \"​No\"​!"​ 
 +fi
 </​code>​ </​code>​
  
-Luego para usarla:+===== <​fast>​ How to'​s... ==== 
 + 
 +==== Understand free output ===== 
 +  * Free memory is the amount of memory which is currently not used for anything. This number should be small, because memory which is not used is simply wasted. 
 +  * Available memory is the amount of memory which is available for allocation to a new process or to existing processes. 
 + 
 +Available does include free and buff/cache columns. These (free and buff/cache) can be reused for current needs immediately. 
 +==== How to enable root ==== 
 +So, rirst execute in a terminal: ''​sudo passwd root''​. you will prompted for a new Unix password. Write it twice(second for confirmation). Then execute: ''​sudo passwd -u root ''​. to unlock the account.  
 + 
 +If you want to disable root account in Ubuntu you need to lock the root account by using the following command ''​sudo passwd -l root''​ 
 + 
 +==== Change kernel variables ==== 
 + 
 +Kernel variables are changed with ''​sysctl''​. 
 + 
 +Set a serie of variables:
 <​code>​ <​code>​
-echo ${USER} +sysctl net.ipv4.ip_forward=1 
-ls /​home/​${USER}+sysctl net.ipv4.conf.all.accept_redirects=0 
 +sysctl net.ipv4.conf.all.send_redirects=0
 </​code>​ </​code>​
  
-Para borrarla:+You can watch set variables currently in memory with ''​sysctl -p''​ 
 + 
 +Or all of them with: ''​sysctl -a''​ 
 + 
 +To make permanent those values write them at ''/​etc/​sysctl.conf''​. 
 + 
 +==== Detect which process is using which ports ==== 
 +All open network connections:
 <​code>​ <​code>​
-unset PRUEVAR+sudo netstat -nlp
 </​code>​ </​code>​
  
-Otra forma:+List of processes using tcp port 43796:
 <​code>​ <​code>​
-set NAME=Value +lsof -i tcp:43796 
-setenv NAME=Value+# or 
 +lsof -i :9200
 </​code>​ </​code>​
  
-Para usarla para un comando:+List of pids using tcp port 43796:
 <​code>​ <​code>​
-export PGPASSWORD=mysecretpassword && psql -h 127.0.0.1 -U postgres+sudo fuser 43796/tcp
 </​code>​ </​code>​
 +==== Know info about the system ====
  
-Puedes ejecutar un comando con variables de entorno temporales:+''​cat /​etc/​*-release''​ will give you info about the Linux distribution version. 
 + 
 +''​uname -r''​ will give you info about the kernel. 
 + 
 +''​uname -a''​ will give you info about the Unix system. 
 + 
 + 
 +==== Create an iso from a folder ====
 <​code>​ <​code>​
-env NAME=Value echo $NAME+genisoimage -o ~/​backup.iso -V BACKUP -R -J ~/Documents
 </​code>​ </​code>​
-Por ejemplo un ''​a.sh'' ​que podrías ejecutar como ''​env PT=123 PP=33 ./a.sh''​+ 
 + 
 +==== Copy and paste from console ==== 
 +With the ''​xclip'' ​command, adding these lines to ''​.bashrc'' ​file:
 <​code>​ <​code>​
-echo $PT +alias pbcopy='​xclip -selection clipboard'​ 
-echo $PP+alias pbpaste='​xclip -selection clipboard -o'
 </​code>​ </​code>​
  
-''​printenv''​ es otro comando que permite mostrar el valor de una variable de entorno.+You can do the next:
 <​code>​ <​code>​
-printenv WATCHEXEC_META_CHANGED_PATH+echo "​Welcome To OSTechNix!"​ | pbcopy 
 +echo `pbpaste` 
 +pbcopy < /​etc/​resolv.conf
 </​code>​ </​code>​
 +==== Generate random string ====
 +<​code>​
 +# Allow "​tr"​ to process non-utf8 byte sequences
 +export LC_CTYPE=C
  
-''​env''​ también te sirve para listar las variables de entorno definidas en esta sesión. +# read random bytes and keep only alphanumerics 
-===== Work in background ​=====+< /​dev/​urandom tr -dc A-Za-z0-9 | head -c32 
 +</​code>​ 
 +==== Install Java ==== 
 + 
 +<​code>​ 
 +sudo apt-get install python-software-properties 
 +sudo add-apt-repository ppa:​webupd8team/​java 
 +sudo apt-get update 
 +sudo apt-get install oracle-java7-installer 
 +</​code>​ 
 + 
 +If you want to check: 
 + 
 +<​code>​  
 +sudo update-alternatives --config java 
 +</​code>​ 
 + 
 + 
 +==== Work in background ====
  
 Run in background: ''​$ command &''​ Run in background: ''​$ command &''​
Línea 193: Línea 273:
  
 Cortar la ejecución de un programa en background: ''​kill %<​número>''​ Cortar la ejecución de un programa en background: ''​kill %<​número>''​
-===== Sudo =====+
 ==== Disable sudo password for a user ==== ==== Disable sudo password for a user ====
 ''​sudo visudo'',​ add this line at the end (change “jerome” to your username): ''​jerome ALL=(ALL) NOPASSWD: ALL''​ ''​sudo visudo'',​ add this line at the end (change “jerome” to your username): ''​jerome ALL=(ALL) NOPASSWD: ALL''​
  
-===== Boot process ​=====+==== Boot process ====
 <​code>​ <​code>​
 /​var/​log/​boot.log ​ ---  System boot log /​var/​log/​boot.log ​ ---  System boot log
Línea 203: Línea 283:
 $ dmesg | grep -i memory $ dmesg | grep -i memory
 </​code>​ </​code>​
-===== Define a proxy =====+==== Define a proxy ====
  
 System-wide proxies in CLI Ubuntu/​Server must be set as environment variables. System-wide proxies in CLI Ubuntu/​Server must be set as environment variables.
Línea 228: Línea 308:
 Finally, logout and reboot to make sure the changes take effect. Finally, logout and reboot to make sure the changes take effect.
  
-===== Know active IPs on a network ​=====+==== Know active IPs on a network ====
 <​code>​ <​code>​
 nmap -sP 192.168.1.* nmap -sP 192.168.1.*
Línea 235: Línea 315:
 will scan the entire .1 to .254 range will scan the entire .1 to .254 range
  
-===== Linux console shortcuts ​=====+==== Linux console shortcuts ====
 Just to summarise all the answers Just to summarise all the answers
  
Línea 249: Línea 329:
 Toggle between the start of line and current cursor position: Ctrl + XX \\  Toggle between the start of line and current cursor position: Ctrl + XX \\ 
  
-===== Linux redirection ​=====+==== Linux redirection ====
 Redirect stderr to another file: Redirect stderr to another file:
 <​code>​ <​code>​
Línea 263: Línea 343:
 </​code>​ </​code>​
  
-===== Change timezone ​=====+==== Change timezone ====
 You can see it with ''​timedatectl''​. ​ You can see it with ''​timedatectl''​. ​
 <​code>​ <​code>​
Línea 285: Línea 365:
 </​code>​ </​code>​
  
-===== List USB devices ===== 
  
-To detect your USB device, in a terminal, you can try: 
-<​code>​ 
-lsusb , example: 
-$ lsusb 
-Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 
-Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub 
-Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub 
-Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub 
-Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub 
-Bus 001 Device 002: ID 046d:0809 Logitech, Inc. Webcam Pro 9000 
-Bus 003 Device 002: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse 
-</​code>​ 
-or this powerful tool, lsinput , 1st install it, and then try it, it lists all input devices including your USB device : 
-<​code>​ 
-$ sudo apt-get install input-utils 
-$ lsinput 
-/​dev/​input/​event0 
-... 
- 
-/​dev/​input/​event1 
-... 
- 
-/​dev/​input/​event2 
-... 
- 
-/​dev/​input/​event3 
-bustype : BUS_USB 
-vendor ​ : 0x46d 
-product : 0xc016 
-version : 272 
-name    : "​Logitech Optical USB Mouse" 
-phys    : "​usb-0000:​00:​1d.1-2/​input0"​ 
-uniq    : ""​ 
-bits ev : EV_SYN EV_KEY EV_REL EV_MSC 
-</​code>​ 
-udevadm , with this command line, you need to unplug the device before using the command and then plug it to see it: 
-<​code>​ 
-$ udevadm monitor --udev 
-monitor will print the received events for: 
-UDEV - the event which udev sends out after rule processing 
-UDEV  [1915.787445] add      /​devices/​pci0000:​00/​0000:​00:​1d.3/​usb5/​5-2 (usb) 
-UDEV  [1915.796226] add      /​devices/​pci0000:​00/​0000:​00:​1d.3/​usb5/​5-2/​5-2:​1.0 (usb) 
-</​code>​ 
- 
- 
-===== Grub ===== 
  
-==== Modificar opciones de inicio ====+==== Grub: Modificar opciones de inicio ====
   1. Editar el fichero ''/​etc/​default/​grub''​   1. Editar el fichero ''/​etc/​default/​grub''​
   2. Modificar la línea de linux: ''​GRUB_CMDLINE_LINUX_DEFAULT="​quiet splash acpi=off"''​   2. Modificar la línea de linux: ''​GRUB_CMDLINE_LINUX_DEFAULT="​quiet splash acpi=off"''​
Línea 340: Línea 373:
  
  
-===== Install mono =====+==== Install mono ====
  
 <​code>​ <​code>​
 $ sudo apt-get install mono-complete $ sudo apt-get install mono-complete
 </​code>​ </​code>​
-===== <​fast>​ How to'​s... =====+
 ==== Run several commands at once  ==== ==== Run several commands at once  ====
  
Línea 384: Línea 417:
 sudo mount 10.10.10.10:/​volume1/​sir-vices ./data sudo mount 10.10.10.10:/​volume1/​sir-vices ./data
 </​code>​ </​code>​
 +
 +==== Update system Certificate Authority ====
 +
 +<​code>​
 +sudo apt-get install apt-transport-https ca-certificates -y
 +sudo update-ca-certificates
 +</​code>​
 +
 ===== Notes about Mint ===== ===== Notes about Mint =====
  
wiki2/linux_howto.1598369966.txt.gz · Última modificación: 2020/08/25 16:39 (editor externo)