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
Read more
Category: QA
Questions and answers.
Ubuntu’s GUI response is very slow
Posted onFor Dell PowerEdge T630 server, if you install latest Ubuntu desktop version (16.04) or (14.04), you will get a very slow GUI (X-window). $ inxi -G Graphics: Card: Matrox Systems G200eR2 X.org: 1.15.1 driver: vesa tty size: 205×58 Advanced Data: N/A out of X For Ubuntu 14.04.1, this problem can be solved by following steps.
Read more
How to remove the bottom panel in gnome 3 classic?
Posted onThe gnome 3 classic’s bottom panel looks not useful to me. I do not use it. How to remove the bottom panel in gnome 3 classic? That bottom panel is from the “Window List” plugin. The gnome 3 classic package depends on that plugin package on CentOS 7 as far as I checked. And Gnome
Read more
How to redirect non-www domain to www domain in .htaccess?
Posted onI have a website. But I would like use the www.example.com instead of example.com. How to redirect non-www domain to www domain on my server? I am using apache2 (httpd). You can add a piece of code into the top .htaccess in your site: Specific method: redirect example.com domain to www.example.com domain RewriteEngine On RewriteBase
Read more
How to make output jpeg file of xsane smaller on Linux?
Posted onxsane’s output jpeg file is large (10+MB). But we usually do not need it to make a so big jpeg file. Some compression (even lossy) will be good. How to make output jpeg file of xsane smaller on Linux? You can adjust the output file size by changing the compression levels and quality. Through the
Read more
How to save the output of screen windows to a file on Linux?
Posted onIn the screen, copying the history of the window output is quite hard. How to save the screen easily to a file? First type Ctrl + A then : to get to command mode. In the command mode, execute hardcopy -h /path/to/file screen will save the window output to /path/to/file.
How to detect whether a file is readable and writable in Python?
Posted onBefore reading or writing a file, access should be checked first. How to detect whether a file is readable and writable in Python? You can use the os.access(path, mode) library function https://docs.python.org/release/2.6.6/library/os.html#os.access like the Linux access library function for C. It returns True if access is allowed, False if not. For readable and writable, you
Read more
How to set up HP printer and scaner on CentOS 7?
Posted onHow to set up the driver for an HP all-in-one printer/scanner on CentOS 7 Linux? First, install these packages and it may ask you to download and install other plugins. Without these packages, my printer does work. # yum install hplip hplip-gui hpijs Second, install plugins for the HP printer. # hp-plugin Then you can
Read more
How to make tee catch the stderr only in Linux?
Posted onI would like to make tee catch the stderr and log it into a file. A brute force method by let tee listen on both stderr and stdout is okay like cmd 2>&1 | tee -a log But how to make tee catch the stderr only? You can make use of “process substitution” (>(…)) to
Read more
How to handle spaces in paths with rsync on Linux?
Posted onThe common rsync commands seems not handle spaces well. For example, rsync -avxP file “user@server:/data/my dir” It reports: rsync: link_stat “/home/zma/file” failed: No such file or directory (2) How to make rsync handle spaces well? You can use the –protect-args option of rsync. $ rsync –protect-args -avxP file “user@server:/data/my dir” What does –protect-args do: -s,
Read more
How to make a unique temporary file in Bash on Linux?
Posted onIt is common to make a unique temporary file. How to make a unique temporary file in Bash on Linux safely and quickly? You can use the mktemp program. In the simplest way, tmpfile=$(mktemp) The file will be like /tmp/tmp.j0wD39Mr3b if you do not prefer any meaningful names. You can set the file to your
Read more
In Python, how to check whether a key already exists in a dict?
Posted onHow to check whether a key already exists in a dict in Python since version 2.6? If d is a dict(), you can directly test whether a key k is in d in Python by the in keyword like if k in d: ..
How to collect VM exit numbers in KVM
Posted onSometimes, we may want to know the specific benchmark can cause what kind of VM exits. 1, Install perf. 2, # perf kvm stat record -a ^C 3, # perf kvm stat report This will report your VM exit numbers and what kind of operation lead to VM exit. You may need to compare many
Read more
How tinstall aria2 on CentOS 7?
Posted onHow tinstall aria2 on CentOS 7? aria2 is a great tool for downloading files from the Internet. The software package for aria2 is proved in EPEL. To install aria2, first, enable EPEL following instructions here. Then, install aria2 by # yum install aira2
How to install curlftpfs on CentOS 7?
Posted oncurtlftpfs is a nice tool to mount ftp to local. How to install curlftpfs on CentOS 7? The software package for curlftpfs is proved in EPEL. To install curlftpfs, first, enable EPEL following instructions here. Then, install curlftpfs by # yum install curlftpfs
How to get the IP addresses of VMs in KVM with virsh
Posted onWhen we create VMs in KVM, we may don’t know the IP addresses because they are automatically assigned by DHCP. So we want to get them in VMM so that can login by SSH. Do the commands as follows. $ virsh domiflist hvm1 Interface Type Source Model MAC ——————————————————- vnet0 network default virtio 52:54:00:1c:36:cd $
Read more
How to use vnc to connect remote server with GUI desktop
Posted onFor my case, I need to bypass one intermediate server so that I can connect to the remote server with vnc. For example, there are two servers (s1, s2) except my local PC and I have to login to s1 so that I can login s2 from my local PC. However, now, I need to
Read more
How to install sshfs on CentOS 7?
Posted onsshfs is a nice tool. But it seems there is no support to it in a newly installed CentOS 7 Linux system: Not installed by default: # sshfs -bash: sshfs: command not found Seems not available from the repositories # yum install sshfs -y Loaded plugins: fastestmirror Repodata is over 2 weeks old. Install yum-cron?
Read more
How to change CONFIG_HZ parameter for Linux Kernel
Posted onIf we want to change the tick time for Linux Kernel, we need to change CONFIG_HZ parameter in Linux Kernel. Do we have other better ways to change it rather than compiling Linux Kernel. Please ignore the way to add ‘divider=10’ in grub config file because it is limited only for RH/CentOS distros. Zhiqiang, please
Read more
How to make Ubuntu Linux boot to text mode?
Posted onMy Ubuntu boots to GUI mode by default. How to make Ubuntu Linux boot to text mode? If you are using Ubuntu older than 16 such as Ubuntu 14.04: Edit /etc/default/grub Change GRUB_CMDLINE_LINUX=… to GRUB_CMDLINE_LINUX=”text”. Backup your old grub config`$ sudo cp -n /etc/default/grub /etc/default/grub.bak-date +%s ` Update grub$ sudo update-grub If you are using
Read more