{"id":1746,"date":"2019-12-15T11:05:27","date_gmt":"2019-12-15T18:05:27","guid":{"rendered":"http:\/\/juixe.com\/techknow\/?p=1746"},"modified":"2019-12-15T11:05:27","modified_gmt":"2019-12-15T18:05:27","slug":"useful-bash-commands","status":"publish","type":"post","link":"http:\/\/juixe.com\/techknow\/index.php\/2019\/12\/15\/useful-bash-commands\/","title":{"rendered":"Useful Bash Commands"},"content":{"rendered":"<p>Every programmer should be well versed with Bash, from finding files to schedule tasks.\u00c2\u00a0 The following are some of the most common Bash commands that I use on a weekly basis.<\/p>\n<ul>\n<li>grep -i aBc &lt;FILE&gt;\n<ul>\n<li>Grep ignore case<\/li>\n<\/ul>\n<\/li>\n<li>grep &#8211;color abc &lt;FILE&gt;\n<ul>\n<li>Color highlight matching pattern<\/li>\n<\/ul>\n<\/li>\n<li>grep -v ABC &lt;FILE&gt;\n<ul>\n<li>Ignore any lines that include ABC<\/li>\n<\/ul>\n<\/li>\n<li>grep abc $(find . -mtime 0 -type f)\n<ul>\n<li>Grep recently modified files<\/li>\n<\/ul>\n<\/li>\n<li>grep &#8220;abc xyz&#8221; &lt;FILE&gt; | grep &#8220;02\/03\/19 09&#8221;\n<ul>\n<li>Find all lines that contain &#8220;abc xyz&#8221; and then find the remaining lines that contain the following timestamp<\/li>\n<\/ul>\n<\/li>\n<li>ps -ef | grep java\n<ul>\n<li>Find Java processes<\/li>\n<\/ul>\n<\/li>\n<li>history | grep git\n<ul>\n<li>Find all commands in the history that contain the word git<\/li>\n<\/ul>\n<\/li>\n<li>history -cw\n<ul>\n<li>Clear history<\/li>\n<\/ul>\n<\/li>\n<li>wc -l &lt;FILE&gt;\n<ul>\n<li>Number of lines in file<\/li>\n<\/ul>\n<\/li>\n<li>ls -1 | wc -l\n<ul>\n<li>Count the number of files in the current directory<\/li>\n<\/ul>\n<\/li>\n<li>ls -lh\n<ul>\n<li>Show the size unit of the file, such as K for kilobyte, M for megabyte, etc<\/li>\n<\/ul>\n<\/li>\n<li>ln -s &lt;SOURCE_FILE&gt; &lt;LINK_FILE&gt;\n<ul>\n<li>Create a symbolic file link reference to &lt;SOURCE_FILE&gt;<\/li>\n<\/ul>\n<\/li>\n<li>df -P &lt;FILE&gt;\n<ul>\n<li>Find free disk space and if it&#8217;s mounted<\/li>\n<\/ul>\n<\/li>\n<li>du -hs\n<ul>\n<li>Find disk usage for each file in current directory<\/li>\n<\/ul>\n<\/li>\n<li>cat \/dev\/null &gt; &lt;FILE&gt;\n<ul>\n<li>Clear\/wipe file<\/li>\n<\/ul>\n<\/li>\n<li>zip -r &lt;FILE&gt;\n<ul>\n<li>Zip all contents in current directory into the specified zip file<\/li>\n<\/ul>\n<\/li>\n<li>zip -er &lt;FILE&gt; &lt;DIRECTORY&gt;\n<ul>\n<li>Zip and encrypt all contents in given directory into the specified zip file<\/li>\n<\/ul>\n<\/li>\n<li>zip -d &lt;FILE&gt; &#8220;file.txt&#8221;\n<ul>\n<li>Remove file file.txt from the specified zip file<\/li>\n<\/ul>\n<\/li>\n<li>unzip -l &lt;FILE&gt;\n<ul>\n<li>List contents of given zip file<\/li>\n<\/ul>\n<\/li>\n<li>diff -rq &lt;DIRECTORY_ONE&gt; &lt;DIRECTORY_TWO&gt;\n<ul>\n<li>Recursively diff two directory structures<\/li>\n<\/ul>\n<\/li>\n<li>crontab -l\n<ul>\n<li>List cron rules for current user<\/li>\n<\/ul>\n<\/li>\n<li>crontab -e\n<ul>\n<li>Open crontab for editing<\/li>\n<\/ul>\n<\/li>\n<li>at -f &lt;COMMAND&gt; -t 201906160701\n<ul>\n<li>Schedule a command or batch file to run at the specified time<\/li>\n<\/ul>\n<\/li>\n<li>atq\n<ul>\n<li>List current scheduled tasks<\/li>\n<\/ul>\n<\/li>\n<li>atrm\n<ul>\n<li>Remove a scheudle task<\/li>\n<\/ul>\n<\/li>\n<li>uuidgen\n<ul>\n<li>Create a 128-bit UUID<\/li>\n<\/ul>\n<\/li>\n<li>date | md5\n<ul>\n<li>Use md5 on a date to generate a UUID based on a hash<\/li>\n<\/ul>\n<\/li>\n<li>$RANDOM\n<ul>\n<li>Create a random number between 0 and 32k<\/li>\n<\/ul>\n<\/li>\n<li>tcpdump -ni eth0 -vvv -s0 -w capture.pcap\n<ul>\n<li>Listen to eth0 interface in verbose mode and write out to file<\/li>\n<\/ul>\n<\/li>\n<li>tcpdump -ni eth0 port 1812 or port 1813 -vvv -s0 -w capture.pcap\n<ul>\n<li>Listen to eth0 interface for only ports 1812 and 1813<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Every programmer should be well versed with Bash, from finding files to schedule tasks.\u00c2\u00a0 The following are some of the most common Bash commands that I use on a weekly basis. grep -i aBc &lt;FILE&gt; Grep ignore case grep &#8211;color abc &lt;FILE&gt; Color highlight matching pattern grep -v ABC &lt;FILE&gt; Ignore any lines that include [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[17,19,3,4],"tags":[824,827,826,825],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p902K-sa","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/1746"}],"collection":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/comments?post=1746"}],"version-history":[{"count":1,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/1746\/revisions"}],"predecessor-version":[{"id":1747,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/1746\/revisions\/1747"}],"wp:attachment":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/media?parent=1746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/categories?post=1746"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/tags?post=1746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}