{"id":178,"date":"2022-07-11T09:16:52","date_gmt":"2022-07-11T09:16:52","guid":{"rendered":"http:\/\/wp.chaoyu.nl\/?p=178"},"modified":"2023-06-21T11:46:44","modified_gmt":"2023-06-21T11:46:44","slug":"linux-cli-most-used-commands","status":"publish","type":"post","link":"https:\/\/chaoyu.nl\/?p=178","title":{"rendered":"Linux CLI Most Used Commands (ongoing)"},"content":{"rendered":"\n<div class=\"wp-block-buttons is-horizontal is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-b618d73c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"#lscd\">ls\/cd<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-black-color has-vivid-green-cyan-background-color has-text-color has-background wp-element-button\" href=\"#headtail\">head\/ tail\/ cat\/ sort\/ piping<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-black-color has-vivid-green-cyan-background-color has-text-color has-background wp-element-button\" href=\"#echo\">Echo \/ Redirect<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-black-color has-vivid-green-cyan-background-color has-text-color has-background wp-element-button\" href=\"#wc\">wc \/ diff<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-black-color has-vivid-green-cyan-background-color has-text-color has-background wp-element-button\" href=\"#rmcp\">rm \/ cp \/ mv<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-black-color has-vivid-green-cyan-background-color has-text-color has-background wp-element-button\" href=\"#expan\">expansion<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-black-color has-luminous-vivid-amber-background-color has-text-color has-background wp-element-button\" href=\"#findgrep\">find \/ grep<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-black-color has-cyan-bluish-gray-background-color has-text-color has-background wp-element-button\" href=\"#dudf\">du \/ df<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-black-color has-pale-cyan-blue-background-color has-text-color has-background wp-element-button\" href=\"#history\">history<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-black-color has-vivid-cyan-blue-background-color has-text-color has-background wp-element-button\" href=\"#ps\">ps<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-vivid-purple-background-color has-text-color has-background wp-element-button\" href=\"#top\">top<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-luminous-vivid-orange-background-color has-text-color has-background wp-element-button\" href=\"#kill\">kill<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-vivid-red-background-color has-text-color has-background wp-element-button\" href=\"#gzip\">gzip<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-cyan-bluish-gray-background-color has-text-color has-background wp-element-button\" href=\"#tar\">tar<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-black-background-color has-text-color has-background wp-element-button\" href=\"#nano\">nano<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-luminous-vivid-amber-background-color has-text-color has-background wp-element-button\" href=\"#alias\">alias<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-vivid-green-cyan-background-color has-text-color has-background wp-element-button\" href=\"#xargs\">xargs<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-vivid-green-cyan-background-color has-text-color has-background wp-element-button\" href=\"#in\">in<\/a><\/div>\n\n\n\n<div class=\"wp-block-button is-style-outline is-style-outline--1\"><a class=\"wp-block-button__link has-white-color has-vivid-cyan-blue-background-color has-text-color has-background wp-element-button\" href=\"#sudo\">Sudo &amp; filepermissions<\/a><\/div>\n\n\n\n<div class=\"wp-block-button is-style-outline is-style-outline--2\"><a class=\"wp-block-button__link has-white-color has-vivid-purple-background-color has-text-color has-background wp-element-button\" href=\"#command_chaining\">Commands Chaining<\/a><\/div>\n\n\n\n<div class=\"wp-block-button is-style-outline is-style-outline--3\"><a class=\"wp-block-button__link has-white-color has-vivid-cyan-blue-background-color has-text-color has-background wp-element-button\" href=\"#environ_variable\">Environment Variables<\/a><\/div>\n\n\n\n<div class=\"wp-block-button is-style-outline is-style-outline--4\"><a class=\"wp-block-button__link has-white-color has-vivid-cyan-blue-background-color has-text-color has-background wp-element-button\" href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/nohup-command-in-linux\" target=\"_blank\" rel=\"noreferrer noopener\">nohup<\/a><\/div>\n<\/div>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">whoami\n#return current login user<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-cyan-bluish-gray-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">man : display Manual of commands<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">man whoami\n# to check mannual of a command\n# use key 'Q' to escape \n# use 'SPACE' or 'ARROW' key to navigate\nman man<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-black-color has-white-background-color has-text-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"lscd\">\n<p class=\"wp-block-paragraph\">ls : listing folder structures<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cd: navigate folder structures <\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">pwd\n#current working directory\nls\nls -l #list with detailed info, e.g permission\nls -la #list hidden, .**\nls -a # .*<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">#go 1 level up, 2 level up\ncd ..\ncd ..\/..\/<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-pale-pink-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"headtail\">\n<p class=\"wp-block-paragraph\">Head,tail : peek content of a file (default 10 lines)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cat: concate files, display content of a file (full)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sort:  sort output lines (numerica or alphabic)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">less: display file content with pagination<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">| : piping standard input to the next command<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">head file.txt #output first 10 lines (default)\nhead file.txt -n 100   #output first 100 lines\ntail file.txt #output last 10 lines (default)\ntail file.txt -n 100   #output the last 100 lines.\ntail log.txt -f # nice to have to read logfile where it keeps update\ncat file.txt #prints out all content\n\nless file.txt #prints out all content with pagination\n#within less\n\/patten #to search matching patten\n\n# sort output \n# sort output of ls , -ru : reverse and unique values only and pipe it to wc to count lines\nls | sort -ru | wc -l\n# sort output of ls, -n: sort on numbers \nls | sort -n | wc -l\n\n# display only unique lines from a file \ncat file.txt | sort -u\nsort -u file.txt\n# or combine it with uniq\n# -d show only duplicated lines\nsort file.txt | uniq -d\n# -u only non duplicated lines\nsort file.txt | uniq -u\n# -c gives a count of each unique entries\nsort file.txt | uniq -c\n# to make it more fun, we can pipe it and sort it to give it a rank\nsort file.txt | uniq -c | sort -n # low to high\nsort file.txt | uniq -c | sort -nr # hight to low<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-white-color has-vivid-red-background-color has-text-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"echo\">\n<p class=\"wp-block-paragraph\">&gt;&gt;, &gt;: Edit file Content, redirect output into file. &gt; repace &gt;&gt; concate<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo: print lines to console<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># redirect output into a file with append mode\nls -la &gt;&gt; test.txt  \n# redirect output into a file with replace mode\nls -la &gt; test.txt  \n# echo string to file\necho \"test string \" &gt; test.txt\necho \"test string \" &gt;&gt; test.txt\n\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-white-color has-luminous-vivid-orange-background-color has-text-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"wc\">\n<p class=\"wp-block-paragraph\">wc: word counts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">diff: compare file content differences<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># count file # lines # of words # of bits\nwc file.txt\nman wc # to read more \n\n# use pipe to combine commands\n# count lines of the output of ls -la\nls -la | wc\n\n# concate file1.txt and file2.txt pipe it to wc and count lines\/ words and bits\ncat file1.txt file2.txt | wc\n\n# the results of wc can also be redirected into a file like this\ncat file1.txt file2.txt | wc &gt; wcresult.txt\n\n# compare two files , use man diff to read more \ndiff filea.txt fileb.txt\n\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"rmcp\">\n<p class=\"wp-block-paragraph\">rm, cp and mv: Copy , move and remove files \/ folder<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">cp -r  #recursive , to cp folder and its nested childs \nrm -r  #recursive , to rm folder and its nested childs<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-light-green-cyan-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"expan\">\n<p class=\"wp-block-paragraph\">Expansions<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># expansions\n\n# print out all files names with .txt as extenion\necho *.txt\n# print out all files start with a, b or cand with .txt as extension\necho {a,b,c}.txt \n# print out all files with two letter as extension\necho *.??\n# print out 1 to 100\necho {1..100}\necho day{1..365}\n\n# print out all app files where its extension in js, php or py\necho app.{js,php,py} \n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-style-plain has-white-color has-cyan-bluish-gray-background-color has-text-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"findgrep\" style=\"font-style:normal;font-weight:300\">\n<p class=\"wp-block-paragraph\">Find<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">is used to search files with name\/type\/extension<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-style-plain has-pale-pink-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" style=\"font-style:normal;font-weight:300\">\n<p class=\"wp-block-paragraph\">Grep<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">is used to search content within a file.<a href=\"https:\/\/www.cyberciti.biz\/faq\/grep-regular-expressions\/\" target=\"_blank\" rel=\"noreferrer noopener\">READMORE<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">#find files, find file with name in current directory\n# find all files + directories with .py as extension\nfind . -name '*.py'\n# find all directory with name start with cap A\nfind . -type d -name 'A*'\n# -iname , case insensitive\nfind . -type d -iname 'A*'\n# or operator \n# -type f , files only\nfind . -type d -iname 'A*' -or -name 'B*'\n\n#grep keyword \"green\" from file.txt\ngrep green file.txt\n#find keyword \"green\" case sensitive within all files and subfiles in \/root\/files \ngrep -r \"green\" \/root\/files\n#find keyword \"green\" case insensitive within all files and subfiles in \/root\/files\ngrep -ir \"green\" \/root\/files\n# or if directory is not mentioned, it earches current active directory\ngrep -ir \"green\"\n# grep also allows regular express -o prints only matching part of the lines\ngrep -rE -o '^[a-zA-Z0-9]*@[a-zA-Z].[com|nl]' file.txt\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-style-default has-black-color has-light-green-cyan-background-color has-text-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"dudf\">\n<p class=\"wp-block-paragraph\">DU: display directory and files sizes <\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># -h human readable, -m megabytes, -g gigabyte\ndu -h \/foldername\ndu -m \/foldername \ndu -g \/foldername\n#get all file size in human readable format and sort it from ASC humanreadable\ndu -h \/foldername | sort -h \n\ndu -h \/foldername | sort -h | tail -12 # get the largest 12 files\ndu -h \/foldername | sort -h | head -12 # get the smallest 12 files<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-style-plain has-black-color has-pale-pink-background-color has-text-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">DF: get disk usage information<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">df -h\ndf -h \/folder<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-pale-cyan-blue-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"history\">\n<p class=\"wp-block-paragraph\">History: dispay history commands with sequence number<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">history | sort -r -n # display history and sort it large to small on number\n  126  df\n  125  history | sort -r -n\n  124  history | sort -n\n  123  history | sort -r -n\n  122  history\n  121  df -h\n  120  clear\n  119  du -h\n  118  df\n  117  clear\n  116  du -h | sort -h | head \n  115  du -h | sort -h | tail -r -12\n  114  du -h | sort -h | tail -12 -r\n  113  du -h | sort -h | tail -12\n  112  du -h | sort -h\n  111  du -mh | sort -h\n# here with \"!\" and the sequence number, can trigger run of the same command. it's called expansion\n!121\n# previous 10 history \nhistory -10\n\n#pipe history to grep and file 'grre' in the output\nhistory | grep  'grre'<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-white-color has-vivid-red-background-color has-text-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"ps\">\n<p class=\"wp-block-paragraph\">PS: display running processes<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">ps             #display user processes\nps axww        #display all (user + system processes)\n\n# display all processes and find Safari.app\nps axww | grep  'Safari.app'<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-pale-cyan-blue-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"top\">\n<p class=\"wp-block-paragraph\">Top: used to show all running processes lively dashboard<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">top           #sorting on CPU usage\n\ntop -o mem    #sorting on memory usage <\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-green-cyan-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"kill\">\n<p class=\"wp-block-paragraph\">Kill:kill process<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Killall: name<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">killall Safari\nkill 3289283<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># jobs, bg, and fg\n\njobs # display a list of running \/pending\/paused jobs\n# bg or '&amp;' sign run process in the background\nfg # brings process to the foreground\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-white-color has-pale-pink-background-color has-text-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"gzip\">\n<p class=\"wp-block-paragraph\">gzip : create zip files from file to reduce size <\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">gzip -k file.txt \n# this will create a new file called file.txt.gz\n# use ls -lh to check file size\nls -lh\n\n# -kv keep and vbose mode to show details of the zip \ngzip -kv file.txt \n\n# gzip -d = gunzip<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"tar\">\n<p class=\"wp-block-paragraph\">Tar : used to create archives, used to group files into 1 single file <\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">tar -cf groupfile.tar file1.txt file2.txt file3.txt\n# - c f , create file name : groupfile.tar, group file 1, 2, 3\n\ntar -tf groupfile.tar \n# - t f, shows what are files are in the .tar archives\n\n\ntar -xf groupfile.tar\n# extract all files within the archives in the current directory\n\ntar -xf groupfile.tar -C \/root\/foldername\n# to extract to specific folder \n\n# Combine tar archive with gzip!\n# a new file is created and compressed\ntar -czf groupfile.tar.gz file1.txt file2.txt file3.txt\n\n\n# combine unzip and untar\ntar -xf groupfile.tar.gz <\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"nano\">\n<p class=\"wp-block-paragraph\">Nano: text editor in console<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">nano file.txt\n# ctrl + k \n# to cut current line\n# ctrl + u \n# to past cutted line\n\n# ctrl + shift + 6 start select \n# use arrow key to select more \n# option + 6 to copy\n# ctrl + u to paste\n\n# navigation\n# ctrl + A to the begining of current line\n# ctrl + E to the end of current line\n# ctrl + Y go to top\n# ctrl + V go to end\n\nthere seems to be no redo and undo on Mac\n\n# option + u  redo \n# option + e  undo<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-pale-pink-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"alias\">\n<p class=\"wp-block-paragraph\">Alias: to create alias for commands<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">alias my_ls_lah='ls -lah'  # this way is not persistent\n\n# add this line to .bashrc to make it persistent\n# aad this line to .zshrc to make it persistent on Mac \n\n# Attention, \"\" and '' double and single quotes\nalias a001=\"echo $PATH\"\nalias a002='echo $PATH'\n\n# a001 the path varible to be fixed, even after new path is added after. you will not seee it\n# a002 the path is expanded at run time, any new path is displayed.\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-white-color has-vivid-cyan-blue-background-color has-text-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"xargs\">\n<p class=\"wp-block-paragraph\">xargs: similar to piping, but this is special arguments <\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">find . -size +1M | xargs ls -lah\n\n# find a files where size is larger than 1 mb and pipe arguments to ls -lah to display details <\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-pale-cyan-blue-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"in\">\n<p class=\"wp-block-paragraph\">ln : links, hard and soft links. they are like shortcuts on windows<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># create a new hard link\n\nln file.txt filelink.txt\n\necho \"new content\" &gt;&gt; file.txt \necho \"new content\" &gt;&gt; filelink.txt  \n# does the same thing..\n\n# even\nrm file.txt \n# filelink.txt still there with content.\n\n# create a soft link (windows shortcuts)\nln -s file.txt filelink.txt\n\n# examples of link\n\nls -la \/usr\/bin\/python*\n\nlrwxr-xr-x  1 root  wheel      75 Feb  6 22:22 \/usr\/bin\/python -&gt; ..\/..\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.7\/bin\/python2.7\nlrwxr-xr-x  1 root  wheel      82 Feb  6 22:22 \/usr\/bin\/python-config -&gt; ..\/..\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.7\/bin\/python2.7-config\nlrwxr-xr-x  1 root  wheel      75 Feb  6 22:22 \/usr\/bin\/python2 -&gt; ..\/..\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.7\/bin\/python2.7\nlrwxr-xr-x  1 root  wheel      75 Feb  6 22:22 \/usr\/bin\/python2.7 -&gt; ..\/..\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.7\/bin\/python2.7\nlrwxr-xr-x  1 root  wheel      82 Feb  6 22:22 \/usr\/bin\/python2.7-config -&gt; ..\/..\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.7\/bin\/python2.7-config\n-rwxr-xr-x  1 root  wheel  167072 Feb  6 22:22 \/usr\/bin\/python3\nlrwxr-xr-x  1 root  wheel      76 Feb  6 22:22 \/usr\/bin\/pythonw -&gt; ..\/..\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.7\/bin\/pythonw2.7\nlrwxr-xr-x  1 root  wheel      76 Feb  6 22:22 \/usr\/bin\/pythonw2.7 -&gt; ..\/..\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.7\/bin\/pythonw2.7\n\n# where python command is pointing at 2.7<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-green-cyan-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\" id=\"sudo\">\n<p class=\"wp-block-paragraph\">who : used to display users logged in to the system <\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote has-light-green-cyan-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Su : switch user<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote has-white-color has-midnight-gradient-background has-text-color has-background is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Sudo : super user do<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote has-white-color has-luminous-vivid-orange-to-vivid-red-gradient-background has-text-color has-background is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Chown: change ownership<\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/wp.chaoyu.nl\/wp-content\/uploads\/2022\/07\/Screenshot-2022-07-15-at-15.25.52.png\" alt=\"\" class=\"wp-image-520\" width=\"840\" height=\"168\"\/><figcaption class=\"wp-element-caption\">Red: Owner | Yellow: Group Owner<\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># list all groups \ngroups \n\n# change group ownership\n\nsudo chown work:root \/folder\n\n# change ownership of a file\nsudo chown &lt;USER&gt; &lt;FILE&gt;\n\n# change ownership of a folder\nsudo chown -R &lt;USER&gt; &lt;Folder&gt;\n\n#under stand permissions \n\ndrwxr-xr-x\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table is-style-regular has-small-font-size\"><table class=\"has-white-background-color has-background has-fixed-layout\"><thead><tr><th class=\"has-text-align-center\" data-align=\"center\">1<\/th><th class=\"has-text-align-center\" data-align=\"center\">2<\/th><th class=\"has-text-align-center\" data-align=\"center\">3<\/th><th class=\"has-text-align-center\" data-align=\"center\">4<\/th><th class=\"has-text-align-center\" data-align=\"center\">5<\/th><th class=\"has-text-align-center\" data-align=\"center\">6<\/th><th class=\"has-text-align-center\" data-align=\"center\">7<\/th><th class=\"has-text-align-center\" data-align=\"center\">8<\/th><th class=\"has-text-align-center\" data-align=\"center\">9<\/th><th class=\"has-text-align-center\" data-align=\"center\">10<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">d<\/td><td class=\"has-text-align-center\" data-align=\"center\">r<\/td><td class=\"has-text-align-center\" data-align=\"center\">w<\/td><td class=\"has-text-align-center\" data-align=\"center\">x<\/td><td class=\"has-text-align-center\" data-align=\"center\">r<\/td><td class=\"has-text-align-center\" data-align=\"center\">&#8211;<\/td><td class=\"has-text-align-center\" data-align=\"center\">x<\/td><td class=\"has-text-align-center\" data-align=\"center\">r<\/td><td class=\"has-text-align-center\" data-align=\"center\">&#8211;<\/td><td class=\"has-text-align-center\" data-align=\"center\">x<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">file type<\/td><td class=\"has-text-align-center\" data-align=\"center\">read<\/td><td class=\"has-text-align-center\" data-align=\"center\">write<\/td><td class=\"has-text-align-center\" data-align=\"center\">execute<\/td><td class=\"has-text-align-center\" data-align=\"center\">read<\/td><td class=\"has-text-align-center\" data-align=\"center\">write<\/td><td class=\"has-text-align-center\" data-align=\"center\">execute<\/td><td class=\"has-text-align-center\" data-align=\"center\">read<\/td><td class=\"has-text-align-center\" data-align=\"center\">write<\/td><td class=\"has-text-align-center\" data-align=\"center\">execute<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Position 1 options: {-,d,c,l} <em style=\"font-weight: bold;\">&#8211;<\/em> file, <strong><em>d<\/em><\/strong> directory, <strong><em>c<\/em><\/strong> character special file, <strong><em>l<\/em><\/strong> symbolic link<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1530\" height=\"477\" src=\"http:\/\/wp.chaoyu.nl\/wp-content\/uploads\/2022\/07\/Screenshot-2022-07-15-at-15.50.29.png\" alt=\"\" class=\"wp-image-531\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Position 1: indicates file type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Position 2 ~ 4 : indicates  Owner Rights<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Position 5 ~ 7 : indicates Owner Group Rights <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Position 8 ~ 10: indicates Everyone&#8217;s Rights<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1611\" height=\"743\" src=\"http:\/\/wp.chaoyu.nl\/wp-content\/uploads\/2022\/07\/Screenshot-2022-07-15-at-15.56.08.png\" alt=\"\" class=\"wp-image-536\"\/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote has-white-color has-vivid-red-background-color has-text-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">&#8220;<strong>x<\/strong>&#8221;  on folders gives &lt;<strong><em>cd&gt;<\/em><\/strong> into permission. Without it, users cannot cd into the folder<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<blockquote class=\"wp-block-quote has-light-green-cyan-background-color has-background has-medium-font-size is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>chmod<\/strong> : used to change file\/folder permissions<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">When specifying permissions with chmod, we use a special syntax to write permission statements. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>First<\/strong>, we specify the &#8220;who&#8221; part using following values:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>u<\/em><\/strong> &#8211; user (the owner of the file\/ folder)<\/li>\n\n\n\n<li><strong><em>g<\/em><\/strong> &#8211; group (owner group)<\/li>\n\n\n\n<li><strong><em>o<\/em><\/strong> &#8211; Others (the rest of the world)<\/li>\n\n\n\n<li><strong><em>a <\/em><\/strong>&#8211; all of the above (<strong><em>u, g, o<\/em><\/strong>)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">Next<\/mark><\/strong>, we tell chmod &#8220;what&#8221; we are doing using the following characters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>&#8211;<\/em><\/strong> (minus sign) removes a permission<\/li>\n\n\n\n<li><strong><em>+<\/em><\/strong> (plus sign) to grant a permission<\/li>\n\n\n\n<li><strong><em>=<\/em><\/strong> (equals sign) set a permission and removes others<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">Finally<\/mark><\/strong>, the &#8220;which&#8221; values:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>r<\/em><\/strong> &#8211; the read permission<\/li>\n\n\n\n<li><strong><em>w<\/em><\/strong> &#8211; the write permission<\/li>\n\n\n\n<li><strong><em>x<\/em><\/strong> &#8211; the execute permission<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># add write permission to group \n\nsudo chmod g+w file.txt\n\n# remove write permission to All ( user, group and world)\nsudo chmod a-w file.txt\n\n# add multiple permission at the same time\n\nsudo chmod g+rwx file.txt\nsudo chmod o-rwx file.txt\n\n# use \"=\"\n\nchmod g=r file.txt # will remove \"wx\" for group if exists (replace)\nchmod g=rx file.txt # will remove \"w\" for group if exists (replace)\n\n# change permission for user group at the same time\n\nchmod ug+r file.txt # this will add read permission for user and group at the same time<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-purple-background-color has-background is-layout-flow wp-block-quote-is-layout-flow\" id=\"command_chaining\">\n<p class=\"wp-block-paragraph\">Commands Chaining<\/p>\n<cite>; semi column || double pipe( or ) &amp;&amp; ampersand ampersand ( and )<\/cite><\/blockquote>\n\n\n\n<pre title=\"make directory named &quot;test&quot; if fails echo out &quot;directory .... &quot;\" class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\">mkdir test || echo \"directory already exisits\"<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-cyan-blue-background-color has-background is-layout-flow wp-block-quote-is-layout-flow\" id=\"environ_variable\">\n<p class=\"wp-block-paragraph\">Environment Variables<\/p>\n<cite>printenv<\/cite><\/blockquote>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash line-numbers\"># to read all environment variables\nprintenv\n\necho $PATH \n# or \nprintenv PATH<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>man : display Manual of commands ls : listing folder structures cd: navigate folder structures Head,tail : peek content of a file (default 10 lines) cat: concate files, display content of a file (full) Sort: sort output lines (numerica or alphabic) less: display file content with pagination | : piping standard input to the next&#8230;<\/p>\n","protected":false},"author":1,"featured_media":277,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-178","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=178"}],"version-history":[{"count":201,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/178\/revisions"}],"predecessor-version":[{"id":1345,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/posts\/178\/revisions\/1345"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=\/wp\/v2\/media\/277"}],"wp:attachment":[{"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chaoyu.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}