When programming in C on Linux, it is common to allocate a buffer for storing the full path of a file. How to get a safe maximum size for allocating buffers for file paths? The header <linux/limits.h> includes macros for the path and file name length limits. On my system (Fedora 21), it is located
Read more
Tag: Programming
Good tutorials for screen on Linux
Posted onAny suggestions on good tutorials for screen on Linux? To start with screen: A quick tutorial on screen. After can use the basic functions of screen, you may check out A dummies introduction to GNU Screen and A guide to GNU Screen. During all the progresses, frequently check the screen man page.
How to email admins automatically after a Linux server starts?
Posted onManaging a cluster of servers, I would like to notified when a server is started. How to make the Linux servers email me or other admins automatically after they are started? I did this by adding a crontab entry on each servers like @reboot date | mailx -S smtp=smtp://smtp.example.com -s “`hostname` started” -r zma@example.com zma@example.com
Read more
how to skip mapper function in hadoop
Posted onIn hadoop I need to skip mapper function and directly execute the reducer function. We doing this to improve hadoop performance, if the hadoop framework is used to analyze same data sets, then mapper’s output will be same for different kind of jobs. To save the redundant computation for same results, I am planning to
Read more
How to add a crontab entry from a shell script on Linux?
Posted oncrontab -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
Read more
How to set replication factors for HDFS directories?
Posted onIs it possible to set the replication factor for specific directory in HDFS to be one that is different from the default replication factor? This should set the existing files’ replication factors but also new files created in the specific directory. This can simplify the administration. We can set the replication factor of /tmp/ to
Read more
How to get files without certain strings in their files names (reverse of *string*) on Linux?
Posted onTo get files with certain string in their file names, it is quite straightforward: ls *string* However, how to do the reverse one: how to get files without certain strings in their files names on Linux? You can get a list of file names by a combination of find and xargs as follows: find .
Read more
Deleting a Specific Line From a Text File in Command Line in Linux
Posted onOn Linux, how to delete a specific line from a text file in command line? For example, to delete the 4th line from a file aaa bbb ccc ddd eee ffffff You can use the “stream editor for filtering and transforming text” sed. With GNU sed: sed -i ‘4d’ ./file Here, -i means edit the
Read more
How to enable RPM Fusion for CentOS 6.6?
Posted onHow to enable RPM Fusion for CentOS 6.6? Enable RPM fusion on RHEL 6 or compatible like CentOS: su -c ‘yum localinstall –nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm’ It will install https://fedoraproject.org/wiki/EPEL. If it fails to install EPEL automatically, you will need to install it manually. Reference: http://rpmfusion.org/Configuration
How to convert between Simplified Chinese and Traditional Chinese characters in text files on Linux?
Posted onHow 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
Read more
How to make dd faster on Linux?
Posted ondd 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
Read more
How to measure a function’s execution time in OCaml?
Posted onHow to measure the execution time of a function, say f: ‘a -> ‘b in OCaml? This small OCaml function is handy: let time f = let t = Unix.gettimeofday () in let res = f () in Printf.printf “Execution time: %f secondsn” (Unix.gettimeofday () -. t); res ;; The gettimeofday returns a float representing
Read more
How to find the number of files in each directories on Linux?
Posted onHow to find the number of files in each sub-directories of a directory on Linux? For example, . ├── a19 ├── a8 ├── d2 ├── ecfddd └── t1 The number of sub-directories can be quite large. How to find the number of files in each sub-directories here? You can use this piece of script to
Read more
What are the differences between database DDL and DML
Posted onDifferences beween DDL (Data Definition Language) and DML (Data Manipulation Language) Data Definition Language (DDL) statements are used to define the database structure or schema. Data Manipulation Language (DML) statements are used for managing data within schema objects. References:http://www.orafaq.com/faq/what_are_the_difference_between_ddl_dml_and_dcl_commands
How to change the commit message of a commit in the history (not HEAD)?
Posted onA commit is not the HEAD now. and git commit –amend will not work for it. How to change its commit message? You can use git rebase together with git commit –amend as follows. Assume your commit to be edited is 2b8ed. $ git rebase -i 2b8ed^ Change the pick to edit in the line
Read more
Which are sequence points in C?
Posted onWhat are sequence points in C? The comp.lang.c FAQ explains this quite well. A sequence point is a point in time at which the dust has settled and all side effects which have been seen so far are guaranteed to be complete. The sequence points listed in the C standard are: at the end of
Read more
How to make ctags recognize specific files with certain extensions as C source files?
Posted onHow to make ctags recognize specific files with certain extensions such as .c0 or .puc as C source files? You may add this line to your ~/.ctags: –langmap=c:+.c0,c:+.puc
How to make taglist recognize specific files with certain extensions as C source files?
Posted onHow to make taglist recognize specific files with certain extensions as C source files? You may try adding this line to your ~/.vimrc: autocmd BufRead,BufNewFile *.c0 set filetype=c Reference: https://stackoverflow.com/questions/9013263/vim-tagslist-plugin-not-detecting-custom-language-racket
How to suppress “Entering/Leaving…” messages when invoking make recursively?
Posted onThe “Entering/Leaving…” messages when invoking another make by a make is kind of annoying. Is it possible to suppress these messages and how to suppress them? For GNU make, it is controlled by options: -w, –print-directory Print a message containing the working directory before and after other processing. This may be useful for tracking down
Read more
How to resize a batch of images on Linux?
Posted onResizing images on Linux with gThumb is easy. However, I have a batch of images inside a folder. Manually resizing them will consume too much time. How to automatically resize them on Linux with a script? You can use convert from ImageMagick together with bash script to resize images inside a directory. mkdir resize; IFS=$(echo
Read more