1. Show Desktop
Control + Win + D
2. Lock Desktop
Control + Alt + L
3. Delete current command quickly
Control + U
4. List file size (Directory)
du -sh /path
5. List installed packages
sudo apt list –installed | grep “name”
6. Check information without opening file
cat xxx.txt | grep “name”
tail xxx.txt
7. Ubuntu install deb file
// sudo apt install ./xxx.deb
sudo dpkg -i ./xxx.deb
sudo install -f
8. tmux
Control + A Then (Up, Down, Left, Right) switch windows (Default tmux is Control + B)
9. TensorBoard
tensorboard --logdir=/path/to/logdir
10. SCP
# 1. Download file through server to client:
scp username1@hostname1:/path/to/file /local/path/to/file
# 2. Upload file from client to server:
scp /path/to/local/file username@hostname:/path/to/remote/file
# 3. Upload folders:
scp -r /source /destination
11. virtualenv
# Create:
virtualenv /path/to/venvs/
# Activate:
source /path/to/venvs/name/bin/activate
# For Python 3:
sudo apt-get install python3-venv
python3 -m venv /path/to/new/virtual/environment
12. Git to Gerrit
git pull
git add ...
git commit -m "..."
git pull --rebase
git push origin HEAD:refs/for/master
13. Fast Copy and Paste:
Select the text you want to copy, then go to the place where you want to copy to and press the scroll wheel of the mouse.
14. Check file / folder size du
command.
Size of a directory:
$ du -sh /tmp
Size of a file:
$ du -h /tmp/xyz
15. Download file using SFTP
# Connection:
sftp username@remote_hostname_or_IP
# Download:
get (-r) some_remote_file
# Upload:
put (-r) some_local_file
# OR download directly:
sftp username@remote_address:/path/to/file/some_remote_file
16. Download files from URL in terminal
wget "http://......"
# or
wget -o /path/to/file "http://......"
17. Update specific package in Ubuntu:
apt-get install --only-upgrade <packagename>
18. Compress and extract files:
Compress a folder:
tar -zcvf archive-name.tar.gz directory-name
tar -xvzf example.tar.gz
To explain a little further, tar collected all the files into one package, example.tar. The gzip program applied compression, hence the gz extension. So the command does a couple things:
f
: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file.
z
: tells tar to decompress the archive using gzip
x
: tar can collect files or extract them. x
does the latter.
v
: makes tar talk a lot. Verbose output shows you all the files being extracted.
Extracting bz2 files:
tar xvjf file.tar.bz2
Uncompressing tar file (.tar):
tar xvf file.tar
And to uncompress tar file (.tar) to another directory:
tar xvC /var/tmp -f file.tar
For zip and unzip:
Unzip file:
unzip xxx.zip ./
unzip xxx.zip ./
zip file:
zip xxx.zip zzz.xxx
zip a folder:
zip -r example.zip example/
19. Terminal New Tab
In terminal, press Control + Shift + T:
This operation will open a new terminal tab page in the same directory as the current one.
Press Control + Shift + W to close the current tab.
20. Terminate Ubuntu File Manager:
Sometimes, the Ubuntu file manager will get stuck, and we can’t open any folder or the trash can, we can terminate Nautilus by:
# If nautilus is in the middle of doing something you should use the first command as it allows nautilus to exit gracefully.data.
nautilus -q
# OR
killall nautilus
21. Convert audio from pcm to wav or from wav to pcm:
From wav to pcm:
ffmpeg -i file.wav -f s16le -acodec pcm_s16le file.pcm
From pcm to wav:
ffmpeg -f s16le -ar 44.1k -ac 2 -i file.pcm file.wav
where those parameters mean:
-f s16le
… signed 16-bit little endian samples-ar 44.1k
… sample rate 44.1kHz-ac 2
… 2 channels (stereo)-i file.pcm
… input filefile.wav
… output file
22. Recursively delete all files with a given extension:
find . -name '*.o' -delete
23. Take screenshots:
PrtSc – Save a screenshot of the entire screen to the “Pictures” directory.
Shift + PrtSc – Save a screenshot of a specific region to Pictures.
Alt + PrtSc – Save a screenshot of the current window to Pictures.
Ctrl + PrtSc – Copy the screenshot of the entire screen to the clipboard.
Shift + Ctrl + PrtSc – Copy the screenshot of a specific region to the clipboard.
Ctrl + Alt + PrtSc – Copy the screenshot of the current window to the clipboard.