In Python, how to process read a file line by line to process it? Like those lines in Bash: while read line ; do echo $line done < ./input.txt In Python, you can process a file line by line by a for in the file like with open(“./input.txt”, “r”) as thefile: for line in thefile: […]
In Python, how to get hostname as the command hostname does on Linux? In Python, you can get the hostname by the socket.gethostname() library function in the socket module: import socket hostname = socket.gethostname() Reference: https://www.systutorials.com/dtivl/20/how-to-get-the-hostname-of-the-node?show=34#a34 Answered by zma.
I got this error when I tried to save a file with a space in its name into HDFS: $ hdfs dfs -put -f “/home/u1/testa/test a” “/u1/testa/test a” put: unexpected URISyntaxException while the HDFS seems allow spaces in its file names: https://hadoop.apache.org/docs/r2.7.3/hadoop-project-dist/hadoop-common/filesystem/model.html . How to achieve the effect of saving the files with spaces in […]
In Python, how to get an environment variable? In Python, you may use this piece of code to get an environment variable: os.environ.get(‘ENV_MIGHT_EXIST’) or this piece of code: os.getenv(‘ENV_MIGHT_EXIST’) It will return None if the environment variable is not present. Reference and for more ways, please check https://www.systutorials.com/dtivl/13/how-to-get-an-environment-variable?show=80#answer-80 . Answered by zma.
In Go lang, how to get an environment variable? To get an environment variable (e.g. “VAR”) in GO: import “os” import “fmt” fmt.Println(“VAR:”, os.Getenv(“VAR”)) Answered by zma.
In Python, how to get the epoch time (the number of seconds since epoch)? In Python, you can get the epoch time by calling time.time(): import time print time.time() Reference: https://www.systutorials.com/dtivl/16/how-to-get-the-epoch-timestamp#answer-18 Answered by zma.
The download page of Hadoop http://hadoop.apache.org/releases.html only contains several recent release packages. I would like to download some old release packages such as Hadoop 2.5.0 which is not available anymore on the release page. Where to download a copy of the old release? You can download the old release packages of Hadoop on the http://archive.apache.org […]
How to extract the images from a PDF file in Linux? You may use the pdfimages tool. To output jpg images from a PDF ./a.pdf, run pdfimages -j ./a.pdf ./images The images in ./a.pdf will be extracted and saved as ./images-nnn.jpg. Answered by anonymous.
In Bash script, how to join multiple lines from a file? For example, to join the lines a good boy to a good boy You can use tr command, something like: tr -s ‘n’ ‘ ‘ < file.txt It just goes through its input and makes changes according to what you specify in two sets […]
How to export my Google Chrome password on Linux to a human-readable text file? In newer versions of Chrome, the passwords are stored using the encrypted password storage provided by the system, either Gnome Keyring or KWallet. We need to force Chrome to use a temporary profile folder with unencrypted password storage. Step 1. Connect […]
Hi, I noticed that your site serves AdSense ads through BuySellAds and it is not in an iframe. By default, BuySellAds puts the backfill ads in an iframe. Puting AdSense ads in iframe is violation of the terms. How do you make BuySellAds not put AdSense ads in an iframe? Thanks! To inline the ads […]
There are various lightning cables on the market. I ever purchased one but it does not work for iPhone 6… How to identify a certificated lightning cable that is good for iPhone 6? (I know the cables from Apple will definitely work. But it takes time to receive one from Apple or not always easy […]
How to sort all the files in a directory and subdirectories recursively by modification time on Linux? You can make use of find (GNU find, or plus stat), sort and sed together to achieve recursively sort files by modification time: find . -type f -printf ‘%T@ %pn’ | sort -k 1 -n | sed ‘s/^[^ […]
I recently changes the media aspects. The problem is that the existing thumbnails are not changed to the new aspects. How to make WordPress regenerate the thumbnails after I changing the media aspects? The “Regenerate Thumbnails” works like a charm for me: https://wordpress.org/plugins/regenerate-thumbnails/ . It allows you to regenerate your thumbnails after changing the thumbnail […]
crontab -e will start an editor to edit the crontab entries. But how to add a crontab entry from a shell script on Linux without interaction from users? You can try this piece of script: (crontab -l; echo “@reboot echo “rebooted””;) | crontab – Note that the update by this line of script is not […]
How to convert between Simplified Chinese and Traditional Chinese characters in text files on Linux from command line? You can use opencc to convert between Traditional Chinese and Simplified Chinese: https://github.com/BYVoid/OpenCC For example, to transfer a file in simplified Chinese sc.txt to traditional Chinese: opencc -i sc.txt -o tc.txt -c zhs2zht.ini The authors also provide […]
dd seems slow when I use command like # dd if=/dev/sda2 of=./sda2.bak How to make it faster? You can make dd faster by specifying a good bs like # dd if=/dev/sda2 of=./sda2.bak bs=8192 8192 is a magic number. There are may be other good sizes for bs for different systems. But 8192 works pretty well […]
How to un-trust a computer that I have trusted with iOS 7 device, such as iPhone? You can delete the Lockdown folder to reset the trust/un-trust status of iPhones. Apple provides tutorials for Max OS X and Windows at: http://support.apple.com/kb/TS5335 (archived) . If you are using Linux, the Lockdown folder is: /var/lib/lockdown Answered by Lucy.
How to get a tree-like view of the git commit history? My favorite command line: git log –graph –oneline It will prints a text based graph like (with colors): * b5dc8b9 Merge branch ‘master’ of https://github.com/layerzero/libi0 | | * 7514ef1 revised the README.md a little bit | * 6692428 align size to page for both […]
libvirt uses files for VM images by default under /var/lib/libvirt/images/. LVM is a convenient tool for managing VM images. How to use LVM groups with libvirt? This post discusses the method to add LVM groups as a storage pool for libvirt: http://ailoo.net/2011/02/use-a-lvm-volume-group-with-libvirt/ For a general introduction of the storage management in libvirt, please check: http://libvirt.org/storage.html […]