Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:linux_howto [2020/08/25 15:45] alfred [Find concrete files] |
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 with contain "X" === | + | === Find those files that contain "X" === |
| <code> | <code> | ||
| Línea 28: | Línea 46: | ||
| <code> | <code> | ||
| + | grep -Ril "text-to-find-here" / | ||
| + | |||
| # This will only search through those files which have .c or .h extensions: | # This will only search through those files which have .c or .h extensions: | ||
| grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern" | grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern" | ||
| Línea 36: | Línea 56: | ||
| # This will exclude the dirs dir1/, dir2/ and all of them matching *.dst/: | # 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" | grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern" | ||
| + | </code> | ||
| + | === Find those files that contain "X" and "Y" === | ||
| + | |||
| + | <code> | ||
| + | # Being X = "'pending': False," | ||
| + | # Being Y = "'program_id': 'sps_lease'" | ||
| + | grep -rl '.' -e "'pending': False," | xargs grep -l -e "'program_id': 'sps_lease'" | ||
| + | </code> | ||
| + | |||
| + | === Search only in some files with extension... === | ||
| + | |||
| + | <code> | ||
| + | grep -rn '/home/alfred/Workspaces' --include \*.py --include \*.pyc -e 'bcrypt' | ||
| + | </code> | ||
| + | |||
| + | |||
| + | ===== Environment variables ===== | ||
| + | |||
| + | 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: | ||
| + | <code> | ||
| + | echo ${USER} | ||
| + | ls /home/${USER} | ||
| + | </code> | ||
| + | |||
| + | Para borrarla: | ||
| + | <code> | ||
| + | unset PRUEVAR | ||
| + | </code> | ||
| + | |||
| + | Otra forma: | ||
| + | <code> | ||
| + | set NAME=Value | ||
| + | setenv NAME=Value | ||
| + | </code> | ||
| + | |||
| + | Para usarla para un comando: | ||
| + | <code> | ||
| + | export PGPASSWORD=mysecretpassword && psql -h 127.0.0.1 -U postgres | ||
| + | </code> | ||
| + | |||
| + | Puedes ejecutar un comando con variables de entorno temporales: | ||
| + | <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> | ||
| + | |||
| + | ''printenv'' es otro comando que permite mostrar el valor de una variable de entorno. | ||
| + | <code> | ||
| + | printenv WATCHEXEC_META_CHANGED_PATH | ||
| + | </code> | ||
| + | |||
| + | ''env'' también te sirve para listar las variables de entorno definidas en esta sesión. | ||
| + | |||
| + | |||
| + | ===== How to create a ram disk ===== | ||
| + | |||
| + | There are two available types: | ||
| + | |||
| + | * ramfs file systems cannot be limited in size like a disk base file system which is limited by it’s capacity. ramfs will continue using memory storage until the system runs out of RAM and likely crashes or becomes unresponsive. This is a problem if the application writing to the file system cannot be limited in total size. Another issue is you cannot see the size of the file system in df and it can only be estimated by looking at the cached entry in free. | ||
| + | * tmpfs is a more recent RAM file system which overcomes many of the drawbacks with ramfs. You can specify a size limit in tmpfs which will give a ‘disk full’ error when the limit is reached. This behaviour is exactly the same as a partition of a physical disk. | ||
| + | |||
| + | To mount a disk: | ||
| + | <code> | ||
| + | mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk | ||
| + | mount -o size=16G -t tmpfs none /mnt/tmpfs | ||
| + | </code> | ||
| + | |||
| + | ''mount -t [TYPE] -o size=[SIZE] [FSTYPE] [MOUNTPOINT]''. [TYPE] is the type of RAM disk to use; either tmpfs or ramfs. [SIZE] is the size to use for the file system. Remember that ramfs does not have a physical limit and is specified as a starting size. [FSTYPE] is the type of RAM disk to use; either tmpfs, ramfs, ext4, etc. | ||
| + | |||
| + | You can also edit the fstab file: | ||
| + | <code> | ||
| + | tmpfs /mnt/ramdisk tmpfs nodev,nosuid,noexec,nodiratime,size=1024M 0 0 | ||
| + | tmpfs /home/szymon/ramdisk tmpfs rw,size=512M,mode=777 0 0 | ||
| + | </code> | ||
| + | |||
| + | You can also use SquashFS. SquashFS is intended for general read-only file system use and in constrained block device/memory systems (e.g. embedded systems) where low overhead is needed. The standard version of SquashFS uses gzip compression, although there is also a project that brings LZMA compression to SquashFS. Install squasfsh tools: \\ | ||
| + | ''sudo apt-get install squashfs-tools'' \\ | ||
| + | Create .sqsh file: \\ | ||
| + | ''mksquashfs /usr/lib/jvm/java-6-sun-1.6.0.21 /home/nancom/jdk6.sqsh'' \\ | ||
| + | Unsquash: \\ | ||
| + | ''unsquashfs [options] target [files/directories to extract] $shell > sudo mount /home/nancom/jdk6.sqsh /media/ramdisk -t squashfs -o loop sudo update-alternatives --install "/usr/bin/java" "java" "/media/ramdisk/bin/java" 1 Check install java complete sudo update-alternatives --config java'' \\ | ||
| + | !! 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 | ||
| + | |||
| + | |||
| + | ===== MessageBox ===== | ||
| + | |||
| + | ==== Yes and no questions ==== | ||
| + | <code> | ||
| + | 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> | ||
| + | ===== <fast> How to's... ==== | ||
| - | ===== Understand free output ===== | + | ==== 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. | * 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 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. | Available does include free and buff/cache columns. These (free and buff/cache) can be reused for current needs immediately. | ||
| - | ===== How to enable root ===== | + | ==== 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. | 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'' | 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 ===== | + | ==== Change kernel variables ==== |
| Kernel variables are changed with ''sysctl''. | Kernel variables are changed with ''sysctl''. | ||
| Línea 66: | Línea 189: | ||
| To make permanent those values write them at ''/etc/sysctl.conf''. | To make permanent those values write them at ''/etc/sysctl.conf''. | ||
| - | ===== Detect which process is using which ports ===== | + | ==== Detect which process is using which ports ==== |
| All open network connections: | All open network connections: | ||
| <code> | <code> | ||
| Línea 83: | Línea 206: | ||
| sudo fuser 43796/tcp | sudo fuser 43796/tcp | ||
| </code> | </code> | ||
| - | ===== Know info about the system ===== | + | ==== Know info about the system ==== |
| ''cat /etc/*-release'' will give you info about the Linux distribution version. | ''cat /etc/*-release'' will give you info about the Linux distribution version. | ||
| Línea 92: | Línea 215: | ||
| - | ===== Create an iso from a folder ===== | + | ==== Create an iso from a folder ==== |
| <code> | <code> | ||
| genisoimage -o ~/backup.iso -V BACKUP -R -J ~/Documents | genisoimage -o ~/backup.iso -V BACKUP -R -J ~/Documents | ||
| </code> | </code> | ||
| - | ===== Graphic tablet ===== | ||
| - | To see all registered inputs: | ||
| - | <code> | ||
| - | xinput | ||
| - | </code> | ||
| - | To map a xinput with a display (''xrandr'' will give you the display id): | ||
| - | <code> | ||
| - | xinput map-to-output <registered input id> <display id> | ||
| - | xinput map-to-output 22 HDMI-1-1 | ||
| - | </code> | ||
| - | ===== Copy and paste from console ===== | + | |
| + | ==== Copy and paste from console ==== | ||
| With the ''xclip'' command, adding these lines to ''.bashrc'' file: | With the ''xclip'' command, adding these lines to ''.bashrc'' file: | ||
| <code> | <code> | ||
| Línea 120: | Línea 234: | ||
| pbcopy < /etc/resolv.conf | pbcopy < /etc/resolv.conf | ||
| </code> | </code> | ||
| - | ===== Generate random string ===== | + | ==== Generate random string ==== |
| <code> | <code> | ||
| # Allow "tr" to process non-utf8 byte sequences | # Allow "tr" to process non-utf8 byte sequences | ||
| Línea 128: | Línea 242: | ||
| < /dev/urandom tr -dc A-Za-z0-9 | head -c32 | < /dev/urandom tr -dc A-Za-z0-9 | head -c32 | ||
| </code> | </code> | ||
| - | ===== Install Java ===== | + | ==== Install Java ==== |
| <code> | <code> | ||
| Línea 142: | Línea 256: | ||
| sudo update-alternatives --config java | sudo update-alternatives --config java | ||
| </code> | </code> | ||
| - | ===== How to create a ram disk ===== | ||
| - | There are two available types: | ||
| - | * ramfs file systems cannot be limited in size like a disk base file system which is limited by it’s capacity. ramfs will continue using memory storage until the system runs out of RAM and likely crashes or becomes unresponsive. This is a problem if the application writing to the file system cannot be limited in total size. Another issue is you cannot see the size of the file system in df and it can only be estimated by looking at the cached entry in free. | + | ==== Work in background ==== |
| - | * tmpfs is a more recent RAM file system which overcomes many of the drawbacks with ramfs. You can specify a size limit in tmpfs which will give a ‘disk full’ error when the limit is reached. This behaviour is exactly the same as a partition of a physical disk. | + | |
| - | + | ||
| - | To mount a disk: | + | |
| - | <code> | + | |
| - | mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk | + | |
| - | mount -o size=16G -t tmpfs none /mnt/tmpfs | + | |
| - | </code> | + | |
| - | + | ||
| - | ''mount -t [TYPE] -o size=[SIZE] [FSTYPE] [MOUNTPOINT]''. [TYPE] is the type of RAM disk to use; either tmpfs or ramfs. [SIZE] is the size to use for the file system. Remember that ramfs does not have a physical limit and is specified as a starting size. [FSTYPE] is the type of RAM disk to use; either tmpfs, ramfs, ext4, etc. | + | |
| - | + | ||
| - | You can also edit the fstab file: | + | |
| - | <code> | + | |
| - | tmpfs /mnt/ramdisk tmpfs nodev,nosuid,noexec,nodiratime,size=1024M 0 0 | + | |
| - | tmpfs /home/szymon/ramdisk tmpfs rw,size=512M,mode=777 0 0 | + | |
| - | </code> | + | |
| - | + | ||
| - | You can also use SquashFS. SquashFS is intended for general read-only file system use and in constrained block device/memory systems (e.g. embedded systems) where low overhead is needed. The standard version of SquashFS uses gzip compression, although there is also a project that brings LZMA compression to SquashFS. Install squasfsh tools: \\ | + | |
| - | ''sudo apt-get install squashfs-tools'' \\ | + | |
| - | Create .sqsh file: \\ | + | |
| - | ''mksquashfs /usr/lib/jvm/java-6-sun-1.6.0.21 /home/nancom/jdk6.sqsh'' \\ | + | |
| - | Unsquash: \\ | + | |
| - | ''unsquashfs [options] target [files/directories to extract] $shell > sudo mount /home/nancom/jdk6.sqsh /media/ramdisk -t squashfs -o loop sudo update-alternatives --install "/usr/bin/java" "java" "/media/ramdisk/bin/java" 1 Check install java complete sudo update-alternatives --config java'' \\ | + | |
| - | !! 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á: | + | |
| - | <code> | + | |
| - | export PRUEVAR=PRUEBA | + | |
| - | </code> | + | |
| - | + | ||
| - | Luego para usarla: | + | |
| - | <code> | + | |
| - | echo ${USER} | + | |
| - | ls /home/${USER} | + | |
| - | </code> | + | |
| - | + | ||
| - | Para borrarla: | + | |
| - | <code> | + | |
| - | unset PRUEVAR | + | |
| - | </code> | + | |
| - | + | ||
| - | Otra forma: | + | |
| - | <code> | + | |
| - | set NAME=Value | + | |
| - | setenv NAME=Value | + | |
| - | </code> | + | |
| - | + | ||
| - | Para usarla para un comando: | + | |
| - | <code> | + | |
| - | export PGPASSWORD=mysecretpassword && psql -h 127.0.0.1 -U postgres | + | |
| - | </code> | + | |
| - | + | ||
| - | Puedes ejecutar un comando con variables de entorno temporales: | + | |
| - | <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> | + | |
| - | + | ||
| - | ''printenv'' es otro comando que permite mostrar el valor de una variable de entorno. | + | |
| - | <code> | + | |
| - | printenv WATCHEXEC_META_CHANGED_PATH | + | |
| - | </code> | + | |
| - | + | ||
| - | ''env'' también te sirve para listar las variables de entorno definidas en esta sesión. | + | |
| - | ===== Work in background ===== | + | |
| Run in background: ''$ command &'' | Run in background: ''$ command &'' | ||
| Línea 231: | 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 241: | 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 266: | 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 273: | 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 287: | 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 301: | 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 323: | 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 378: | 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 422: | 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 ===== | ||