Sunday, August 6, 2017

Command not found when using sudo

Give sudo your current PATH with:
sudo env "PATH=$PATH" your_command
 
 
Elaborating on @opyate's answer, I am using the following shell script (which may be named mysudo, for example):
#!/bin/bash
sudo -E env "PATH=$PATH" "$@"
  • -E tells sudo to preserve the environment.
  • env "PATH=$PATH" is expanded outside the sudo call, making the external PATH available inside the sudo too (this is required in addition to the -E as the PATH usually receives special treatment in addition to the treatment the entire environment receives).
  • "$@" passes the arguments our script receives to the sudo line.
Save the script in a file in a directory in the PATH, give it +x permissions, et voilĂ .
 
Since the current answers are a little vague, the specific setting in /etc/sudoers changing your path is secure_path:
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
You can modify it it with sudo visudo, or better yet, add the directories you need:
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
shareimprove this answer
 
 

Saturday, August 5, 2017

Run multiple command together

command1 && command2
    run command2 only if command1 is success

command1 || command2
    run command2 only if command1 failed.

command1 ; command2
    run command2 after command1 no matter what happen to command1



How to get System Information in Ubuntu

sudo lshw -short
sudo lshw -html >sysiinfo.html
lscpu lsblk lspci lsusb
dmidecode
sudo dmidecode -l memory
ex. memory, baseboard, bios, processor, chassis,

To add more desktops to Ubuntu

sudo apt install ubuntu-gnome-desktop

Choose lightdm
Logout and click on Ubuntu Logo
Choose gnome desktop

sudo apt install cinnamon-desktop-environment -y