I set up rules to ignore all files under git by adding a .gitignore like * But how to unignore some files or dirs in git? For example unignore all files under ./bin/tool1/ under the git repository. You can use patterns with ! as the prefix to “unignore” files. From gitignore man page: An optional prefix “!”
Read more
Tag: Tutorial
How to remove newline characters from a string in C++?
Posted onHow to remove newline characters from a string in C++? For example, a string like line 1 line 3 line 4 should be converted to line 1line 3line 4 Method 1: use `erase()` and `remove()` In short, use this code snippet: input.erase(std::remove(input.begin(), input.end(), ‘\n’), input.end()); std::remove() shifts all elements that are equal to the value
Read more
How to cat a single file’s content from a tar without unpacking it on Linux?
Posted onHow to cat a single file’s content from a tar without unpacking it on Linux? For example, I know there is a file README.txt in a tar tools.tar.gz . How to cat the content of README.txt out? You can do this by using a combination of tar‘s options and arguments. -O, –to-stdout Extract files to
Read more
How to change the default target of `make`?
Posted onThe default target of make is the first target. But can I change the default target in Makefile and how to change the default target of make? The default goal of make is the first target whose name does not start with ‘.’ if .DEFAULT_GOAL is not set. Ref: make manual. To set the default
Read more
How to test whether a given path is a directory or a file in C++?
Posted onHow to test whether a given path is a directory or a file in C++? For example, pathtype(“/”) –> “a dir” pathtype(“/tmp/file.txt”) –> “a file” # if there is a file file.txt pathtype(“/tmp/dir.txt”) –> “a dir” # if there is a dir named dir.txt The type of a file/dir can be found out using lstat()
Read more
how to list and delete shared memory in linux?
Posted onhow to list and delete shared memory in linux? List all shared memories in your Linux Systems > $ ipcs -m Delete specific one > $ ipcrm -M 0x0001869c
How to get one process’s port number?
Posted onIf we want to check one program on one remote server, we need to know this server’s IP and port number. How to get this program’s port number in the remote server? # netstat -tulpn Remember to run this program with root permission since some programs can only be accessed by root.
How to get a server’s serial number remotely?
Posted onHow to get a server’s serial number remotely? Tested on Linux Ubuntu 14.04 Trusty > sudo apt-get install dmidecode > sudo dmidecode -s system-serial-number I tried this on several Linux boxes with CentOS 7 and it seems A physical node returns a string like System Serial Number. A KVM VM returns a string like 3fd12bba-12d4-48c7-875a-7a5f57ed8a9a.
Read more
How to judge whether its STDERR is redirected to a file in a Bash script on Linux?
Posted onWithin a Bash script, how to judge whether its STDERR is redirected to a file in Bash on Linux? For example, ./script.sh /tmp/log 2>&1 Can script.sh detect that its STDERR is redirected? Knowing the destination file is better. To test whether a script’s STDERR (or STDOUT) is redirected to a file, check by [[ -f
Read more
how to set linux date and time in commands
Posted onhow to set linux date and time in commands For example, to change date to 14 Nov 2017 11:57:00, the command would be, $ sudo date –set “14 Nov 2017 11:57:00” Tue Nov 14 11:57:00 HKT 2017
In Python, `os.makedirs()` with 0777 mode does not give others write permission
Posted onIn Python, os.makedirs() with 0777 mode can not give others write permission The code is as follows $ python Python 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> import os >>> os.makedirs(“/tmp/test1/test2”, 0777) >>> The created dirs are not
Read more
How to split a string by string in Python?
Posted onHow to split a string by string in Python? For example, “a string separated by space” => [“a”, “string”, “separated”, “by”, “space”] and “a,string,separated,by,comma” => [“a”, “string”, “separated”, “by”, “comma”] Python’s string.split() standard library function, if provided a separator, will split the string by the separator, for example >>> str2 = “a,string,separated,by,,,comma” >>> str2.split(“,”) [‘a’,
Read more
How to install alien on CentOS 7 to convert .deb to .rpm?
Posted onHow to install the alien command on CentOS 7 to convert .deb to .rpm? alien is already in EPEL and it makes it quite easy to install it in CentOS 7. First, enable EPEL following this tutorials. Then, install alien by # yum install alien Then alien should be ready: # yum info alien Installed
Read more
How to autohide top and bottom panel in RHEL 7
Posted onHow to autohide top and bottom panels in RHEL 7 while application is running I don’t think GNOME 3 or GNOME 3 classic has this function available or there any plugins that supports so. If you need this function that the panel can hide automatically, you may consider another desktop environment, such as MATE, that
Read more
How to get the value of a default value if the key does not exist in `dict()` in Python?
Posted onHow to get the value of a default value if the key does not exist in dict() in Python? We can use the get() function to assign default value if the key does not exist in the dict yet. dict.get(key[, default]) Example as follows. msges = {“msg”: “Hello, World!”} msg = msges.get(“msg”, “”) print(msg) #
Read more
How to force a fsck during next rebooting of Linux?
Posted onHow to force a fsck of a file system, say the root, during the next rebooting of Linux? 2 possible ways: /forcefsck way for / # touch /forcefsck and reboot. Next time the / will be fsck’ed . systemd way Add these 2 kernel boot parameters: fsck.mode=force fsck.repair=yes What these 2 kernel parameters do: KERNEL
Read more
How to check interrupts lively in your systems?
Posted onI need to see what kind of interrupts are handled by which CPU. Please run command: # cat /proc/interrupts or you can execute $ watch -n1 “cat /proc/interrupts” to watch interrupts every 1 second. See [1] [2] for more details. References: [1] https://stackoverflow.com/questions/28301875/how-to-observe-interrupts-in-windows-or-linux-ubuntu-14-04 [2] http://www.linuxjournal.com/content/watch-live-interrupts
How to force a checkpointing of metadata in HDFS?
Posted onHDFS SecondaraNameNode log shows 2017-08-06 10:54:14,488 ERROR org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode: Exception in doCheckpoint java.io.IOException: Inconsistent checkpoint fields. LV = -63 namespaceID = 1920275013 cTime = 0 ; clusterId = CID-f38880ba-3415-4277-8abf-b5c2848b7a63 ; blockpoolId = BP-578888813-10.6.1.2-1497278556180. Expecting respectively: -63; 263120692; 0; CID-d22222fd-e28a-4b2d-bd2a-f60e1f0ad1b1; BP-622207878-10.6.1.2-1497242227638. at org.apache.hadoop.hdfs.server.namenode.CheckpointSignature.validateStorageInfo(CheckpointSignature.java:134) at org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode.doCheckpoint(SecondaryNameNode.java:531) at org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode.doWork(SecondaryNameNode.java:395) at org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode$1.run(SecondaryNameNode.java:361) at org.apache.hadoop.security.SecurityUtil.doAsLoginUserOrFatal(SecurityUtil.java:415) at org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode.run(SecondaryNameNode.java:357) It seems the checkpoint
Read more
How to flush STDOUT buffer in Python?
Posted onHow to flush the STDOUT buffer in Python so that the content wrote to STDOUT is shown immediately? Call the flush library function on sys.stdout which is the STDOUT: import sys sys.stdout.flush() From python doc: flush() Flush the write buffers of the stream if applicable. This does nothing for read-only and non-blocking streams. If you
Read more
How to tune systems to achieve high performance in virtualization circumstances?
Posted onMost time, we need to tune system parameters to achieve better performance but what the general parameters to be tuned in Linux systems. I think you may want to add following parameters to Kernel boot (/etc/default/grub) parameters intel_idle.max_cstate=0 processor.max_cstate=0 idle=poll intel_pstate=disable At the same time, you may also want to shutdown/open Pause Loop Exiting (PLE).
Read more