My Avatar

LanternD's Castle

An electronics enthusiast - survive technically

Tips on Ubuntu

2018-07-01

Some quick fixes and minor hacks on Ubuntu. I update it every now and then.

A Few Words

I encounter problem every now and then on Ubuntu. I decide to take some notes on what I get when searching through websites like StackOverflow.

Last update: 2019-04-05.

Tips

Command about listing

How to add a .desktop executable file to start menu and “favorites”?

.desktop file usually comes with the software packages in .tar.bz format, for example, Zotero. When you double click to execute the zotero.desktop, you can not add it to the side bar (favorites). The solution is:

1
ln -s ~/Software/Zotero_linux-x86_64/zotero.desktop ~/.local/share/applications

I just use Zotero to illustrate, other software is likewise. After the symbol exists, you can find it in start menu by press the super (win) key. Open Zotero, and now you can add it to the side bar by right clicking the icon.

2019.03.14 Update: GUI desktop entry editor.

Change file owner and user group

Suppose the file name is “so_happy.org”

1
sudo chown user:group so_happy.org

The userhao and group are the ones you want to set.

Change file permission

Allow file execution:

1
sudo chmod +x your_file

Set read/write/execute

1
sudo chmod 755 your_file

There are three bits to represent readable/writable/executable. Then 000 - 111 are mapped to 0-7 decimal digits.

The three digits in the command are owner, group, others.

Read more: AskUbuntu.

Hold back a package in apt upgrade

Link.

1
sudo apt-mark hold <package>

[] TODO How to ignore packages in Ubuntu Software Updater?

Change user password

1
sudo passwd your_user_name

Type the old password first, then the new one.

Switch between root and normal users

1
2
sudo -i  # switch to root (temporarily)
su your_user_name  # switch to some user.

Change End-of-Line (EOL) of a file

Link.

Install dos2unix.

1
sudo apt install dos2unix

Process file with it.

1
dos2unix input_file.txt output_file.txt

This is especially helpful for the file ~/.aspell_pws/.aspell.en.pws. Once Spacemacs is run on Windows, the EOL will be changed to DOS (I synchronize this file with Dropbox).

Use shortcut to open the file explorer (Nautilus)

Link: Setting a key shortcut to run an application in GNOME - Fedora Docs

Open System Settings -> Devices -> Keyboard. Scroll to the end. Add a new shortcut. The command to open new folder window is nautilus -w. I bind it to Super+E, same as Windows.

img

Btw, I also change the “Hide all normal window” shortcut to Super+D (also, same as Windows).

img

Taking area screenshot with shortcut

Link: How to change the keyboard shortcut to take screenshots with Shutter? - StackOverflow.

  1. Install shutter (Available in Ubuntu Software Center).
  2. Go to System Settings -> Devices -> Keyboard (same as above).
  3. Scroll down to the bottom, add a personal shortcut (Ctrl + Shift + Alt + Z for me).
  4. Give it a name, whatever. The command is shutter -s.
  5. If you want to take a full screenshot, change the command to shutter -f, or simply press the PrintScreen key.

Convert GBK-encoded files to UTF-8 encoding

Link: Linux下GBK->UTF-8文件编码批量转换命令.

  1. Install enca by apt: sudo apt install enca.
  2. Check the usage via man enca.
  3. In our case, run the command in terminal:
1
2
3
enca -L zh_CN file  # check the encoding of the file
enca -L zh_CN -x UTF-8 file  # convert GBK to UTF-8
enca -L zh_CN -x UTF-8 file1 file2  # convert file1 to UTF-8 and save to file2

Note: it supports wild card matching, like *.tex.

Using USB pass-through to Oracle VirtualBox

Link: How to set up USB for Virtualbox?

Minimize the window when clicking the dock icon

Link: Click on Icon to Minimize Application Window in Ubuntu 18.04

Open terminal, type in the following command and press .

1
gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize'

Done.

Check gnome version

1
gnome-shell --version

Dump and load a postgresql database

Link: How to import and export a PostgreSQL database.

1
pg_dump -U <username> -W <dbname> > ~/path_of_backups/postgresql_db.pgsql
1
psql -U <username> <db_name> < ~/path_of_backups/postgresql_db.pgsql

Notice that the command is different.



Disqus Comment 0