Ejecutando el comando anterior con sudo

Muy a menudo en Linux, ejecutamos un comando solo para ver un error que muestra ‘Permiso denegado’. Entonces nos damos cuenta de que habíamos olvidado sudo antes del comando y volvemos a escribir el comando, esta vez con un sudo delante.

Ejemplos:

rohan@Rohan-PC:~$ apt-get update
Reading package lists... Done
W: chmod 0700 of directory /var/lib/apt/lists/partial failed - 
SetupAPTPartialDirectory (1: Operation not permitted)
E: Could not open lock file /var/lib/apt/lists/lock - open 
(13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - 
RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - 
RemoveCaches (13: Permission denied)

rohan@Rohan-PC:~$ sudo apt-get update
[sudo] password for rohan: 
Get:1 http://packages.microsoft.com/repos/vscode stable InRelease [2, 802 B]
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease                
Hit:3 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial InRelease 
Ign:4 http://dl.google.com/linux/chrome/deb stable InRelease           
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Hit:6 https://deb.nodesource.com/node_8.x xenial InRelease             
Hit:7 http://ppa.launchpad.net/hanipouspilot/rtlwifi/ubuntu xenial InRelease
Hit:8 http://dl.google.com/linux/chrome/deb stable Release             
Get:9 http://packages.microsoft.com/repos/vscode stable/main amd64 Packages [77.9 kB]
Hit:10 http://ppa.launchpad.net/maarten-baert/simplescreenrecorder/ubuntu xenial InRelease
Get:12 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Hit:13 https://download.sublimetext.com apt/stable/ InRelease          
Hit:14 http://ppa.launchpad.net/noobslab/apps/ubuntu xenial InRelease  
Get:15 http://archive.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Hit:16 http://ppa.launchpad.net/noobslab/macbuntu/ubuntu xenial InRelease
Hit:17 http://packages.treasuredata.com/3/ubuntu/xenial xenial InRelease
Get:18 http://nginx.org/packages/ubuntu xenial InRelease [4, 339 B]     
Ign:18 http://nginx.org/packages/ubuntu xenial InRelease    
Hit:19 http://ppa.launchpad.net/otto-kesselgulasch/gimp/ubuntu xenial InRelease
Hit:20 http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu xenial InRelease
Hit:21 http://ppa.launchpad.net/videolan/master-daily/ubuntu xenial InRelease
Hit:22 https://dl.winehq.org/wine-builds/ubuntu xenial InRelease
Hit:23 https://download.docker.com/linux/ubuntu xenial InRelease
Hit:24 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease
Fetched 408 kB in 3s (117 kB/s)                     
Reading package lists... Done

La situación se vuelve frustrante cuando el comando que ha escrito es largo. Ciertamente no querrías volver a escribir ese comando largo. Para resolver este problema, se presenta el siguiente truco genial de Linux:

Command : sudo !!

Este comando repite el comando anterior con sudo al frente. Sin duda, ahorra mucho tiempo y esfuerzo y evita la frustración entre los geeks.

Example:
rohan@Rohan-PC:~$ apt-get update
Reading package lists... Done
W: chmod 0700 of directory /var/lib/apt/lists/partial failed - 
SetupAPTPartialDirectory (1: Operation not permitted)
E: Could not open lock file /var/lib/apt/lists/lock - open 
(13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - 
RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - 
RemoveCaches (13: Permission denied)

rohan@Rohan-PC:~$ sudo !!
sudo apt-get update
Hit:1 http://packages.treasuredata.com/3/ubuntu/xenial xenial InRelease
Ign:2 http://dl.google.com/linux/chrome/deb stable InRelease           
Hit:3 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial InRelease 
Hit:4 http://archive.ubuntu.com/ubuntu xenial InRelease                
Hit:5 http://dl.google.com/linux/chrome/deb stable Release             
Get:6 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:8 http://nginx.org/packages/ubuntu xenial InRelease [4, 339 B]      
Hit:9 https://dl.winehq.org/wine-builds/ubuntu xenial InRelease        
Ign:8 http://nginx.org/packages/ubuntu xenial InRelease                
Hit:10 http://ppa.launchpad.net/hanipouspilot/rtlwifi/ubuntu xenial InRelease
Hit:11 https://download.sublimetext.com apt/stable/ InRelease          
Hit:12 http://ppa.launchpad.net/maarten-baert/simplescreenrecorder/ubuntu xenial 
InRelease
Get:13 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Hit:14 http://ppa.launchpad.net/noobslab/apps/ubuntu xenial InRelease  
Get:15 http://archive.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Hit:16 https://deb.nodesource.com/node_8.x xenial InRelease            
Hit:17 https://download.docker.com/linux/ubuntu xenial InRelease       
Hit:18 http://ppa.launchpad.net/noobslab/macbuntu/ubuntu xenial InRelease
Hit:19 http://ppa.launchpad.net/otto-kesselgulasch/gimp/ubuntu xenial InRelease
Hit:20 http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu xenial InRelease
Hit:21 http://ppa.launchpad.net/videolan/master-daily/ubuntu xenial InRelease
Get:22 http://packages.microsoft.com/repos/vscode stable InRelease [2, 802 B]
Hit:23 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease
Fetched 330 kB in 3s (103 kB/s)                     
Reading package lists... Done

Publicación traducida automáticamente

Artículo escrito por rohan23chhabra y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *