{"id":210,"date":"2016-05-13T19:50:17","date_gmt":"2016-05-13T14:20:17","guid":{"rendered":"http:\/\/www.bhuvankrishna.in\/blog\/?p=210"},"modified":"2025-02-23T00:13:55","modified_gmt":"2025-02-22T18:43:55","slug":"bits-of-code","status":"publish","type":"post","link":"https:\/\/www.bhuvankrishna.in\/blog\/2016\/05\/13\/bits-of-code\/","title":{"rendered":"bits of code"},"content":{"rendered":"\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Move content of the current directory to a sub-directory excluding the sub-directory<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shopt -s extglob dotglob\nmv !(new) new\nshopt -u dotglob<\/code><\/pre>\n\n\n<nav class=\"is-responsive wp-block-navigation is-layout-flex wp-block-navigation-is-layout-flex\" aria-label=\"primary\" \n\t\t data-wp-interactive=\"core\/navigation\" data-wp-context='{\"overlayOpenedBy\":{\"click\":false,\"hover\":false,\"focus\":false},\"type\":\"overlay\",\"roleAttribute\":\"\",\"ariaLabel\":\"Menu\"}'><button aria-haspopup=\"dialog\" aria-label=\"Open menu\" class=\"wp-block-navigation__responsive-container-open\" \n\t\t\t\tdata-wp-on--click=\"actions.openMenuOnClick\"\n\t\t\t\tdata-wp-on--keydown=\"actions.handleMenuKeydown\"\n\t\t\t><svg width=\"24\" height=\"24\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M4 7.5h16v1.5H4z\"><\/path><path d=\"M4 15h16v1.5H4z\"><\/path><\/svg><\/button>\n\t\t\t\t<div class=\"wp-block-navigation__responsive-container\"  id=\"modal-1\" \n\t\t\t\tdata-wp-class--has-modal-open=\"state.isMenuOpen\"\n\t\t\t\tdata-wp-class--is-menu-open=\"state.isMenuOpen\"\n\t\t\t\tdata-wp-watch=\"callbacks.initMenu\"\n\t\t\t\tdata-wp-on--keydown=\"actions.handleMenuKeydown\"\n\t\t\t\tdata-wp-on--focusout=\"actions.handleMenuFocusout\"\n\t\t\t\ttabindex=\"-1\"\n\t\t\t>\n\t\t\t\t\t<div class=\"wp-block-navigation__responsive-close\" tabindex=\"-1\">\n\t\t\t\t\t\t<div class=\"wp-block-navigation__responsive-dialog\" \n\t\t\t\tdata-wp-bind--aria-modal=\"state.ariaModal\"\n\t\t\t\tdata-wp-bind--aria-label=\"state.ariaLabel\"\n\t\t\t\tdata-wp-bind--role=\"state.roleAttribute\"\n\t\t\t>\n\t\t\t\t\t\t\t<button aria-label=\"Close menu\" class=\"wp-block-navigation__responsive-container-close\" \n\t\t\t\tdata-wp-on--click=\"actions.closeMenuOnClick\"\n\t\t\t><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" aria-hidden=\"true\" focusable=\"false\"><path d=\"m13.06 12 6.47-6.47-1.06-1.06L12 10.94 5.53 4.47 4.47 5.53 10.94 12l-6.47 6.47 1.06 1.06L12 13.06l6.47 6.47 1.06-1.06L13.06 12Z\"><\/path><\/svg><\/button>\n\t\t\t\t\t\t\t<div class=\"wp-block-navigation__responsive-container-content\" \n\t\t\t\tdata-wp-watch=\"callbacks.focusFirstElement\"\n\t\t\t id=\"modal-1-content\">\n\t\t\t\t\t\t\t\t<ul class=\"wp-block-navigation__container is-responsive wp-block-navigation\"><li class=\"wp-block-navigation-item menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-393 current_page_item current_page_parent wp-block-navigation-link\"><a class=\"wp-block-navigation-item__content\"  href=\"https:\/\/askubuntu.com\/a\/91743\" target=\"_blank\"   title=\"\"><span class=\"wp-block-navigation-item__label\">Source<\/span><\/a><\/li><\/ul>\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div><\/nav>\n\n\n<p class=\"wp-block-paragraph\"><strong>How to<\/strong> <strong>chroot properly. What are the devices and directories to mount<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for i in \/dev \/dev\/pts \/proc \/sys \/run; do sudo mount -B $i \/mnt\/$i; done<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>To create user in kobotoolbox<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have access to the hosted server:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can get into the kpi container doing:<br><code>docker exec -it &lt;kpi&gt; bash<\/code><\/li>\n\n\n\n<li>Then enter the Django shell:<br><code>.\/manage.py shell_plus<\/code><\/li>\n\n\n\n<li>Then from inside the ipython shell, you can create a user doing the following:<br><code>User.objects.create(username='&lt;some new user&gt;')<\/code><\/li>\n\n\n\n<li>Or if you are creating a whole bunch of users:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>for user in users:\n    User.objects.create(username=user)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(Additionally you can assign permissions to those users as you create them through the shell \u2014 perhaps listing usernames and permissions in your spreadsheet, importing that and iterating through as you create and assign, etc. I can send through some sample code if that will be useful)<\/p>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>pretify json via commandline<code><br>cat myfile.json | python -m json.tool<\/code><\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Start Unetbootin in debian. change sudo to su accordingly.<code><br>sudo export QT_X11_NO_MITSHM=1 unetbootin<\/code><br><a href=\"https:\/\/bbs.archlinux.org\/viewtopic.php?pid=1508298#p1508298\">archlinux forum<\/a><\/li>\n\n\n\n<li>Reset git HEAD<code><br>git reset HEAD~1<\/code><\/li>\n\n\n\n<li>Include full path in the output of find command for current directory<code><br>find -name \"filename\" -exec readlink -f {} \\;<\/code><\/li>\n\n\n\n<li>Check progress of dd command while writing to a drive. Very useful while creating bootable pen drives.<br><br>Create bootable drive.<code><br>dd if=[iso path] of=[device] bs=4<\/code><br><br>While the above command is running open another terminal and give this command and check output in previous terminal<code><br>watch -n5 'sudo kill -USR1 $(pgrep ^dd)'<\/code><br><\/li>\n\n\n\n<li>How to come out of ssh connections that got closed.<code><br>Enter, ~, .<\/code>&nbsp;type these on the terminal whose connection is lost.<\/li>\n\n\n\n<li>Play music from a folder and sub folders.<code><br>mplayer -playlist &lt;(find \"$PWD\" -name \"*.mp3\" -type f)<\/code><\/li>\n\n\n\n<li>Adjust recording time for gnome default recorder which is activated with CTRL+ALT+SHIFT+R and to stop use the same combination before max recording time is reached or recording will stop automatically reaching the max time.<code><br>gsettings set org.gnome.settings-daemon.plugins.media-keys max-screencast-length 360<br><br>360 sec<\/code><\/li>\n\n\n\n<li>Extract audio from video file<code><br>ffmpeg -i sample.avi -q:a 0 -map a sample.mp3<\/code><\/li>\n\n\n\n<li>List all public_html folder with long list in home directory<code><br>find . -maxdepth 1 -type d -exec ls -l {} + | grep 'public_html' | grep 'drw'<\/code><\/li>\n\n\n\n<li>List files based on extension, date and copy them to a directory<code><br>find . -type f -newermt 2018-04-18 ! -newermt 2018-04-19 | grep php | xargs -P 2 -I _FILE_ cp _FILE_ [foldername]\/<\/code><\/li>\n\n\n\n<li>Sort unique values and get word with length between 8 and 63<code><br>cat [textfile] | sort | uniq | pw-inspector -m 8 -M 63 &gt; [textfile]<\/code><\/li>\n\n\n\n<li>Exclude folders from compression with tar. Make sure to remove trailing \u2018\/\u2019<code><br>tar -zcv --exclude='[folder]' -f [backup.tgz] [dir_to_backup]<\/code><\/li>\n\n\n\n<li>find zombie processes<code><br>ps xao pid,ppid,pgid,uname,stat,comm | awk '$5==\"Zs\"'<\/code><\/li>\n\n\n\n<li>Find size of directories from the current path and sort them in decending order with highest first.<code><br>du -sch * | sort -h -r<\/code><\/li>\n\n\n\n<li>Command to get hardware information in the system<code><br>inxi -Fxz<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Check history of changes to a file in git<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">to list only commits details for specific file changes,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git log --follow file_1.rb\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">to list difference among various commits for same file,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git log -p file_1.rb\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">to list only commit and its message,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git log --follow --oneline file_1.rb\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/stackoverflow.com\/questions\/8048584\/see-changes-to-a-specific-file-using-git\">link<\/a> of the source<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Move content of the current directory to a sub-directory excluding the sub-directory How to chroot properly. What are the devices and directories to mount To create user in kobotoolbox If you have access to the hosted server: (Additionally you can assign permissions to those users as you create them through the shell \u2014 perhaps listing\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.bhuvankrishna.in\/blog\/2016\/05\/13\/bits-of-code\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":10,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":598,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/210\/revisions\/598"}],"wp:attachment":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}