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:40]
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 ======
  
 +===== Find and prepare new hard-disks =====
  
 +On modern udev installations,​ there are symbolic links to storage media in subdirectories of /dev/disk, that let you look up a 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/​).
 +
 +Linux also provides the lsblk utility which displays a nice tree view of the storage volume.
 +
 +To prepare:
 +<​code>​
 +mkdir -p /mnt/vdb
 +mkfs.ext4 /dev/vdb
 +mount /dev/vdb /mnt/vdb
 +</​code>​
 +
 +===== Services =====
 +==== List services ====
 +<​code>​
 +pstree
 +service --status-all
 +</​code>​
 ===== Navigate on files ===== ===== Navigate on files =====
  
Línea 14: Línea 32:
  
  
 +=== Find those files that contain "​X"​ ===
  
-===== Understand free output ===== +<​code>​ 
-  * Free memory ​is the amount of memory which is currently not used for anything. This number ​should be smallbecause memory which is not used is simply wasted+grep -rnw '/​path/​to/​somewhere/'​ -e '​pattern'​ 
-  * Available memory is the amount ​of memory which is available for allocation to a new process or to existing processes.+</​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.
  
-Available does include free and buff/cache columns. These (free and buff/cache) can be reused for current needs immediately. +Others: 
-===== How to enable root ===== +  * -i for ignore ​the case
-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>​
-sysctl net.ipv4.ip_forward=1 +grep -Ril "​text-to-find-here" ​/
-sysctl net.ipv4.conf.all.accept_redirects=0 +
-sysctl net.ipv4.conf.all.send_redirects=0 +
-</code>+
  
-You can watch set variables currently in memory with ''​sysctl ​-p''​+# This will only search through those files which have .c or .h extensions:​ 
 +grep --include=\*.{c,​h} -rnw '/​path/​to/​somewhere/​' ​-e "​pattern"​
  
-Or all of them with: ''​sysctl ​-a''​+# This will exclude searching ​all the files ending ​with .o extension: 
 +grep --exclude=\*.o -rnw '/​path/​to/​somewhere/​' ​-e "​pattern"​
  
-To make permanent those values write them at ''/etc/sysctl.conf''. +# 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"​
-===== Detect which process is using which ports ===== +
-All open network connections:​ +
-<​code>​ +
-sudo netstat ​-nlp+
 </​code>​ </​code>​
 +=== Find those files that contain "​X"​ and "​Y"​ ===
  
-List of processes using tcp port 43796: 
 <​code>​ <​code>​
-lsof -i tcp:43796 +# Being X = "'​pending'​False,"​ 
-or +Being Y = "'​program_id':​ '​sps_lease'"​ 
-lsof -:9200+grep -rl '​.'​ -e "'​pending':​ False,"​ | xargs grep -l -e "'​program_id'​'​sps_lease'"​
 </​code>​ </​code>​
  
-List of pids using tcp port 43796:+=== Search only in some files with extension... === 
 <​code>​ <​code>​
-sudo fuser 43796/tcp+grep -rn '/home/​alfred/​Workspaces'​ --include \*.py --include \*.pyc -e '​bcrypt'​
 </​code>​ </​code>​
-===== Know info about the system ===== 
  
-''​cat /​etc/​*-release''​ will give you info about the Linux distribution version. 
  
-''​uname -r''​ will give you info about the kernel.+===== Environment variables =====
  
-''​uname -a'' ​will give you info about the Unix system.+Puedes definirlas en el ''​.profile''​ para toda la sesión o en el ''​.bashrc''​. ​Una definicións será: 
 +<​code>​ 
 +export PRUEVAR=PRUEBA 
 +</​code>​
  
- +Luego para usarla:
-===== Create an iso from a folder =====+
 <​code>​ <​code>​
-genisoimage -o ~/backup.iso -V BACKUP -R -J ~/Documents+echo ${USER} 
 +ls /home/${USER}
 </​code>​ </​code>​
-===== Graphic tablet ===== + 
-To see all registered inputs:+Para borrarla:
 <​code>​ <​code>​
-xinput+unset PRUEVAR
 </​code>​ </​code>​
-To map a xinput with a display (''​xrandr''​ will give you the display id):+ 
 +Otra forma:
 <​code>​ <​code>​
- ​xinput map-to-output <​registered input id> <display id> +set NAME=Value 
- xinput map-to-output 22 HDMI-1-1+setenv NAME=Value
 </​code>​ </​code>​
  
-===== Copy and paste from console ===== +Para usarla para un comando:
-With the ''​xclip''​ command, adding these lines to ''​.bashrc''​ file:+
 <​code>​ <​code>​
-alias pbcopy='​xclip ​-selection clipboard'​ +export PGPASSWORD=mysecretpassword && psql -h 127.0.0.1 ​-U postgres
-alias pbpaste='​xclip -selection clipboard ​-o'+
 </​code>​ </​code>​
  
-You can do the next:+Puedes ejecutar un comando con variables de entorno temporales:
 <​code>​ <​code>​
-echo "​Welcome To OSTechNix!"​ | pbcopy +env NAME=Value ​echo $NAME
-echo `pbpaste` +
-pbcopy < /​etc/​resolv.conf+
 </​code>​ </​code>​
-===== Generate random string =====+Por ejemplo un ''​a.sh''​ que podrías ejecutar como ''​env PT=123 PP=33 ./​a.sh''​
 <​code>​ <​code>​
-# Allow "​tr"​ to process non-utf8 byte sequences +echo $PT 
-export LC_CTYPE=C +echo $PP
- +
-# read random bytes and keep only alphanumerics +
-< /​dev/​urandom tr -dc A-Za-z0-9 | head -c32+
 </​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 147: 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 207: 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 217: 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 242: 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 249: 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 263: 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 277: 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 299: 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 354: 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 398: 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.1598370056.txt.gz · Última modificación: 2020/08/25 16:40 (editor externo)