It is common that the root disk space is not enough when running a Virtual Machine in the cloud such as Amazon Web Service (AWS). The cloud storage usually provides tools or facilities to enlarge a virtual disk size. However, to make the Linux recognize and and use the enlarged disks without rebooting the OS,
Read more
Tag: Linux
How to synchronize Google Drive and Google Docs files in Ubuntu/Debian/Mint Linux using Insync
Posted onGoogle Drive is a nice cloud storage service. It provides a suite of nice online document spreadsheet and slide editors Google Docs, Google Sheets and Google Slides. The collaborative editing and full history tracking features of Google Docs are excellent. Google Drive gives 16GB free storage which is pretty much larger compared to other free
Read more
How to get date and time using date command from another timezone in Linux?
Posted ondate command on Linux gets the date and time in the system timezone. But how to get date and time using date command from another timezone in Linux? You can make date print the time of another timezone by setting the TZ environment variable. For example, export TZ=Hongkong; date Sat Dec 1 09:39:13 HKT 2018
Read more
GNOME 3 "Natural scrolling" mouse option does not work
Posted onIn GNOME 3 “Settings” -> “Devices” -> “Mouse & Touchpad”, after setting “Natural scrolling” to On, the scrolling is still as the same before (non-natural). How to fix this? This is likely related to the X11 driver. Remove the xorg-x11-drv-synaptics driver if it is installed. And install the xorg-x11-drv-libinput driver if it is not installed.
Read more
How to install GNOME 3 in Ubuntu MATE 18.04?
Posted onHow to install the GNOME 3 (gnome-shell) desktop environment in Ubuntu MATE 18.04? To install gnome3 to Ubuntu, install these packages sudo apt install gnome-session gdm3 ubuntu-desktop During installation, the installation tools will let you choose the default display manager. You may choose gdm3. Then reboot you Ubuntu Linux and gdm3 will be shown. Click
Read more
Installing Zlib from Source Code in Ubuntu Linux
Posted onZlib is a popular open-source compression library used by many software applications to compress and decompress data. While it can be installed in Ubuntu using the apt package manager, you may need to install it from the source code if the version available in the Ubuntu repositories is outdated or if you need to customize
Read more
System Call Tracking without ptrace,strace,etc.
Posted onHow could I log system calls made by another process without using current built in functions like ptrace, strace, audit etc. I think two options are intercepting the system call table, and another is modifying the entry_64.s file. I want to output these system calls to a file. Can’t find any suggestions on this anywhere.
Read more
Handling Sparse Files on Linux
Posted onSparse files are common in Linux/Unix and are also supported by Windows (e.g. NTFS) and macOSes (e.g. HFS+). Sparse files uses storage efficiently when the files have a lot of holes (contiguous ranges of bytes having the value of zero) by storing only metadata for the holes instead of using real disk blocks. They are
Read more
How to open a port in iptables?
Posted onHow to open a port, say 3389, in iptables to allow incoming traffics to it? There are several cases for this question: ipv4 or ipv6 or both, TCP or UDP or both and which interface? For simplicity, I give commands to allow all (ipv4 and ipv6, TCP and UDP from all interfaces) using port 3389
Read more
How to Add a File Based Swap for Linux
Posted onWe may want to add some swap space for a Linux box while only find that all disk space is partitioned and mounted. Some partition has large available free space. For such cases, we may not want to change the partition allocation. The solution may be to add a file based swap for Linux as
Read more
How to check whether a file of a given path is a block device in Python?
Posted onHow to check and test whether a file of a given path is a block device in Python? This can be Linux specific. You can use the os.stat() function to get the stat of the path. Then use the stat.S_ISBLK() function against the stat’s .st_mode to test whether it is a block device. An example:
Read more
How to test a file or directory exists in C++?
Posted onHow to test a path (a file or directory exists) in C++? In Bash, the [ -f ] and [ -d ] tests can test whether a file or a directory exist. What are the corresponding C++ ways for these tests? To test whether a file or dir (a path) exists, you may call stat()
Read more
How to decode a quoted URL in Python?
Posted onHow to decode a quoted URL in Python? For example, an quoted URL as follows https://www.example.com/tag/%E9%93%B6%E8%A1%8C/ should be decoded to https://www.example.com/tag/银行/ In Python 3, we can use `urllib.parse_plus()` (for URL only). One example is as follows. $ python3 Python 3.6.8 (default, Oct 7 2019, 12:59:55) [GCC 8.3.0] on linux Type “help”, “copyright”, “credits” or “license”
Read more
How to configure /dev/shm size of Linux?
Posted on/dev/shm is a nice in memory disk on Linux. The default size seems half of the physical memory’s size. How to configure shm size of Linux? And what’s the consequence? To change the configuration for /dev/shm, add one line to /etc/fstab as follows. tmpfs /dev/shm tmpfs defaults,size=8g 0 0 Here, the /dev/shm size is configured
Read more
How to exclude a package from a specific repository only in yum?
Posted onThis post https://www.systutorials.com/1661/making-dnf-yum-not-update-certain-packages/ introduces how to exclude a package from yum. But is it possible to exclude a package from a specific repository only? For example, a repository R1 I am using contains an updated version of gdb while I don’t want to use the gdb from it as I trust the version (although older)
Read more
How to resize a virtual disk of KVM
Posted onI test it for qcow2 format. Other formats are TBA. qemu-img resize kvm1.qcow2 +20G cp kvm1.qcow2 kvm1-orig.qcow2 virt-resize –expand /dev/sda1 kvm1-orig.qcow2 kvm1.qcow2 Reference: https://fatmin.com/2016/12/20/how-to-resize-a-qcow2-image-and-filesystem-with-virt-resize/ I test it for qcow2 format. Other formats are TBA. qemu-img resize kvm1.qcow2 +20G cp kvm1.qcow2 kvm1-orig.qcow2 virt-resize –expand /dev/sda1 kvm1-orig.qcow2 kvm1.qcow2 Reference: https://fatmin.com/2016/12/20/how-to-resize-a-qcow2-image-and-filesystem-with-virt-resize/
How to test whether a file exists and is a block special file in Python on Linux?
Posted onBash has a -b test to test whether a file exists and is a block special file. -b file True if file exists and is a block special file. How to do this in Python? Python’s stat module provides the similar functions for the C standard APIs and macros underlining such as stat() and S_ISBLK().
Read more
How to escape special characters in a Bash string in Linux?
Posted onThe problem is with ssh that makes a quoted string to more than one if there are spaces. For example, ssh user@host cmd “my string” The cmd on host will be executed like cmd my string rather than cmd “my string” It will only work if the string is escaped like ssh user@host cmd my
Read more
How to split and iterate a string separated by a specific character in C++?
Posted onHow to split and iterate a string separated by a specific character in C++? For example, “a string separated by space” by ‘ ‘=> [“a”, “string”, “separated”, “by”, “space”] and “a,string,separated,by,comma” by ‘,’ => [“a”, “string”, “separated”, “by”, “comma”] C++ standard library’s getline() function can be used to build a function. getline() can accept a
Read more
How to generate a password in Shell on Linux?
Posted onAdmins usually need to generate some passwords for others, such as when creating a new user in a Linux system. How to generate a password in Shell on Linux? Several possible and short methods. Here, we generate a password of length 8. Using pwgen: $ pwgen 8 1 dao3PaW9 Password based on base64 (note that
Read more