===== Linux ===== {{ debian.jpg?200 }} En este apartado os prepararé una lista de comandos Linux útiles para la asignatura. También podéis echar un ojo a la zona de [[extra:referencias|Referencias]] donde encontraréis enlaces a documentación sobre Linux. También podéis consultar alguna de las //Quick Reference Cards// que os dejo aqui: * [[http://www.linuxdevcenter.com/excerpt/LinuxPG_quickref/linux.pdf|Linux Quick Reference Card]] * [[https://files.fosswire.com/2007/08/fwunixref.pdf|Unix/Linux Command Reference]] ==== Estructura del sistema ==== bin boot dev etc home lib mnt opt proc root sbin tmp usr var / \ | user1 user2 log * **bin** * **boot**: Almacena los ficheros de arranque del sistema, como el kernel * **dev**: Almacena ficheros que representan a cada uno de los dispositivos (''devices'') del sistema * **etc**: Almacena los ficheros de configuración del sistema y de las diferentes aplicaciones que se instalen * **home**: Almacena las carpetas de cada uno de los usuarios del sistema, excepto ''root'' * **lib** * **media** * **mnt** * **opt**: En principio está vacía ya que su utilidad es la instalación de software que no se integre con el sistema (''optional'') * **proc** * **root**: Carpeta de inicio del usuario ''root'' * **run** * **sbin** * **srv** * **sys** * **tmp**: Almacén de ficheros y carpetas temporales del sistema. Se vacía en cada arranque * **usr** * **var**: ==== Información del sistema ==== * Mostrar la carga media del sistema santi@zenbook:$ uptime 09:44:52 up 5 min, 2 users, load average: 0.00, 0.05, 0.03 * Mostrar información sobre el uso de CPU y los procesos del sistema santi@zenbook:$ top Mostrará, ocupando toda la pantalla, la siguiente información (se sale pulsando la tecla ''q'') top - 09:45:09 up 6 min, 2 users, load average: 0.00, 0.05, 0.02 Tasks: 69 total, 1 running, 68 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.3 id, 0.3 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 2052640 total, 1824764 free, 43292 used, 184584 buff/cache KiB Swap: 2095100 total, 2095100 free, 0 used. 1865816 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1304 daw 20 0 42692 3620 3064 R 0.3 0.2 0:00.01 top 1 root 20 0 57056 6820 5268 S 0.0 0.3 0:00.88 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 7 root 20 0 0 0 0 S 0.0 0.0 0:00.08 rcu_sched 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 9 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain 11 root rt 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0 . . . . . . * Mostrar información sobre el Sistema Operativo santi@zenbook:$ uname -a Linux despliegue-daw 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u5 (2017-09-19) x86_64 GNU/Linux * Mostrar los usuarios que tienen iniciada una sesión actualmente santi@zenbook:$ who daw tty1 Oct 7 09:39 daw pts/0 Oct 7 09:44 (192.168.1.3) * Muestra los usuarios que han iniciado sesión en el sistema (similar al comando ''who'') y alguna información extra al respecto santi@zenbook:$ w 09:55:54 up 16 min, 2 users, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT daw tty1 - 09:39 11:14 0.14s 0.09s -bash daw pts/0 192.168.1.3 09:44 1.00s 0.10s 0.00s w * Mostrar el uso de disco santi@zenbook:$ df -h Filesystem Size Used Avail Use% Mounted on udev 992M 0 992M 0% /dev tmpfs 201M 3.0M 198M 2% /run /dev/sda1 5.9G 917M 4.7G 17% / tmpfs 1003M 0 1003M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 1003M 0 1003M 0% /sys/fs/cgroup tmpfs 201M 0 201M 0% /run/user/1000 * Mostrar la información sobre un proceso (en este caso los que contengan la cadena ''apache'') santi@zenbook:$ ps aux | grep apache root 397 0.0 0.2 75608 4316 ? Ss 09:39 0:00 /usr/sbin/apache2 -k start www-data 401 0.0 0.1 364768 4068 ? Sl 09:39 0:00 /usr/sbin/apache2 -k start www-data 402 0.0 0.1 364768 4072 ? Sl 09:39 0:00 /usr/sbin/apache2 -k start daw 1378 0.0 0.0 12756 972 pts/0 S+ 09:55 0:00 grep apache ==== Carpetas y directorios ==== * Listar el contenido de una carpeta (en este caso de ''/usr/local'') santi@zenbook:$ ls /usr/local bin etc games include lib man sbin share src santi@zenbook:$ ls -la /usr/local total 40 drwxrwsr-x 10 root staff 4096 Oct 4 23:06 . drwxr-xr-x 10 root root 4096 Oct 4 23:06 .. drwxrwsr-x 2 root staff 4096 Oct 4 23:06 bin drwxrwsr-x 2 root staff 4096 Oct 4 23:06 etc drwxrwsr-x 2 root staff 4096 Oct 4 23:06 games drwxrwsr-x 2 root staff 4096 Oct 4 23:06 include drwxrwsr-x 4 root staff 4096 Oct 4 23:11 lib lrwxrwxrwx 1 root staff 9 Oct 4 23:06 man -> share/man drwxrwsr-x 2 root staff 4096 Oct 4 23:06 sbin drwxrwsr-x 7 root staff 4096 Oct 4 23:11 share drwxrwsr-x 2 root staff 4096 Oct 4 23:06 src santi@zenbook:$ cd mis_trabajos santi@zenbook:$ pwd /home/santi/mis_trabajos santi@zenbook:$ mkdir mis_trabajos * Eliminar un directorio (en este caso el directorio ''mis_trabajos'') santi@zenbook:$ rmdir mis_trabajos santi@zenbook:$ cp trabajo.pdf trabajos/ santi@zenbook:$ cp -r trabajos/ mas_trabajos/ santi@zenbook:$ mv trabajo.pdf trabajos/ santi@zenbook:$ mv trabajo.pdf mi_trabajo.pdf santi@zenbook:$ rm trabajos/mitrabajo.pdf santi@zenbook:$ rm -rf trabajos/ santi@zenbook:$ tar cvzf mis_trabajos.tar.gz mis_trabajos/ santi@zenbook:$ tar xvzf mis_trabajos.tar.gz ==== Ficheros de texto/configuración ==== * Mostrar el contenido (completo) de un fichero de texto (en este caso del fichero ''/etc/apache2/apache2.conf'') santi@zenbook:$ cat /etc/apache2/apache2.conf * Muestra las últimas líneas de un fichero (en este caso de ''/var/log/apache2/error.log'') santi@zenbook:$ tail /var/log/apache2/error.log * Muestra las últimas 100 líneas de un fichero (en este caso de ''/var/log/apache2/error.log'') santi@zenbook:$ tail -n 100 /var/log/apache2/error.log * Busca una cadena de texto (en este caso ''php'') entre las últimas 100 líneas de un fichero (en este caso ''/var/log/apache2/error.log'') santi@zenbook:$ tail -n 100 /var/log/apache2/error.log | grep 'php' ==== Permisos ==== * Añade permisos de ejecución al propietario de un fichero (en este caso ''fichero_ejecutable.sh'') santi@zenbook:$ chmod u+x fichero_ejecutable.sh * Añade permisos de lectura y ejecución al resto de usuarios para un fichero (en este caso ''fichero_ejecutable.sh'') santi@zenbook:$ chmod a+rx fichero_ejecutable.sh * Añade permisos de lectura y ejecución al usuario y grupo de un fichero (en este caso ''fichero_ejecutable.sh'') santi@zenbook:$ chmod ug+rx fichero_ejecutable.sh * Elimina permisos de lectura al grupo de un fichero (en este caso ''fichero_ejecutable.sh'') santi@zenbook:$ chmod g-r fichero_ejecutable.sh * Fijar usuario y grupo (usuario.grupo) al fichero ''mi_trabajo.pdf'' santi@zenbook:$ chown santi.santi mi_trabajo.pdf ==== Gestión de usuarios ==== * Añadir un usuario al sistema (en este caso a ''otro_usuario'') santi@zenbook:$ sudo adduser otro_usuario * Eliminar un usuario (y su carpeta de inicio) (en este caso al usuario ''otro_usuario'') santi@zenbook:$ sudo userdel -r otro_usuario * Cambiar la contraseña del usuario actual santi@zenbook:$ passwd * Añade un usuario a un grupo (en este caso añade al usuario ''santi'' al grupo ''sysadmin'') santi@zenbook:$ sudo adduser santi sysadmin * Cambiar la contraseña de otro usuario (siendo ''root'') santi@zenbook:$ sudo passwd otro_usuario * Convertirse en superusuario (root) santi@zenbook:$ su Password: root@zenbook:$ | ==== Redes ==== * Visualizar la configuración de red santi@zenbook:$ sudo ifconfig * Comprobar la conectividad de red con otro equipo (en este caso con ''192.168.1.3'') santi@zenbook:$ ping 192.168.1.3 PING 192.168.1.3 (192.168.1.3) 56(84) bytes of data. 64 bytes from 192.168.1.3: icmp_seq=1 ttl=64 time=0.161 ms 64 bytes from 192.168.1.3: icmp_seq=2 ttl=64 time=0.327 ms 64 bytes from 192.168.1.3: icmp_seq=3 ttl=64 time=0.275 ms 64 bytes from 192.168.1.3: icmp_seq=4 ttl=64 time=0.345 ms 64 bytes from 192.168.1.3: icmp_seq=5 ttl=64 time=0.305 ms 64 bytes from 192.168.1.3: icmp_seq=6 ttl=64 time=0.274 ms ^C --- 192.168.1.3 ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 5044ms rtt min/avg/max/mdev = 0.161/0.281/0.345/0.060 ms * Reiniciar la configuración de red del equipo santi@zenbook:$ sudo /etc/init.d/networking restart * Solicitar una IP al servidor DHCP (al router) santi@zenbook:$ sudo dhclient * Reiniciar el servidor web Apache santi@zenbook:$ sudo service apache2 restart ==== Inicio/Apagado ==== * Reiniciar el equipo santi@zenbook:$ sudo shutdown -r now santi@zenbook:$ sudo reboot * Apagar el equipo santi@zenbook:$ sudo shutdown -h now ==== Instalación/Desinstalación de aplicaciones ==== * Instalar un paquete/aplicación (en este caso ''apache2'') santi@zenbook:$ sudo apt-get install apache2 * Reconfigurar un paquete ya instalado (en este caso ''phpmyadmin'') santi@zenbook:$ sudo dpkg-reconfigure phpmyadmin * Eliminar completamente un paquete (en este caso ''apache2'') santi@zenbook:$ sudo apt-get remove apache2 --purge * Listar todos los paquetes instalados santi@zenbook:$ dpkg -l Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-=============================-==============================-============-====================== ========================================================= ii adduser 3.115 all add and remove users a nd groups ii apache2 2.4.25-3+deb9u3 amd64 Apache HTTP Server ii apache2-bin 2.4.25-3+deb9u3 amd64 Apache HTTP Server (mo dules and other binary files) ii apache2-data 2.4.25-3+deb9u3 all Apache HTTP Server (co mmon files) ii apache2-utils 2.4.25-3+deb9u3 amd64 Apache HTTP Server (ut ility programs for web servers) ii apt 1.4.7 amd64 commandline package ma nager ii apt-listchanges 3.10 all package change history notification tool ii apt-utils 1.4.7 amd64 package management rel ated utility programs ii aspell 0.60.7~20110707-3+b2 amd64 GNU Aspell spell-check er . . . . . . * Mostrar información detallada sobre un paquete (en este caso ''apache2'') santi@zenbook:$ apt-cache show apache2 * Corregir los fallos de alguna instalación previa que no ha terminado bien santi@zenbook:$ sudo apt-get install -f * Reinstalar un paquete (en este caso ''apache2'') santi@zenbook:$ sudo apt-get install --reinstall apache2 * Actualizar la base de datos del repositorio de paquetes santi@zenbook:$ sudo apt-get update * Actualizar todos los paquetes instalados a su versión más reciente santi@zenbook:$ sudo apt-get upgrade ==== Ayuda ==== * Mostrar el manual de un comando de Linux, en este caso del comando ''ls'' (se sale pulsando la letra ''q'') santi@zenbook:$ man ls LS(1) User Commands LS(1) NAME ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alpha- betically if none of -cftuvSUX nor --sort is specified. Mandatory arguments to long options are mandatory for short options too. -a, --all do not ignore entries starting with . -A, --almost-all do not list implied . and .. --author with -l, print the author of each file . . . . . . * Mostrar la ayuda en línea de un comando (''ls'' en este caso) santi@zenbook:$ ls --help Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. Mandatory arguments to long options are mandatory for short options too. -a, --all do not ignore entries starting with . -A, --almost-all do not list implied . and .. --author with -l, print the author of each file -b, --escape print C-style escapes for nongraphic characters --block-size=SIZE scale sizes by SIZE before printing them; e.g., '--block-size=M' prints sizes in units of 1,048,576 bytes; see SIZE format below -B, --ignore-backups do not list implied entries ending with ~ -c with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and sort by name; . . . . . . ---- (c) 2017 Santiago Faci