Posts

VirtualBox commands

Here are few frequently used commands Creating a VM VBoxManage createvm — name ubuntu1804 — ostype Ubuntu_64 — register To check the info of the VM created VBoxManage showvminfo ubuntu1804 Setting Ram for VM VBoxManage modifyvm ubuntu1804 — memory 4096 — boot1 dvd — vrde on — vrdeport 5001 Create a bridge virtual network adapter VBoxManage modifyvm ubuntu1804 — nic1 nat Add a storage controller to be used with the hard disk VBoxManage storagectl ubuntu1804 — name ubuntu1804_SATA — add sata Create a new virtual hard disk image VBoxManage createhd — filename ubuntu1804.vdi — size 10280 — format VDI — variant Standard Attach the hard disk to the controller? VBoxManage storageattach ubuntu1804 — storagectl ubuntu1804_SATA — port 1 — type hdd — medium ubuntu1804.vdi Attach the dvddrive to the controller? VBoxManage storageattach ubuntu1804 — storagectl ubuntu1804_SATA — port 0 — type dvddrive — medium /home/guest1/iso/ubuntu-18.04.1-desktop...

Create custom commands in Linux (aka alias)

Image
Let’s say you are using some of the commands frequently and you don’t want to type the whole command everytime. An alternative is to create a short command for it and use that instead. First, go to the home folder in the terminal which looks like the following /home/username In case if you are in some other directory, you can type  ~  in terminal and press Enter to get there Next, you can list the contents of that directory including the hidden files using ls -a Here, -a is to show hidden files which start with dot Among the list of files, find  .bashrc  and open it At the end of the file, add some custom commands by using alias. alias [custom command name]=’[original command] Here is an example. You can create any number of custom commands here After entering the custom commands, close the terminal and open a new one.

List files in directory using Python

Image
First  import os Then call  listdir()  method as follows In terminal, first we have listed the directories. Later, we have used python to list them This is another example using Jupyter

Enable Clipboard in VirtualBox

Image
1. Open VirtualBox 2. Select the GuestOS instance where you want to enable it. 3. Right click on it and select Settings (Or click on the Settings icon above) 4. In  General , select  Advanced tab  and enable Bidirectional for  Shared Clipboard  as below. You are all set now :)

Passing a file location to python

Rather than hardcoding paths in your Python script we should make use of the path operation from module OS os.path.expanduser( path )  expands the path to the user’s home directory os.path.join( path1 ,*path2*,…)  joins path elements with the appropriate separator os.sep  gives the OS dependent path separator ( /  for Linux/Unix,  \  for Windows) os.getcwd()  gives the current working directory os.path.abspath(path)  gives the OS dependent absolute path of a given path Example: >>>import os >>>path = os.path.join(os.path.expanduser('~'), 'documents', 'python', 'file.txt') >>>print (path) Result /home/user/documents/python/file.txt ## when on Ubuntu C:\Users\user\documents\python\file.txt ## when running on Windows Source link:  https://askubuntu.com/users/3940/takkat

Ports on Ubuntu — Netstat

List all listening ports sudo netstat -plnt Filter by a particular port $ sudo netstat -plnt | grep ':80' If something else is listening on the port, you can disable the program by running  sudo service httpd stop or change its configuration so that it no longer listens on the port. When  netstat  shows the port is free, enable the correct service (for example  sudo service vsftpd start ). If you make any changes because the incorrect service is listening, run the  netstat  command again. If  netstat  doesn’t show the program listening on the correct port, you need to address its configuration before you go any further. Check status of firewall sudo ufw status verbose To allow/open a port 21 sudo ufw allow 21/tcp More:  https://www.cyberciti.biz/faq/how-to-open-firewall-port-on-ubuntu-linux-12-04-14-04-lts/