Helpful Ubuntu Tips - jacobmoroni/ubuntu_hacks GitHub Wiki

Command Line Stuff

General Ubuntu Stuff

Ros Stuff

Python Stuff

Package and Program installation stuff


Command Line Stuff

  • ifconfig -- see connection and networking information

  • sudo nmtui -- set up wifi in terminal

  • hostname -I --see own ip address

  • ls -ltrh /dev/video* --list all video devices plugged in

  • Look for lost files (if you accidentally delete them): strings /dev/<partition> | grep -c $[<lines>*2] "<exact text>" > </some/file/on/another/partition/file.txt> Replace with the partition that your files were on, replace with how many lines you want to search in either direction when you find the text. Replace with exact text you know was in your file. This will a text file with all of the bits from your file where it found the exact text you searched for + #of lines in each direction. The new partition where you create the txt file can be a partition on a flash drive or an external hard drive.

  • sudo fdisk -l --show partitions on your computer

  • nmap -sP 192.168.0.1/24 --See all IP addresses on network

  • ssh <username>@<IPaddress> --SSH into another computer

  • ssh-copy-id <username>@<hostname>.local remember the password after you log in so you dont need it anymore

  • ps -ax --shows all running processes

  • ps -ax | grep <desired program> --search all processes for a desired program (use this if you need to kill something)

  • kill <process number> -- kill a process. Replace <process number with number returned from ps -ax | grep <S program>

  • pkill -f <desired progam> will automatically kill all processes associated with that program (faster than ps -ax method if you know what you want to kill)

  • xkill lets you click on a program you want to kill

  • df -- show memory of all hard drives include --block-size=g to see in GB,--block-size=m to see in MB, and --block-size=k to see in KB

  • htop --show processor and memory usage

  • scp username@ip:path/to/file/ /path/to/destination --copy a file from SSH to local

  • scp /path/to/file username@ip:/path/to/destination --copy a file from local to SSH

  • grep -rnw '/path/to/somewhere/' -e 'pattern' --search for 'pattern' in files inside '/path/to/somewhere'.

    • -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. Along with these, --exclude, --include, --exclude-dir flags could be used for efficient searching:

    • This will only search through those files which have .c or .h extensions: grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"

    • This will exclude searching all the files ending with .o extension: grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"

    • For directories it's possible to exclude a particular directory(ies) through --exclude-dir parameter. For example, 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"

    more details can be found here

  • -j<number> and -l<number> -- used for cmake and catkin make to control how many threads you want. On an i7 you can usually do twice the ammount of threads as you have cores the -l is for load sharing, to prevent overloading your cores. Use these to speed up builds or slow them down to prevent crashing

  • If you copy files out to NTFS or exfat memory it doesnt keep read write permissions so when you copy it back, you need to fix the permisions. this lets you fix those with a single command

    • set files in folder to 644 find </desired_location> -type f -print0 | xargs -0 chmod 0644

    • set folders in folder to 755 find </desired_location> -type d -print0 | xargs -0 chmod 0755

  • Convert files in bulk from .CR2 to .jpg parallel convert {} {.}.jpg ::: *.CR2 Runs parallel to convert as quickly as possible.

  • screen usage tips

    • install with sudo apt install screen
    • start a new screen screen -S <name>
    • detach from screen Ctrl + a d
    • see currently running screens screen -ls
    • reatach to a screen screen -r if you have only one, or screen -r <session ID> to reattach to a specific on (sreen -ls shows the session ID next to the name)
    • here is some more stuff if that isnt enough
  • Undo an uzip command: unzip -l filename | awk 'BEGIN { OFS="" ; ORS="" } ; { for ( i=4; i<NF; i++ ) print $i " "; print $NF "\n" }' | xargs -I{} rm -v {} this scrapes through the files and deletes them. the last time I wrote this, it didnt remove the empty directories though so it isnt perfect. but it helped a lot:


General Ubuntu stuff

  • ctrl-alt-F1 through F6 -- open terminal interface outside of GUI (helpful for recovery stuff)

  • ctrl-alt-F7 --enters GUI interface mode (normal mode)

  • numlock default to on on startup 16.04:

    1. install numlockx sudo apt install numlockx
    2. add greeter-setup-script=/usr/bin/numlockx on to bottom of file: usr/share/lightdm/lightdm.conf.d/50-unity-greeter.conf
  • numlock default on startup 18.04 sudo -i

    Switch to user gdm in the terminal: su gdm -s /bin/bash

    Finally set ‘Numlock on’ via gdm user: gsettings set org.gnome.settings-daemon.peripherals.keyboard numlock-state 'on'

    Restart the computer and done

  • ubuntu 18.04 right click touchpad reenable first sudo apt install gnome-tweaks if it isnt installed yet then in Keyboard and mouse select Area for the mouse options

  • when folders have green background in terminal. Usually caused by copying files from a flash drive or hard drive. See below for meaning:

    image

    remove green background with chmod o-rw <directory name>

  • move program to other monitor (16.04) use compizconfig-settings-manager or ccsm with 'put' plugin and assign "put to next output" see this link for more details. I have assigned it to ctrl-super-m on my computer.

  • Remapping thumb button for mx master: first install xautomation (sudo apt-get install xautomation) :

      Go to Settings > Keyboard > Shortcut and add a new personal shortcut.
      Give it the name you want and the following command : xte 'usleep 100000' 'keydown Super_L' 'key S' 'keyup Super_L'
      Click on your new shortcut to assign a new trigger and press the thumb button (or press Ctrl+Alt+Tab)
    
  • to see the last time a file was modified stat -c '%y' filename

  • Disable caps lock and set to only turn it on by pressing both shift keys at once

    • Option 1: just use gnome tweaks: Gnome Tweaks -> Keyboard & Mouse -> Additional Layout Options -> Caps Lock Behaviour
    • Option 2: do it with dconf
    1. Install DCONF sudo apt install dconf-tools
    2. Disable caps lock and reenable it as pressing both shift keys at once: setxkbmap -option "caps:none" && setxkbmap -option "shift:both_capslock"
    3. Optionally set Caps as extra Ctrl with setxkbmap -option "caps:ctrl_modifier"
  • Change Login Screen in ubuntu 18.04

    1. edit /usr/share/gnome-shell/theme/ubuntu.css file (with sudo) sudo vim /usr/share/gnome-shell/theme/ubuntu.css
    2. change
    #lockDialogGroup{
      background: #2c001e url(resource:///org/gnome/shell/theme/noise-texture.png);
      background-repeat: repeat;}
    

    to

    #lockDialogGroup
    {
      background: #2c001e url(file:///<fileLocation/filename.png>);
      background-repeat: no-repeat;
      background-size: cover;
      background-position: center;
    }
    

    but replace <fileLocation/filename.png> with the actual location and filename you want (Reboot required to take effect). It seems like you might have to do this every time gnome updates. here is an example of the file url url(file:///home/jacob/Pictures/background_green.jpg)

  • change thumbnail size in nautilus.

    First make sure experimental view is disabled gsettings set org.gnome.nautilus.preferences use-experimental-views false

    Then change thumbnail size. This changes it to 400% gsettings set org.gnome.nautilus.icon-view thumbnail-size 400

    then kill nautilus. and restart it killall nautilus

  • Push repo to github from gitlab repo (works vice-versa as well)

    create an empty repo on GitHub

    git remote add github https://[email protected]/yourLogin/yourRepoName.git

    git push --mirror github

  • To set up chrome webpages as desktop apps:

    1. Click the 3 dots on the top-right corner
    2. Click More tools
    3. Click Create shortcut...
    4. Select the Open as window checkbox

    Chrome > Version 70 (Update for new versions of Chrome, where no Open as window checkbox appears):

    1. Click the 3 dots on the top-right corner
    2. Click More tools
    3. Click Create shortcut...
    4. Click Create
    5. Navigate to chrome://apps
    6. Right-click on the new app
    7. Click Open as window

    Then once they are created, if you double click on the desktop icons created, then click trust and launch, you will be able to add them to startup (with gnome-tweaks) if you right click on the icon and click properties there is a line that says command. that is the command that will launch from the command line. so you can use that to set up aliases.

  • I recently did a firmware update and my computer stopped booting into ubuntu. The problem ended up being that the EFI (booting) partition got marked hidden so it could only boot to windows. I will detail things that I did to fix it to remember in case it happens again. The way I fixed it was

    1. Using a bootable linux flashdrive to boot into linux (just use the Try Ubuntu without Installing option) and install some stuff.

      • side note with this: When I was trying to boot into the bootable drive I was just getting pixelated lines accross my screen. The fix to this is detailed here. But I will include the gist of it here in case that site dies. You need to add the nomodeset parameter to the to grub. to do this:

      • Procedure to add nomodeset to grub:

        • Stop the installation to the grub menu.
        • Press e to edit the menu entry you choose (e.g Try Ubuntu Without Installing) and it will lead to edit the boot parameters.
        • Find the line which ends with quiet splash and add nomodeset in front of it. So it becomes nomodeset quiet splash. Whatever is there in front of it leave it as it is just add nomodeset in front of quiet splash.
        • Press Ctrl+X or F10 to boot with this new parameter.
    2. Once you can actually boot into linux from the flash drive. You need to install boot-repair there are pretty good instructions here but once again, I'll go through what I actually had to do to get it to work.

      • either from an Ubuntu live-session (boot your computer on a Ubuntu live-CD or live-USB then choose "Try Ubuntu") or from your installed Ubuntu session (if you can access it)

      • connect to the Internet

      • open a new Terminal, then type the following commands (press Enter after each line):

      sudo add-apt-repository ppa:yannubuntu/boot-repair
      sudo apt-get update
      sudo apt-get install -y boot-repair && boot-repair
      
      • then after boot-repair opens, click Recommended Repair and hopefully that will just work.
        • when I ran it it was complaining that there was not ESP partition. But really there was. It was just hidden. to fix it i ran gparted right clicked on the EFI partition and then clicked manage flags. then unchecked the hidden flag and closed gparted. Then when I ran it again it fixed my issue.

ROS Stuff

  • View an image streaming in ROS: rosrun image_view image_view image:=<topic> or rqt_image_view then select the topic in the gui

  • Echo a topic in ros repeating it in the same place rather than scrolling: rostopic echo <topic> -c

  • Get info from mocap system: rosrun vrpn_client_ros vrpn_client_node _server:=192.168.0.103 _refresh_tracker_frequency:=10

  • export ROS_MASTER_URI=http://<ipaddress>:11311 export ROS_IP=http:$(hostname -I) -- point to roscore on another machine to visualize on yours. You can replace with either the tartget IP address of where you want to point to, or just the user name, if you have it saved in /etc/hosts with the IP address.

  • To make Gazebo end quicker: sudo vim /opt/ros/melodic/lib/python2.7/dist-packages/roslaunch/nodeprocess.py and change the following variables _TIMEOUT_SIGINT = 0.5 #seconds _TIMEOUT_SIGTERM = 0.5 #seconds

  • throttle a topic rosrun topic_tools throttle messages <in topic> <rate> <optional out topic>

  • Error [REST.cc:205] during startup gazebo You need to change ~/.ignition/fuel/config.yaml as following. url: https://api.ignitionfuel.org to url: https://api.ignitionrobotics.org

  • using python3 with ROS:

    • at top of python files include #!/usr/bin/env python3 rather than #!/usr/bin/env python
    • for rosbag:
      • pip3 install pycryptodome pycryptodomex gnupg
      • tf.transformations does not appear to work with python3

Python Stuff

  • Breakpoints and debugging in python: from IPython.core.debugger import set_trace or from ipdb import set_trace or from pdb import set trace (Depending on whether you are using iPython or just normal python) then use set_trace() in the line you want to insert the break point. Then when in the debugging mode, C-n moves to the next line and it works just like iPython live editor.

  • if you messed up pip stuff, fix it with this

sudo apt purge python3-pip  
rm -rf '/usr/lib/python3/dist-packages/pip'  
sudo apt install python3-pip   
cd
cd .local/lib/python3/site-packages
sudo rm -rf pip*  
cd
cd .local/lib/python3.6/site-packages
sudo rm -rf pip*  
pip3 install --upgrade pip setuptools wheel --user

here is a link to the thread that I found

I also deleted ~/.cache/pip because I was getting a warning about it and I think it fixed the problem

do this for python2 if you managed to mess that one up too. then reboot computer here

the you are good to start installing packages using pip --user


Package/Program Install instructions

OpenScene Graph

  • to install openscene graph from ppa
sudo add-apt-repository ppa:openmw/openmw
sudo apt update
sudo apt install openscenegraph-3.4 libopenscenegraph-3.4-dev

JAVA jdk 12

sudo add-apt-repository ppa:linuxuprising/java
sudo apt update
sudo apt install oracle-java12-installer
sudo apt install oracle-java12-set-default

Tizen Studio Prereqs

Had to do some weird stuff to get it to work on ubuntu 18.04

[this doesnt work...] as of 5-21-19 tizen studio doesnt support openjdk 11 so you need to install openjdk 8. acutally openjdk at all isnt really supported if you want to use the emulator. so skip the following and install oracle java 8

here are instructions to install it. or

sudo apt install default-jre
sudo apt install default-jdk
sudo apt install openjdk-8-jdk
sudo apt install openjdk-8-jre

then sudo update-alternatives --config java and set to java 8

then sudo update-alternatives --config javac and set to java 8

THIS WORKS HERE --> so as of writing this, openjdk doesnt let you open an emulator so you need oracle jdk 8 which 18.04 doesnt have a funcitoning ppm for. here is what I did that maybe works

download the tar.gz for jdk 8 here then copy it into /usr/lib/jvm (with sudo)

then unpack and install it tar zxvf jdk-8uversion-linux-x64.tar.gz <-- change the '8uversion' to whatever the file name is. then you need to change the symlinks to java and javac to point to this rather than whatever else you have. so go to /usr/bin and run sudo ln -s /usr/lib/jvm/jdk1.8.0_211/bin/java java but replace the jdk1.8.0... with whatever the installation is. then do it with javac too check if it worked with java -version and javac -version

then the rest of the install from the tizen site should work here are a couple other packages that it will prompt you to install if you havent installed them yet. sudo apt install libwebkitgtk-1.0-0 rpm2cpio libsdl1.2debian bridge-utils openvpn

Need to do that stuff before installing tizen studio.

Eigen

  • EIGEN --Be careful with this. I think sudo apt install libeigen3-dev works for just about all cases
   git clone https://github.com/eigenteam/eigen-git-mirror.git
   cd eigen-git-mirror
   git checkout tags/3.3.5
   mkdir build && cd build
   cmake ..
   sudo make install

VLC

This is a very handy tip on how to prevent VLC from freezing when playing hd video

I included a plugin that will allow jumping back a single frame as well. it is included in dotfiles/JumpToTimeV3.lua. copy that file into /usr/lib/x86_64-linux-gnu/vlc/lua/extensions/ then when you open vlc under the View menu click on Jump To Time (Previous Frame) v3 and it opens a little gui that lets you jump one frame at a time (or any ammount of time for that matter)


⚠️ **GitHub.com Fallback** ⚠️