commandref.txt 150 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031
  1. # Never-do's in UNIX (The Unix programming environment - Mark Burgess page: 11)
  2. * Don't ever call a program or an important file 'core'. Many scripts go around
  3. deleting files called 'core' because, when a program crashes, UNIX dumps the
  4. entire kernel image to a file called 'core' and these files use up a lot of
  5. disk space. If you call a file 'core' it might get deleted!
  6. * Don't call test programs test. There is a UNIX command which is already
  7. called test and chances are that when you try to run your program you will
  8. start the UNIX command instead. This can cause a lot of confusion because the
  9. UNIX command doesn't seem to do very much at all!
  10. w.xx.y-zzz
  11. w - kernel version, xx - major revision, y - minor revision, zzz - patch number
  12. i386 - 32bit
  13. amd64 - 64bit
  14. Note:
  15. adding rw init=/bin/bash to boot parameters will open a full root session for
  16. anyone who happens to push the power button on your PC. If you think you might
  17. need this kind of access, I would advise you to create a secure BIOS or GRUB
  18. password to protect yourself.
  19. Note:
  20. always tar up a directory, not an individual files
  21. echo $LANG
  22. echo $MAIL # To output the location of your inbox
  23. echo $PATH
  24. echo $SHELL
  25. echo $TERM
  26. printenv # to display environment variables
  27. name=newton
  28. echo $name # $ symbol is used before a variable in echo command
  29. newton
  30. ulimit # get and set user limits
  31. # bash prompt
  32. The bash prompt is set by the environment variable PS1 (Prompt String 1), which
  33. is used for interactive shell prompts. There is also a PS2 variable, which is
  34. used when more input is required to complete a bash command.
  35. [user@$host ~]$
  36. [user@$host ~]$ export PS1="[Linux Rulez]$ "
  37. [Linux Rulez]$
  38. PS1 is a regular environment variable. The system default value is set in
  39. /etc/bashrc. If you want to see a custom prompt, however, you should not be
  40. editing /etc/bashrc. You should instead add it to .bashrc in your Home
  41. directory.
  42. \u: username
  43. \h: short hostname
  44. \W: basename of the current working directory (~ for home)
  45. \s: shell name (bash or sh, depending on how the shell is called)
  46. \v: the shell's version
  47. \d: expands to the date in the format "Tue Jan 27"
  48. \D{fmt}: allows custom date formats (see man strftime for the available options)
  49. \D{%c}: gives the date and time in the current locale
  50. \n: include a new line
  51. \w: the full path of the current working directory
  52. \H: the full hostname for the current machine
  53. \!: history number
  54. If you use longer prompts (say if you include \H or \w or a full date-time), you
  55. may want to break things over two lines. Here is an example of a multi-line
  56. prompt, with the date, time, and current working directory on one line, and
  57. username@hostname on the second line:
  58. PS1="\D{%c} \w\n[\u@\H]$ "
  59. To change the date-time above to display in red text, the directory in cyan, and
  60. your username on a yellow background, you could try this:
  61. PS1="\[\e[31m\]\D{%c}\[\e[0m\]\[\e[36m\]\w\[\e[0m\]\n[\[\e[1;43m\]\u\[\e[0m\]@\H]$ "
  62. \[..\] declares some non-printed characters
  63. \e[.. is an escape character
  64. 31m is red text (41m would be a red background)
  65. 36m is cyan text
  66. 1;43m declares a yellow background (1;33m would be yellow text)
  67. \[\e[Om\] at the end resets the colors to the terminal defaults
  68. You can find more colors and tips in the Bash prompt HOWTO:
  69. https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
  70. # command and argument
  71. cal 2020 # command: cal, argument: 2020
  72. * Passing an argument to the command alters its behavior.
  73. * Some commands may require obligatory arguments and will return an error
  74. message if they are missing. For example, the command to copy a file needs
  75. two arguments: what file to copy, and where to copy it.
  76. * All commands can be modified using options that are specific to each command.
  77. cal -j # use option -j to display Julian calendar
  78. leave 2005 # to remind yourself to leave at 08:05 pm
  79. mkdir Directory; cd Directory; touch 1.txt 2.txt 3.c
  80. echo *.txt
  81. 1.txt 2.txt
  82. echo *
  83. 1.txt 2.txt 3.c
  84. rm -rf Directory
  85. mkdir -p dir1/dir2/dir3 # will create directories and its parent directories
  86. rm -rf dir1 # recursively deletes the contents of dir1 and its sub-directories
  87. # verify electronic mail addresses
  88. vrfy user@example.edu # verify that the email address user@example.edu valid
  89. # type
  90. type -a pwd
  91. IBM Developer
  92. https://developer.ibm.com/technologies/
  93. Learn Linux, 101:A road-map for LPIC-1
  94. https://developer.ibm.com/tutorials/l-lpicl-map/
  95. http://www.research.ibm.com/haifa/ponderthis/challenges/October2019.html
  96. http://www.brendangregg.com/index.html # perf tutorials
  97. # boot time check in Linux
  98. systemd-analyze
  99. systemd-analyze blame
  100. sudo systemctl disable NetworkManager-wait-online.service
  101. sudo systemctl enable NetworkManager-wait-online.service
  102. A repository is a collection of files that has information about various
  103. software, their versions and some other details like the checksum. Each Ubuntu
  104. version has its own official set of four repositories:
  105. Main - Canonical-supported free and open-source software
  106. Universe - Community-maintained free and open-source software
  107. Restricted - Proprietary drivers for devices
  108. Multiverse - Software restricted by copyright or legal issues
  109. /bin - Binaries, programs used in booting the system.
  110. /usr/bin - User binaries, standard programs available to users.
  111. /usr/local/bin - Local binaries, programs specific to an installation.
  112. https://www.ubuntu.com/about/release-cycle
  113. https://www.kernel.org/doc/man-pages/
  114. https://clearlinux.org/documentation/clear-linux
  115. # free and df
  116. free -h # RAM memory
  117. df -h # Hard Drive memory
  118. # Generate a random password
  119. gpw () { openssl rand -base64 48 | cut -c1-${1}; }
  120. date +%s | sha256sum | base64 | head -c 32 ; echo
  121. < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
  122. openssl rand -base64 32
  123. tr -cd `[:alnum:]` < /dev/urandom | fold -w30 | head -n1
  124. < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
  125. date | md5sum
  126. gpg --gen-random --armor 1 14
  127. pwgen 14 1
  128. Ref: https://www.howtogeek.com/howto/30184/10-ways-to-generate-a-random-
  129. password-from-the-command-line/
  130. journalctl -b | grep 'DMI:'
  131. dell supports LVFS https://fwupd.org/lvfs/ for some, but not all devices.
  132. Note: If you use systemd, read the journalctl man page. It may seem heavy-going
  133. at first, but it makes searching the system logs so much more effective.
  134. sudo lsblk # list block devices
  135. swapon --summary # to find information about your swap space
  136. cat /proc/swaps
  137. set -o # to display all shell options
  138. set -o noclobber # - (dash) for enabling
  139. set +o noclobber # + (plus) for disabling
  140. apt-show-versions # to list installed packages
  141. aptitude search ~E # list essential packages
  142. ## id
  143. $ id username # print real and effective user and group IDs
  144. ## installed packages
  145. $ apt list --installed | less
  146. $ apt list --installed | grep -i apache
  147. $ dpkg -l
  148. $ dpkg -l | grep -i apache
  149. $ dpkg -S $(which <command>)
  150. /var/log/apt/
  151. sudo less -N history.log
  152. /var/lib/dpkg/available # available packages
  153. /etc/init.d # Configuration of System V init under Debian GNU/Linux
  154. /etc/systemd # Configuration of Systemd
  155. /etc/default # some default files
  156. In systemd, unit files get packaged into
  157. /usr/lib/systemd/system, but if you want
  158. to replace the default with your own, you
  159. can put them in /etc/systemd/system and
  160. whatever is there will take precedence
  161. over the defaults.
  162. To limit the amount of CPU a process gets by dropping in a new unit
  163. configuration file to /etc/systemd/system and adding:
  164. [Service]
  165. CpuShares=200
  166. # To login in text mode
  167. vi /etc/default/grub
  168. replace "quiet splash" -> "text"
  169. sudo update-grub
  170. # To start XMonad
  171. startx /usr/bin/xmonad-session
  172. # To start dwm
  173. startx /usr/local/bin/dwm
  174. # To start without cursor
  175. startx -- -nocursor
  176. # To start qutebrowser
  177. cd qutebrowser
  178. .venv/bin/python3 -m qutebrowser
  179. :set zoom.default 67%
  180. :config-source # to recompile
  181. ctrl+T # new tab
  182. shift+j # move to next tab
  183. shift+k # move to previous tab
  184. D # close the current tab
  185. # man pages
  186. apropos partition
  187. man ascii
  188. $ ascii # to display ascii characters
  189. man hier
  190. man systemd.unit
  191. man systemd.service
  192. # ctrl
  193. ctrl+A - begining of shell command
  194. ctrl+E - end of shell command
  195. ctrl+H - delete a letter
  196. ctrl+W - delete a word
  197. ctrl+U - erase line before cursor
  198. ctrl+K - erase line after cursor
  199. ctrl+Y - reverse of ctrl+W, ctrl+U and ctrl+K
  200. ctrl+B - move backward by letter
  201. ctrl+F - move forward by letter
  202. ctrl+P - scrolls through previous command
  203. ctrl+N - scrolls through next command
  204. ctrl+R - searches for commands you've already typed
  205. # alt
  206. alt+B - move backward by word
  207. alt+F - move forward by word
  208. alt+U - uppercase a word
  209. alt+L - lowercase a word
  210. alt+C - capitalizes letter where cursor is and moves to end of word
  211. # Special key strokes
  212. ctrl-U erase line before cursor
  213. ctrl-H erase a character before cursor
  214. ctrl-D terminate input (exit shell if you are using shell)
  215. ctrl-C terminate a running program
  216. ctrl-Z temporarily stop program by moving it to the background job
  217. ctrl-S halt output to screen
  218. ctrl-Q reactivate output to screen
  219. ctrl-Alt-Del reboot/halt the system, see inittab(5)
  220. Left-Alt-Key meta-key for Emacs and the similar UI
  221. Up-arrow start command history search under bash
  222. ctrl-R start incremental command history search under bash
  223. Tab complete input of the filename to the command line under bash
  224. ctrl-V Tab input Tab without expansion to the command line under bash
  225. # shutdown
  226. shutdown -h now
  227. shutdown -r now
  228. # Groups
  229. groups # to list the groups
  230. groups username # to list the groups to which the user belongs
  231. Note: Please bear in mind that the user ID of root is always 0 -every user
  232. with a user ID of 0 has root privileges!
  233. # sudo
  234. sudo -u username program # in sudoers you can permit the user to only sudo to
  235. that user and run that one program
  236. # Documents
  237. /usr/share/doc
  238. # whereis - to find the binary files
  239. whereis python3
  240. # alias
  241. alias
  242. alias ec='echo'
  243. unalias ec # to unalias the command
  244. note: enter it in .bashrc file (source ~/.bashrc)
  245. # information regarding the OS installed
  246. cat /etc/*release
  247. cat /etc/issue.net # to view Linux distribution
  248. lsb_release -a
  249. # Bash
  250. source ~/.bashrc # to compile changes in .bashrc file
  251. (to execute your .bashrc with source ~/.bashrc)
  252. ~/.bash_history # bash history file
  253. ~/.local/share/Trash #files in trash folder
  254. cp -r directory/ foo/ # copy recursively
  255. du -Sh # list all files size in directory
  256. du -sh # list only the file size of directory
  257. dpigs -H --lines=3000 | less -N
  258. ip addr list wlan0
  259. hostname -I # show ip address
  260. last - show a listing of last logged in users
  261. !! - alias to previous command
  262. # Adding/Deleting Users
  263. adduser username
  264. deluser username
  265. ## su command
  266. The su command is used to switch to a different user's account. You can use
  267. this command with the username of another user to log in with that user's
  268. session.
  269. $ su username
  270. To exit anytime from the other user's session just type exit and hit enter.
  271. # file
  272. file <filename> # displays the file type
  273. file -i <filename> # to get the mimetype
  274. # You can obtain detailed information on the hardware using ls commands such as
  275. lspci - list all PCI devices
  276. lsblk - list block devices
  277. lscpu - display information about the CPU architecture
  278. lsscsi - display SCSI devices information
  279. # hardware identification
  280. For the PCI-like devices (AGP, PCI-Express, CardBus, ExpressCard, etc.), lspci
  281. (probably with "-nn" option) is a good start for the hardware identification.
  282. Alternatively, you can identify the hardware by reading contents of
  283. "/proc/bus/pci/devices" or browsing directory tree under "/sys/bus/pci"
  284. pciutils - Linux PCI utilities: lspci
  285. usbutils - Linux USB utilities: lsusb
  286. pcmciautils - PCMCIA utilities for Linux: pccardctl
  287. scsitools - collection of tools for SCSI hardware management: lsscsi
  288. procinfo - system information obtained from "/proc": lsdev
  289. lshw - information about hardware configuration: lshw
  290. discover - hardware identification system: discover
  291. # system and hardware time
  292. The following sets system and hardware time to MM/DD hh:mm, CCYY.
  293. # date MMDDhhmmCCYY
  294. # hwclock --utc --systohc
  295. # hwclock --show
  296. If the hardware (BIOS) time is set to UTC, change the setting to "UTC=yes" in
  297. the "/etc/default/rcs".
  298. The following reconfigure the timezone used by the Debian system.
  299. # dpkg-reconfigure tzdata
  300. # NTP
  301. If you wish to update system time via network, consider to use the NTP service
  302. with the packages such as ntp, ntpdate, and chrony.
  303. Under systemd, use systemd-timesyncd for the network time synchronization
  304. instead.
  305. ntptrace in the ntp package can trace a chain of NTP servers back to the
  306. primary source
  307. ## keyboard
  308. sudo dpkg-reconfigure keyboard-configuration
  309. The keyboard type on the first screen will likely be correct ("Generic") then
  310. when you hit OK (Enter) the other screens will prompt you for language etc. Use
  311. arrow keys to scroll up and down between options and "Enter" for OK.
  312. # systemd is the most popular init process for bootstrapping user spaces and
  313. controlling multiple system process.
  314. sudo systemctl status
  315. # Dmesg allows you to figure out errors and warnings in the kernel's latest
  316. messages.
  317. dmesg | less
  318. # You can also look at all Linux system logs in the /var/log/messages file,
  319. which is where you'll find errors related to specific issues. It's worthwhile
  320. to monitor the messages via the tail command in real time when you make
  321. modifications to your hardware, such as mounting an extra disk or adding an
  322. Ethernet network interface.
  323. tail -f /var/log/messages
  324. # Commands to figure out networking functions in the Linux server include
  325. ip addr, traceroute, nslookup, dig, and ping, among others.
  326. sudo ip addr show
  327. To mount cd to /home/user/lan :
  328. sudo mount /dev/cdrom /home/user/lan
  329. # chmod
  330. chmod u=rwx,g=rwx,o=rwx <filename>
  331. chmod 777 <filename>
  332. 4=read, 2=write, 1=execute, 0=no permission
  333. 7=4+2+1 5=4+0+1 4=4+0+0
  334. chmod 600 <filename> # make an existing file "<filename>" to be non-readable
  335. and non-writable by the other people
  336. (non-executable for all)
  337. chmod 644 <filename> # make an existing file "<filename>" to be readable but
  338. non-writable by the other people
  339. (non-executable for all)
  340. chmod 755 <filename> # make an existing file "<filename>" to be readable but
  341. non-writable by the other people (executable for all)
  342. u user + to add a permission r read
  343. g group - to remove a permission w write
  344. o other = to assign a permission explicitly x execute (for files),
  345. chmod u=rw file
  346. sets the permissions on the file to give the user read and write permission on
  347. file. No other permissions are altered.
  348. chmod u+x,g+w,o-r file
  349. alters the permissions on the file to give the user execute permission, to
  350. give members of the users group write permission, and prevent any users not
  351. in the group from reading it.
  352. chmod u+w, go-x dir
  353. gives the user write permission in the dir, and prevents all other users
  354. having access to that directory (by using cd. They can still list its
  355. contents using ls.)
  356. chmod a+w file # to add write access for everybody
  357. chmod a-w file # to remove write access
  358. chmod a=r file # set permissions on the file to allow
  359. only read access for all users
  360. chmod u+w, go+r-w file # adds write access for the file owner and removes
  361. write access and adds read access for the group
  362. and other classes
  363. chmod -R go-rwx /home/user # if user wants to protect all the files under
  364. his home directory from everyone else
  365. [recursive option (-R)]
  366. chmod -R +r . # grants read access to all users for the current
  367. directory and every file under it
  368. chmod go= file # prevents any access to the file by anyone other
  369. than its owner
  370. chmod go+rX * # the X access type grants execute access to the
  371. specified access classes only when execute access
  372. is already set for some access class. A typical
  373. use for this access type is to grant group or
  374. other read and execute access to all the
  375. directories and executable files within a
  376. subtree while granting only read access to all
  377. other types of files (example: datafile.txt)
  378. chmod o=g * # makes the other access the same as the current
  379. group access for each file/directory
  380. # umask
  381. 027 is better from security perspective, even better is to use 077 for root.
  382. With 027 mask, when root creates a file, it can be read and executed by users
  383. who belongs to the group of the file. With 077 mask, only root can read write
  384. and execute files.
  385. Why is 077 better?
  386. because by making files belonging to user readable by root only, it avoids some
  387. common system administrator mistakes. because it's harder for an attacker to
  388. run privilege escalation only poorly written shell scripts/binaries if they
  389. can't even read it.
  390. # chown
  391. chown user file/Directory # Change the owner of fiel/Directory to "user"
  392. chown user:staff file/Directory # Likewise but also change its group to "staff"
  393. chown -hR user file/Directory # Change the owner of file/Dire and subfiles
  394. Note: refer man chown (Examples section)
  395. # chgrp
  396. chgrp user file/Directory # Change the group of file/Directory to "user"
  397. chgrp -hR user file/Directory # Change the group of file/Dire and subfiles
  398. Note: refer man chgrp (Examples section)
  399. # irssi - https://freenode.net/kb/answer/registration
  400. https://irssi.org/documentation/startup/
  401. https://wiki.debian.org/IRC
  402. https://fedoraproject.org/wiki/How_to_use_IRC#Meeting_Protocol
  403. Help regarding registration - /msg NickServ help register
  404. Register your IRC nick - /msg NickServ REGISTER password youremail@example.com
  405. Logging in - /connect chat.freenode.net 6667/6697 account_name:password
  406. /help # show all commands
  407. /help command # shows command usage
  408. /network list # list network
  409. /connect Freenode # connect network Freenode
  410. /join #debian # join channel debian
  411. /part # leave channel
  412. /nick name # changes the name
  413. /whois name # shows basic whois info for a name
  414. /msg NickServ info name # more info of /whois name
  415. /away message # leaves a message when you are away frm channel
  416. /back # use /back when you return
  417. /quit message # leaves a message when you quit IRC channel
  418. long pastes: wgetpaste or dpaste.com
  419. For posting multi-line texts into the channel - https://paste.ubuntu.com
  420. To post screenshots use https://imgur.com/
  421. !pastebinit to paste directly from command line
  422. Make sure you give us the URL for your paste
  423. # wireless connection - wlx00873239946f
  424. sudo ifconfig wlan0 up/down # bring wireless network up/down
  425. iw dev # gives wifi adapter device name
  426. iw wlan0 link # Connected/Not Connected
  427. (wlan0 - device name from previous command)
  428. sudo iw wlan0 scan / sudo iwlist wlan0 scan
  429. nmcli dev
  430. nmcli dev wifi
  431. sudo nmcli dev wifi connect name password *****
  432. (replace name with network name)
  433. nmcli con show = nmcli -p connection
  434. (list all ethernet and wireless connections)
  435. # nmcli
  436. nmcli connection show # list all network connections
  437. nmcli device show # list device information including hardware address
  438. nmcli general status # show overall status of Network Manager
  439. nmcli general hostname # get and change system hostname
  440. nmcli general permissions # show the permissions
  441. nmcli general logging # get and change Network Manager logging level
  442. and domains
  443. nmcli networking on/off # enable or disable networking control by
  444. Network Manager
  445. nmcli networking connectivity # get network connectivity state
  446. none = the host is not connected to any network
  447. portal = the host is behind a captive portal and cannot reach the full Internet
  448. limited = the host is connected to a network, but it has no access to Internet
  449. full = the host is connected to a network and has full access to the Internet
  450. unknown = the connectivity status cannot be found out
  451. nmcli radio all/wifi/wwan
  452. nmcli radio wifi on/off
  453. nmcli radio wwan on/off
  454. nmcli radio all on/off
  455. nmcli monitor # observe Network Manager activity
  456. nmcli connection show/up/down/add/edit/modify/delete/monitor/reload/load
  457. nmcli dev status/show/set/connect/reapply/disconnect/delete/monitor/wifi/lldp
  458. nmcli -p -f general,wifi-properties device show wlx00873239946f # dev details
  459. man 7 nmcli-examples -- usage examples of nmcli
  460. # mount/unmount usb
  461. fdisk -l (sudo) #to find name
  462. df -h
  463. /dev/sdb1
  464. sudo mount /dev/sdb1 /media/user
  465. sudo umount /dev/sdb1 /media/user
  466. # undo cannot format on usb storage
  467. - type sudo fdisk -l and not usb drive letter (/dev/sdb1)
  468. - make sure the device is unmount
  469. - type sudo fdisk /dev/sdb
  470. - type d to proceed to delete a partition
  471. - type 1 to select the 1st partition and press enter
  472. - typd d to proceed to delete another partition
  473. (fdisk should automatically select the second partition)
  474. - type n to make a new partition
  475. - type p to make this partition primary and press enter
  476. - type 1 to make this the first partition and then press enter
  477. - press enter to accept the default first cylinder
  478. - press enter again to accept the default last cylinder
  479. - type w to write the new partition information to the USB key
  480. - type umount /dev/sdb1 (check)
  481. - type sudo mkfs.vfat -F 32 /dev/sdb1
  482. # for mkfs.vfat
  483. sudo apt-get install dosfstools
  484. /sbin/mkfs.vfat
  485. # Basic Network Commands
  486. ping www.slackware.com
  487. traceroute www.slackware.com
  488. host www.slackware.com #map name to ip address
  489. nslookup 64.57.102.34
  490. dig @192.168.1.254 www.slackware.com mx
  491. # text editor
  492. sudo update-alternatives --config editor
  493. # X terminal emulator
  494. sudo update-alternatives --config x-terminal-emulator
  495. # Recording the shell activities (record when you perform any sys admin tasks)
  496. $script #Script started, file is typescript
  497. Do whatever shell commands under script
  498. Press Ctrl-D to exit Script
  499. sudo apt purge `dpkg --get-selections | grep deinstall | cut -f1`
  500. aptitude search '?essential'
  501. # To list all essential packages in debian
  502. dpkg-query -Wf '${Package; -40}${Essential}\n' | grep yes
  503. # send message to everyone who is logged on to the system with wall
  504. echo "We are shutting down in 1 hour" | wall
  505. # viewing binary data
  506. od -t x1 <name>
  507. # To convert *.mkv to *.mp4
  508. ffmpeg -i input.mkv -codec copy output.mp4
  509. # pdftk (read man page of pdftk)
  510. pdftk in.pdf output out.pdf uncompress
  511. LESSOPEN="" less out.pdf
  512. merge multiple pdf files into a single document:
  513. pdftk file1.pdf file2.pdf cat output merged.pdf
  514. combine even and odd pages into one document:
  515. pdftk A=even.pdf B=odd.pdf shuffle A B output combined.pdf
  516. split a pdf file into multiple documents:
  517. pdftk input.pdf cat 1 output page1.pdf
  518. pdftk input.pdf cat 2-end output pages2-end.pdf
  519. rotate the pages of a pdf file:
  520. pdftk input.pdf cat 1east 2east 3-endwest output outfile.pdf
  521. This rotates the first and second pages of 'input.pdf' 90 degrees clockwise and
  522. the remaining pages 90 degrees counterclockwise.
  523. rotate all pages by 180 degrees:
  524. pdftk input.pdf cat 1-endS output outfile.pdf
  525. fill out a pdf form:
  526. pdftk form.pdf fill_form data.fdf output filled.pdf
  527. This fills out the form fields in 'form.pdf' using the data in the 'data.fdf'
  528. file and saves the result in 'filled.pdf'.
  529. # qpdf
  530. to combine two pdf files to form a new pdf file:
  531. qpdf --empty --pages file1.pdf file2.pdf -- combined.pdf
  532. using wildcards instead of listing many source files:
  533. qpdf --empty --pages *.pdf -- allcombined.pdf
  534. to extract pages 1 and 2 from file1.pdf and page 1 from file2.pdf:
  535. qpdf --empty --pages file1.pdf 1-2 file2.pdf 1 -- combined.pdf
  536. to extract pages from a large pdf file:
  537. qpdf --empty --pages largefile.pdf 1-3,7,11,18-21,55 -- summary.pdf
  538. The output file, 'summary.pdf' contains pages 1 to 3, 7, 11, 18 to 21, and 55
  539. from the input file 'largefile.pdf'.
  540. to split a pdf file into separate pdf files each holding a single page:
  541. qpdf summary.pdf page.pdf --split-pages
  542. The file we're splitting is 'summary.pdf', and the output file is given as
  543. 'page.pdf'. This is used as the base name. Each new file has a number added to
  544. the base name. The --split-pages option tells qpdf what type of action we're
  545. performing.
  546. use page ranges to select the pages you want to split:
  547. qpdf large.pdf section.pdf --pages large.pdf 1-5,11-14,60,70-100 -- --split-pages
  548. The page ranges are used to specify the pages/ranges we want, but each page is
  549. still stored in a single pdf file.
  550. to extract a page range and stored in a single pdf:
  551. qpdf --empty --pages large.pdf 8-13 -- chapter2.pdf
  552. to rotate a page, we use the --rotate option:
  553. qpdf --rotate=+90:1 summary.pdf rotated1.pdf
  554. The +90 means rotate the page 90 degrees clockwise. You can rotate a page 90,
  555. 180, or 270 degrees. You can also specify the rotation in degrees anticlockwise,
  556. by using a negative number, but there's little need to do so. A rotation of -90
  557. is the same as a rotation +270. The number separated from the rotation by a
  558. colon ':' is the number of the page you want to rotate. This could be a list of
  559. page numbers and page ranges, but we're just rotating the first page. To rotate
  560. all pages use a page range of 1-z.
  561. to create an encrypted version of the 'summary.pdf' called 'secret.pdf':
  562. qpdf --encrypt <user password> <owner password> 256 -- summary.pdf secret.pdf
  563. To encrypt a pdf we need to use the --encrypt option and provide both the user
  564. password and the owner password. We also specify the strength of encryption to
  565. use. You'd only need to drop from 256-bit encryption to 128-bit if you want to
  566. support very old pdf file viewers. We suggest to stick with 256-bit encryption.
  567. to decrypt a file:
  568. qpdf --decrypt --password=<owner password> secret.pdf unlocked.pdf
  569. To decrypt a file, use the --decrypt option. Obviously, you must know the owner
  570. password for this to work. We need to use the --password option to identify the
  571. password.
  572. Reference: https://qpdf.readthedocs.io/en/stable/index.html
  573. # scribus
  574. # cowsay
  575. cowsay -l
  576. cowsay -f tux Linux is awesome
  577. # ls
  578. List only the .txt files in the directory: ls *.txt
  579. List by file size: ls -a
  580. Sort by time and date: ls -d
  581. Sort by extension: ls -x
  582. Sort by file size: ls -S
  583. Long format with file size: ls -ls
  584. send it to a file for later viewing: ls -al > mydirectorylist
  585. # mkdir
  586. mkdir sa{1..50} # 50 directories from sa1 to sa50
  587. # tar files/directories to backup
  588. 1. Compress an Entire Directory or a Single file
  589. tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
  590. -c: Create an archive, -z: Compress the archive with gzip,
  591. -v: Display progress in the terminal while creating the archive
  592. -f: Allows you to specify the filename of the archive
  593. 2. Compress Multiple Directories or Files at once
  594. tar -czvf archive.tar.gz /home/ubuntu/Downloads /usr/local/stuff
  595. /home/ubuntu/Documents/notes.txt
  596. 3. Exclude Directories and Files
  597. tar -czvf archive.tar.gz /home/ubuntu --exclude=/home/ubuntu/Downloads
  598. --exclude=/home/ubuntu/.cache
  599. tar -czvf archive.tar.gz /home/ubuntu --exclude=*.mp4
  600. 4. Use bzip2 Compression Instead
  601. tar -cjvf archive.tar.bz2 stuff
  602. 5. Extract an Archive
  603. tar -xzvf archive.tar.gz
  604. 6. Extract the contents of the archive to a specific directory
  605. tar -xzvf archive.tar.gz -C /tmp
  606. # untar/tar
  607. tar -tf *.tar.gz # to view contents without extracting
  608. tar -tvf *.tar.gz # list more information
  609. tar -xvzf filename.tar.gz # to decompress a tarball
  610. # zip
  611. unzip -l filename.zip # to view contents without unzip
  612. unzip filename.zip # to unzip
  613. # scp
  614. scp ph15m015@172.29.204.101:/home2/mtech/ph15m015/cl.tar.gz .
  615. # hostname
  616. hostname # list machine name
  617. hostname -i # list 127.0.1.1
  618. hostname -I # list ip address of network
  619. # youtube-dl [http://ytdl-org.github.io/youtube-dl/download.html]
  620. To install it right away for all UNIX users type:
  621. $ sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
  622. $ sudo chmod a+rx /usr/local/bin/youtube-dl
  623. If you do not have curl, you can alternatively use wget:
  624. $ sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
  625. $ sudo chmod a+rx /usr/local/bin/youtube-dl
  626. :yank # type :yank in qutebrowser to copy the url
  627. xclip -o -selection clipboard > url.txt # write the url in url.txt
  628. youtube-dl --extract-audio/-x --audio-format mp3 "$(< url.txt)" # mp3 format
  629. youtube-dl -F "$(< url.txt)" # to find best video format
  630. youtube-dl -F --no-playlist "$(< url.txt)" # list available formats of one file
  631. youtube-dl -f no. "$(< url.txt)" # to download the file
  632. youtube-dl -f 22 --no-playlist -f 22 --no-playlist "$(< url.txt)"
  633. # update youtube-dl
  634. sudo youtube-dl --update
  635. # version
  636. youtube-dl --version
  637. # SSH
  638. If you're using a cloud server, you will probably want to allow incoming SSH
  639. connections (port 22) so you can connect to and manage your server. This
  640. section covers how to configure your firewall with various SSH-related rules.
  641. Allow SSH
  642. To allow all incoming SSH connections run this command:
  643. $ sudo ufw allow/deny ssh
  644. An alternative syntax is to specify the port number of the SSH service:
  645. $ sudo ufw allow 22
  646. Allow incoming SSH from specific IP Address or Subnet
  647. To allow incoming SSH connections from a specific IP address or subnet,
  648. specify the source. For example, if you want to allow the entire 15.15.15.0/24
  649. subnet, run this command:
  650. $ sudo ufw allow from 15.15.15.0/24 to any port 22
  651. Allow incoming Rsync from specific IP Address or Subnet Rsync, which runs on
  652. port 873, can used to transfer files from one computer to another.
  653. To allow incoming rsync connections from a specific IP address or subnet,
  654. specify the source IP address and the destination port. For example, if you
  655. want to allow the entire 15.15.15.0/24 subnet to be able to rsync to your
  656. server, run this command:
  657. $ sudo ufw allow from 15.15.15.0/24 to any port 873
  658. Source: https://www.digitalocean.com/community/tutorials/ufw-essentials-common
  659. -firewall-rules-and-commands
  660. https://thepcspy.com/read/making-ssh.secure/
  661. # hardware info
  662. hwinfo --help
  663. hwinfo --netcard
  664. hwinfo --gfxcard
  665. # dpkg commands
  666. # to install a downloaded debian package (.deb)
  667. sudo dpkg -i packagename.deb
  668. # to unpack the package (.deb) without installing it
  669. sudo dpkg --unpack packagename.deb
  670. # to remove a debian package (.deb)
  671. sudo dpkg -r packagename
  672. # to purge a debian package (.deb)
  673. sudo dpkg -P packagename
  674. # to reconfigure/repair an installed debian package
  675. sudo dpkg-reconfigure packagename
  676. # find out what package the file /etc/logrotate.conf belongs
  677. dpkg -S /etc/logrotate.conf
  678. # list information about the pkg including all the files it contains
  679. dpkg -L packagename
  680. # verify the package installation
  681. dpkg -V packagename
  682. # information about .deb package
  683. dpkg --info *.deb
  684. # report status of specified package
  685. dpkg --status packagename
  686. # list all currently installed packages (including those from the repositories)
  687. dpkg -l
  688. # if you need simpler output
  689. dpkg --get-selections
  690. # display details of the specified package
  691. dpkg -s zip
  692. # clamAV
  693. sudo apt install clamav
  694. sudo freshclam # to update the signatures
  695. clamscan --help
  696. clamscan -r --bell -i /home/username/Downloads
  697. # lynis
  698. sudo lynis audit system
  699. sudo lynis audit system --quick
  700. sudo lynis show commands
  701. sudo lynis show help
  702. sudo lynis show profiles
  703. sudo lynis show settings
  704. sudo lynis show version
  705. Reference:
  706. https://cisofy.com/documentation/lynis/get-started/#first-run
  707. https://linuxsecurity.expert/checklists/linux-security-and-system-hardening
  708. https://linuxsecurity.expert/checklists/linux-security-best-practices
  709. Installation:
  710. git clone https://github.com/CISOfy/lynis
  711. Execute:
  712. cd lynis
  713. ./lynis audit system
  714. To run as root, change ownership of the related files (or full directory)
  715. chown -R 0:0 lynis
  716. Test and debug information: /var/log/lynis.log
  717. Report data : /var/log/lynis-report.dat
  718. # ps_mem
  719. sudo pip install --upgrade pip # to upgrade pip to latest version
  720. sudo pip install ps_mem
  721. sudo ps_mem | less # to run ps_mem
  722. # Private Browsing using Tor and I2P
  723. Tor, I2P, etc, are open, distributed networks that bounce your internet
  724. communications around a network of relays run by volunteers all around the
  725. world. This way, anybody watching your internet connection can't figure out the
  726. sites you visit, and the sites you visit can't track your physical location.
  727. Though both of them are supposed to protect your identity online using
  728. cryptographic methods, there are several differences in their respective
  729. approaches to this question of privacy. Tor takes the directory-based approach,
  730. providing a centralised point to manage the overall view of the network, as
  731. well as gather and report statistics, while I2P uses a distributed network
  732. database and peer selection. Tor provides better anonymous access to the open
  733. internet while I2P provides a more tobust and reliable network within the
  734. network layout. Tor also has a larger user base, with more volunteers around
  735. the world.
  736. Also, beware that your ISP can see that you're using Tor or I2P (though they
  737. cannot determine the content of the traffic). To hide this information from
  738. your ISP, you can use a high-quality VPN service to act as an entry point to
  739. your anonymous network. An excellent open source project for this is OpenVPN:
  740. https://openvpn.net
  741. # Tlp
  742. sudo tlp-stat | less # system info
  743. # Service - /etc/init.d
  744. service --status-all # to list status of all services
  745. service sshd status # gives the status of sshd
  746. service sshd stop # to stop the sshd service
  747. service sshd start # to start the sshd service
  748. service sshd restart # to restart the sshd service
  749. # wget
  750. If you ever need to download an entire website, perhaps for off-line viewing,
  751. wget can do the job for you:
  752. $ wget \
  753. --recursive \ # download the entire website
  754. --no-clobber \ # don't overwrite any existing files
  755. --page-requisites \ # get all the elements that compose the page (images, css)
  756. --html-extension \ # save files with the .html extension
  757. --convert-links \ # convert links so that they work locally, off-line
  758. --restrict-file-names=windows \ # modify filename (to work in windows as well)
  759. --domains website.org \ # don't follow links outside website.org
  760. --no-parent \ # don't follow links outside the directory tutorials/html/
  761. www.website.org/tutorials/html/
  762. wget resume download
  763. wget -c url
  764. wget --continue url
  765. wget --continue [options] url
  766. man wget
  767. wget --help
  768. wget address
  769. wget --http-user=USER --http-password=PASSWORD address
  770. # download an entire website
  771. $ wget --random-wait -t -p -e robots=off -U mozilla https://www.website.com
  772. # curl
  773. curl web-address > file-source
  774. example: curl https://address.html > address.html
  775. curl ipinfo.io/ip_addr
  776. curl https://api.ipdata.co/ip_addr?api-key=test
  777. curl https://ipapi.co/ip_addr/json
  778. # trickle
  779. trickle -d 1024 wget -c
  780. https://archive.org/download/CharlieChaplin/Chaplin_512kb.mp4
  781. will download the Charlie Chaplin movie (available as public domain from the
  782. Internet Archive) with the Wget downloader limiting the download speed to
  783. 1024 Kbps.
  784. You can use Wget's --limit-rate option to regulate its download speed.
  785. In the same vein, use the -u switch to regulate the upload speed.
  786. If setting per-application speeds seems too much of a chore, you can set global
  787. speed caps with the trickled command, such as
  788. trickled -d 2048 -u 1024
  789. trickle apt upgrade
  790. will now update the Ubuntu installation while respecting the limits set by the trickled.
  791. # httrack
  792. # tasksel - a user interface for installing tasks
  793. tasksel --list-tasks
  794. tasksel --task-packages dns-server # to list the packages installed
  795. with the DNS server
  796. # Terminal:
  797. sudo update-alternatives --list x-terminal-emulator
  798. sudo update-alternatives --install /usr/bin/x-terminal-emulator
  799. x-terminal-emulator /usr/bin/stterm 100
  800. sudo update-alternatives --list x-terminal-emulator
  801. sudo update-alternatives --config x-terminal-emulator
  802. # Hardware Info
  803. sudo lshw | less
  804. sudo lshw -C network
  805. # APT commands reference
  806. apt-cache pkgnames
  807. apt-cache search <package-name>
  808. apt-cache --names-only search chm
  809. apt-cache show <package-name>
  810. apt-cache showpkg <package-name> # show dependencies
  811. apt-cache depends <package-name>
  812. apt-cache rdepends <package-name>
  813. apt-cache depends --installed <package-name>
  814. apt-cache rdepends --installed <package-name>
  815. apt-cache stats
  816. doas apt-get update / doas apt update
  817. doas apt-get upgrade / doas apt upgrade / doas apt-get dist-upgrade
  818. doas apt-get install <package-name> / doas apt install <package-name>
  819. doas apt-get install <package-name1> <package-name2>
  820. doas apt list # to list all available packages
  821. doas apt list | grep <package-name>
  822. doas apt list --installed # to list only the installed packages
  823. doas apt list --upgradable # to list of the upgradable packages before upgrading
  824. apt search <package-name> # to search for a given package in the list of packages
  825. apt show <package-name> # to retrieve information about a given package
  826. doas apt autoremove # to remove the unneeded dependencies
  827. doas apt remove <package-name> # to remove an installed package
  828. doas apt purge <package-name> # to remove an installed package including config files
  829. doas apt update # to update the package index (pull latest changes from APT repo)
  830. doas apt upgrade # to upgrade the installed packages to their latest versions
  831. doas apt upgrade <package-name> # to upgrade <package-name>
  832. doas apt full-upgrade # will remove the installed packages if needed to upgrade
  833. doas apt install <package-name> # install <package-name>
  834. doas apt install <package-name1> <package-name2>
  835. doas apt install /path/to/file.deb # to install local deb.file
  836. Note:
  837. * apt combines the most frequently used commands from the apt-get and apt-cache
  838. tools with different default values of some options
  839. * apt is designed for interactive use
  840. * prefer using apt-get and apt-cache in shell scripts as they are backward compatible
  841. between the different versions and have more options and features
  842. * always update the package index before upgrading or installing new packages
  843. * upgrade command doesn't upgrade packages that require removal of installed packages
  844. * the difference between upgrade and full-upgrade is that the later will remove
  845. the installed packages if that is needed to upgrade the whole system
  846. # apt-get update/upgrade list without changing anything
  847. apt list --upgradable
  848. apt-get --simulate upgrade
  849. apt-get -s upgrade # --simulate, --just-print, --dry-run, --recon, --no-act
  850. doas apt-get -u upgrade --assume-no
  851. doas apt-get -u -V upgrade # to list packages to be upgraded with their versions
  852. doas apt-get --only-upgrade install <package-name>
  853. # apt-show-versions
  854. apt-show-versions # to know for all your installed packages whether they are
  855. uptodate or upgradeable
  856. apt-show-versions -u # if you want to have a list of all upgradeable packages
  857. apt-show-versions -a -p libc6 # to get list of all available versions of libc6
  858. apt-show-versions dpkg apt # to get information about several packages
  859. apt-show-versions -r ^texlive
  860. apt-get install `apt-show-versions -u -b | grep testing` # to upgrade all packages in
  861. testing
  862. -u, --upgradeable # Print only upgradeable packages
  863. -a, --allversions # Print all available versions of the selected packages
  864. -b, --brief # Print only package_name/distribution for upgradeable packages
  865. -v, --verbose # Prints out messages about which package files are parsed
  866. -V, --version # Prints out version of apt-show-versions
  867. -h, --help # Prints out command-line help
  868. # To decrypt file
  869. qpdf -password=password -decrypt /home/username/Documents/Secured.pdf
  870. /home/username/Documents/unsecured.pdf
  871. # xrandr
  872. xrandr --listmonitors # this command gives the <output name>
  873. for the command below
  874. xrandr --output <output name> --brightness "<x>"
  875. ## <x> is a number between 1 (full brightness) and 0 (backlight off)
  876. # rclone - a command line program to sync files and directories
  877. # List directories in top level of your pCloud
  878. rclone lsd remote:
  879. # List all the files in your pCloud
  880. rclone ls remote:
  881. # To copy a local directory to remote:backup
  882. rclone copy /home/source remote:backup
  883. # To sync a local directory to a remote
  884. rclone sync /home/source remote:directory_name
  885. rclone sync -P /home/source remote:directory_name # -P progress
  886. rclone sync -P Books/Chess/chess-wikibooks.pdf pcloud:Books/Chess/
  887. rclone sync /home/source remote:directory_name --dry-run
  888. rclone move /home/source remote:directory_name
  889. rclone delete remote:path
  890. # checks the files in the source and dest match
  891. rclone check source:path dest:path
  892. rclone check /home/saran/Books pcloud:Books/
  893. # To create a directory in remote
  894. rclone mkdir remote:directory_name
  895. # prints the total size and number of objects in remote:path
  896. rclone size remote:path
  897. # interactively find duplicate files and delete/rename them
  898. rclone dedupe remote:path
  899. rclone version
  900. rclone version --check
  901. # get quota information from the remote
  902. rclone about remote:
  903. rclone config file
  904. rclone config show
  905. rclone config providers
  906. # list all the remotes in the config file
  907. rclone listremotes
  908. # Mount the remote as file system
  909. rclone mount remote:path/to/files /path/to/local/mount
  910. # Explore a remote with a text based user interface
  911. rclone ncdu remote:
  912. # create new file or change file modification time
  913. rclone touch remote:path
  914. # list the contents of the remote in a tree like fashion
  915. rclone tree remote:path
  916. rclone move remote:GRE remote:Books/GRE/
  917. # IP
  918. sudo ip addr show # to check an IP address
  919. sudo ip addr del 192.168.50.5/24 dev eth1 # to remove an IP address
  920. sudo ip link set eth1 up # to enable network interface
  921. sudo ip link set eth1 down # to disable network interface
  922. sudo ip route show # to check route table
  923. *** https://www.tecmint.com/red-hat-rhcsa-rhce-exam-certification-book/
  924. # systemctl
  925. systemctl status ufw # to check the status of ufw
  926. # journald
  927. sudo journalctl -b # log messages right from the system boot
  928. # fdisk http://www.slackware.com/install/partitions.php
  929. When you start fdisk you need to specify the device to use. By default it will
  930. try to open /dev/hda, but in some cases this is not the correct device to use.
  931. Just specify the device name after typing fdisk on the command line.
  932. For example:
  933. fdisk /dev/hdb
  934. This will tell fdisk to open the primary slave IDE hard disk. Notice that you
  935. do not specify a partition number on the device name.
  936. An alternative to fdisk is cfdisk, which provides a menu-based setup program
  937. for the partition setup (DOS users comfortable with DOS's fdisk may find this
  938. program easier).
  939. Just run cfdisk at the prompt instead of fdisk.
  940. Here are some key commands you should be familiar with when using fdisk.
  941. p Display the current partition table
  942. m Display the help screen
  943. d Delete a partition
  944. n Add a new partition
  945. t Change the partition's system ID
  946. q Quit fdisk without saving changes
  947. w Write changes to device and quit fdisk
  948. # w3m
  949. sudo apt install w3m w3m-img # installing w3m
  950. w3m duckduckgo.com # basic browsing
  951. shift-B # take you back a page
  952. shift-T # browser tabs
  953. shift-[ and shift-] # to switch between tabs
  954. Esc + A # to bookmark the page
  955. w3m -M <url> # Display web content in monochrome terminal
  956. w3m -o auto_image=TRUE # Display embedded graphics
  957. # Display content from Usenet
  958. w3m -m nntp://news.aioe.org/comp.os.linux.networking
  959. # Upload data for a URL using the POST method
  960. w3m -post - http://example.com/form.php <<<'a=0&b=1'
  961. ~/.w3m/bookmark.html # default bookmark file
  962. ~/.w3m/config # user defined configuration file; orverrides /etc/w3m/config
  963. ~/.w3m/cookie # cookie jar; written on exit, read on launch
  964. ~/.w3m/history # browser history -visited files and URLs
  965. ~/.w3m/keymap # user defined key bindings; overrides default key bindings
  966. ~/.w3m/mailcap # external viewer configuration file
  967. ~/.w3m/menu # user defined menul overrides default menu
  968. ~/.w3m/mime.types # MIME types file
  969. ~/.w3m/mouse # user defined mouse settings
  970. ~/.w3m/passwd # password and username file
  971. ~/.w3m/pre_form # contains predefined values to fill recurrent HTML forms
  972. http://w3m.sourceforge.net
  973. Translate html to text
  974. cat index.html | w3m -dump -T text/html > index.txt
  975. Useful command line options
  976. -s squeeze multiple blank lines
  977. -cookie
  978. -no-proxy
  979. -post FILE
  980. Moving around
  981. H show runtime options
  982. K,J scroll one line
  983. .,, shift screen by one column
  984. z center current line
  985. [,] go to first/last link
  986. TAB move to next link
  987. C-u,ESC-TAB move to previous link
  988. C-m popup link list menu and move cursor to selected link
  989. C-l popul link list menu and go to selected link
  990. (,) cancel/redo last cursor movement
  991. Hyperlinks
  992. C-t open link in new tab
  993. a save link
  994. c peek current URL
  995. u peek link URL
  996. I view image
  997. ; mark current word as anchor (link navigation will apply)
  998. = view info of current document
  999. F render frame
  1000. L show all links and images
  1001. Buffers
  1002. B back
  1003. v view HTML source
  1004. s popup buffer selection menu
  1005. S save buffer to file
  1006. E edit current document (local file)
  1007. R reload
  1008. + information about current page
  1009. Tabs
  1010. T open new tab
  1011. C-q close current tab
  1012. {,} move to next/previous tab
  1013. ESC-t popup tab selection menu
  1014. Bookmarks
  1015. ESC-b view bookmark
  1016. ESC-a add current page to bookmark
  1017. Search
  1018. /,? search forward/backward
  1019. C-s,C-r incremental search forward/backward
  1020. Marks
  1021. C-@ set/unset mark
  1022. ESC-n,ESC-p move to next/preious mark
  1023. Misc
  1024. o option setting panel
  1025. C-k view cookie list
  1026. C-h view history
  1027. ! execute shell command
  1028. C-z stop loading document
  1029. Q quit without confirmation
  1030. # system information viewers
  1031. dmidecode - it reports information about your system's hardware as described
  1032. in your system BIOS according to the SMBIOS/DMI standard.
  1033. hwinfo - powerful hardware detection tool come from openSUSE
  1034. inxi - a script to get system information
  1035. nmon - console based application for monitoring various system components
  1036. # Apache
  1037. To look into the number of Apache processes your Linux system runs:
  1038. ps ax | grep apache | grep -v grep | wc -l
  1039. The relevant information is kept inside the Apache configuration file:
  1040. /etc/apache2/apache2.conf
  1041. # Server query
  1042. host www.slackware.com
  1043. dig www.slackware.com
  1044. nslookup www.slackware.com
  1045. # Manage processes
  1046. When an executable program starts up, it runs a process and this process will
  1047. be under the management of your Linux system's process table.
  1048. The ps and top commands are very powerful for viewing information about the
  1049. running processes. Then there are commands such as nice and renice and they
  1050. can be used for raising and lowering the process's priority. You can also move
  1051. the processes to run in the background, or back to run in the foreground again.
  1052. A command -chrt- can be used to run processes in real-time. You can use the
  1053. kill and killall commands to send signals to processes by PID or by name.
  1054. The ps command gives a snapshot of currently running processes whereas the
  1055. top command offers a screen-oriented, constantly updated listing of the
  1056. running commands.
  1057. ps # displays the list of processes of the current user at the current shell
  1058. ps -u username # specific user's running process
  1059. ps -u username u # displays all the running processes with CPU and memory info
  1060. ps -e # displays every running process
  1061. ps -el # long list of every running process
  1062. ps -ef # displays a full format list of all running processes
  1063. ps -eF # extra full format list of all running processes
  1064. Some processes start up other processes. The hierarchy of processes can be
  1065. viewed by using several options witht the ps command.
  1066. # shows the process hierarchy with information on process and session IDs.
  1067. ps -ejH
  1068. # default delay to update is 3 seconds; this command changes it to 5 seconds
  1069. top -d 5
  1070. # view only the processes related to the specific user
  1071. top -u username
  1072. # this will refresh the screen ten times before quitting
  1073. top -n 10
  1074. # run in batch mode
  1075. top -b
  1076. # exiftool [apt install libimage-exiftool-perl]
  1077. # to view the metadata for a PDF file
  1078. exiftool filename.pdf
  1079. # to get a specific piece of metadata, such as the author
  1080. exiftool -Author filename.pdf
  1081. # to change the metadata for a field
  1082. exiftool -Author="Issac Newton" filename.pdf
  1083. # to clear the metadata for a field, just overwrite it with empty data
  1084. exiftool -Subject= filename.pdf
  1085. # to clear the metadata for all fields in the PDF file
  1086. exiftool -all= filename.pdf
  1087. # to scrub all the personalizing metadata from the image
  1088. exiftool "-all=" filename.jpg
  1089. # to read the entire history of an image
  1090. exiftool filename.jpg
  1091. # to read the entire history of an mp3 file
  1092. exiftool filename.mp3
  1093. # ffmpeg
  1094. ffmpeg -i filename.mp3/filename.mp4 # to read entire history
  1095. # xmonad
  1096. --recompile Recompiles your configuration in ~/.xmonad/xmonad.hs
  1097. --restart Causes the currently running xmonad process to restart
  1098. --replace Replace the current window manager with xmonad
  1099. --version Display version of xmonad
  1100. --verbose-version Display detailed version of xmonad
  1101. Default keyboard bindings
  1102. mod-shift-return Launch terminal
  1103. mod-p Launch dmenu
  1104. mod-shift-p Launch gmrun
  1105. mod-shift-c Close the focused window
  1106. mod-space Rotate through the available layout algorithms
  1107. mod-shift-space Reset the layouts on the current workspace to default
  1108. mod-n Resize viewed windows to the correct size
  1109. mod-tab Move focus to the next window
  1110. mod-shift-tab Move focus to the previous window
  1111. mod-j Move focus to the next window
  1112. mod-k Move focus to the previous window
  1113. mod-m Move focus to the master window
  1114. mod-return Swap the focused window and the master window
  1115. mod-shift-j Swap the focused window with the next window
  1116. mod-shift-k Swap the focused window with the previous window
  1117. mod-h Shrink the master area
  1118. mod-l Expand the master area
  1119. mod-t Push window back into tiling
  1120. mod-comma Increment the number of windows in the master area
  1121. mod-period Deincrement the number of windows in the master area
  1122. mod-shift-q Quit xmonad
  1123. mod-q Restart xmonad
  1124. mod-shift-slash Run xmessage with a summary of the default keybindings
  1125. mod-[1..9] Switch to workspace N
  1126. mod-shift-[1..9] Move client to workspace N
  1127. mod-{w,e,r} Switch to physical/Xinerama screens 1, 2, or 3
  1128. mod-shift-{w,e,r} Move client to screen 1, 2, or 3
  1129. mod-button1 Set the window to floating mode and move by dragging
  1130. mod-button2 Raise the window to the top of the stack
  1131. mod-button3 Set the window to floating mode and resize by dragging
  1132. Examples
  1133. To use xmonad as your window manager add to your ~/.xinitrc file:
  1134. exec xmonad
  1135. Customization
  1136. xmonad is customized in ~/.xmonad/xmonad.hs, and the restarting with mod-q.
  1137. You can find many extensions to the core feature set in the xmonad-conrtib
  1138. package, available throught your package manager or from xmonad.org
  1139. Ref: https://xmonad.org/manpage.html#customization
  1140. # System Admin Skills
  1141. 1. Manage file systems
  1142. The single most important file related to file systems is /etc/fstab, which
  1143. holds their mount points, their types and various other permissions about
  1144. them - it is the job of the system administrator to alter and maintain the
  1145. /etc/fstab file in order to contain the correct information.
  1146. https://askubuntu.com/questions/420320/what-permissions-would-change-if-i-
  1147. change-umask-to-027-from-022
  1148. failed login attempts are logged in /var/log/faillog
  1149. https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-
  1150. ubuntu-quickstart
  1151. The magic of SysReq
  1152. Linux is usually stable enough to survive misbehaving software, but it is
  1153. possible for a program to lock up the whole computer. Before you reach for
  1154. the Power or Reset button and risk corrupting your file systems, there is a
  1155. better way to get out of it. You can send commands directly to the kernel by
  1156. holding down the Alt and SysReq (aka PrtScr) keys and pressing certain letter
  1157. keys. As the kernel listens for those directly, they work even if X is
  1158. completely locked and accepting no input.
  1159. The keys normally used to get out of a lockup are R, to reset the keyboard -
  1160. this occasionally fixes the problem on its own. Next, press E to send a TERM
  1161. signal to all processes, asking them to shut down cleanly, writing any data
  1162. to disk and closing any open files. Next in line is I, which sends a KILL
  1163. signal to all remaining processes, forcing them to shut down. Pressing S tells
  1164. the kernel to sync, flushing all buffers to disk so that remaining open files
  1165. can be closed cleanly. Press U to unmount all file systems and remount them
  1166. read-only, to avoid further data corruption. Finally, reboots the system.
  1167. So, that is: hold down Alt and SysReq and press R-E-I-S-U-B in turn, preferably
  1168. leaving a coubple of seconds between each. There are several, aminly silly,
  1169. mnemonics to help remember that sequence, the most appropriate being Reboot
  1170. Even if System Utterly Broken, but the easiet way to remember the sequence is
  1171. that it is BUSIER backwards. This is not something you should need very often,
  1172. but it is well worth remembering when you do.
  1173. ## cli-magic
  1174. w3m http://en.wikipedia.org/wiki/May_06
  1175. ## Documentation
  1176. Debian:
  1177. www.debian.org/doc
  1178. http://debian-handbook.info
  1179. Ubuntu:
  1180. https://help.ubuntu.com
  1181. https://help.ubuntu.com/community
  1182. www.askubuntu.com
  1183. Linux Mint:
  1184. www.linuxmint.com/documentation.php
  1185. OpenSuse:
  1186. http://doc.opensuse.org
  1187. Fedora:
  1188. http://docs.fedoraproject.org
  1189. CentOS:
  1190. www.centos.org/doc
  1191. RedHat:
  1192. http://tinyurl.com/rheldocs
  1193. Arch:
  1194. https://wiki.archlinux.org
  1195. ## ImageMagick
  1196. # Converts from JPEG format into PNG, original intact
  1197. convert image.jpg image.png
  1198. # can list the supported formats
  1199. convert -list format
  1200. # displays information about an image in a one-line summary. Add the -verbose
  1201. option to get a very detailed information report.
  1202. identify my_image.png
  1203. # This gives you a PNG image that is a maximum of 600 pixels wide and 400
  1204. pixels high. It preserves the aspect ratio and won't stretch, compress or
  1205. otherwise distort the image.
  1206. convert image.jpg -resize 600*400 image.png
  1207. # list color names
  1208. convert -list color
  1209. # for viewing image sequences(slideshows)
  1210. animate -delay 100 *.png
  1211. ## sxiv
  1212. sxiv -f -S 10 * # f - fullscreen, S - slideshow, 10 - 10 seconds, * - files
  1213. Enter # to view all images
  1214. ## Colors
  1215. #15242F terminal
  1216. #063A76 xmobar
  1217. ## ispell
  1218. ispell filename.txt # to run a spelling check
  1219. ispell highlights the first word it doesn't recognize. If the word is
  1220. misspelled, ispell usually offers one or more alternatives. Press R and
  1221. then the number beside the correct choice. In the screen capture above.
  1222. I'd press R and 0 to fix the error.
  1223. If, on the other hand, the word is correctly spelled, press A to move to the
  1224. next misspelled word. ispell saves your changes, creates a backup of the file
  1225. you just checked (with the extension .bak), and shuts down.
  1226. You need to tell it a file's format. When starting ispell, add -t for a Tex or
  1227. LaTex file, -H for an HTML file, or -n for a groff or troff file. For example,
  1228. if you enter
  1229. ispell -t myReport.tex, ispell ignores all markup.
  1230. If you don't want the backup file that ispell creates after checking a file,
  1231. add -x to the command line - for example, ispell -x myFile.txt
  1232. You can add a word to a personal word list by pressing I. This saves the word
  1233. to a file called .ispell_default in the root of your /home directory.
  1234. ## system-built
  1235. Taskbar: xmobar
  1236. http://projects.haskell.org/xmobar/
  1237. System tray: stalonetray
  1238. http://stalonetray.sourceforge.net/
  1239. Application launcher: dmenu
  1240. https://tools.suckless.org/dmenu/
  1241. Wallpaper setter: feh
  1242. https://feh/finalrewind.org/
  1243. Time management: calcurse
  1244. http://calcurse.org/
  1245. Image viewer: sxiv
  1246. https://github.com/muennich/sxiv
  1247. ## Man-pages
  1248. Using Git, you can obtain the very latest version of man-pages using the
  1249. following command:
  1250. $ git clone http://git.kernel.org/pub/scm/docs/man-pages/man-pages
  1251. You can see what's recently been pushed to kernel.org via CGit:
  1252. http://git.kernel.org/?p=docs/man-pages/man-pages.git
  1253. ## script - Recording the shell activities
  1254. $ script # Script started, file is typescript
  1255. Do whatever shell commands under script.
  1256. Press Ctrl-D to exit script.
  1257. $ vi typescript
  1258. ## popularity-contest
  1259. $ popularity-contest > /var/log/popularity-contest
  1260. $ popcon-largest-unused
  1261. ## apt-mark
  1262. To remove package from list of packages considered for removal, mark that
  1263. package as installed manually. You can do it using apt-mark:
  1264. $ apt-mark manual <package_name>
  1265. ## finger - displays information about the system users
  1266. $ finger # user information lookup program
  1267. ## clean and lean machine
  1268. fslint # a utility to find and clean various forms of lint on a filesystem,
  1269. especially duplicate files and broken symlinks.
  1270. debfoster # creates dependency files to enable you to keep track of what you
  1271. have installed.
  1272. localepurge # will remove all locale files from your system that you have
  1273. no need for
  1274. ## Pandoc
  1275. pandoc # pandoc is invoked without specifying any input files, it operates as
  1276. a filter, taking input from the terminal and sending its output back
  1277. to the terminal
  1278. By default, input is interpreted as pandoc markdown, and output is HTML.
  1279. # converting from HTML to markdown (hit Ctrl-D)
  1280. pandoc -f html -t markdown
  1281. # converting from markdown to LaTeX
  1282. pandoc -f markdown -t latex
  1283. # convert markdown file to HTML
  1284. pandoc test1.md -f markdown -t html -s -o test1.html
  1285. # convert markdown file to LaTeX
  1286. pandoc test1.md -f markdown -t latex -s -o test1.tex
  1287. To create a PDF, you'll need to have LaTeX installed.
  1288. pandoc test1.md -s -o test1.pdf
  1289. pandoc --help
  1290. ## update-alternatives command
  1291. $ ls -l $(type -p vi)
  1292. $ sudo update-alternatives --display vi
  1293. $ sudo update-alternatives --config vi
  1294. The Debian alternatives system keeps its selection as symlinks in
  1295. "/etc/alternatives/". The selection process uses corresponding file
  1296. in "/var/lib/dpkg/alternatives/".
  1297. ## font
  1298. # for core X11 font path
  1299. xset q
  1300. # for fontconfig font default
  1301. fc-match
  1302. # displays sorted list of best matching fonts, but do not do any pruning
  1303. fc-match -a
  1304. # displays sorted list of best matching fonts
  1305. fc-match -s
  1306. # for available fontconfig fonts
  1307. fc-list
  1308. ## watch - repeating a command with a constant interval
  1309. $ watch # executes a program repeatedly with a constant interval
  1310. $ watch w # this displays who is logged on to the system update every 2 seconds
  1311. ## scheduling tasks
  1312. scheduling tasks once
  1313. $ echo 'command -args' | at 3:40 monday
  1314. scheduling tasks regularly
  1315. $ cron(8)
  1316. # splitting a large file into small files
  1317. When a data is too big to backup as a single file, you cna backup its content
  1318. after splitting it into, e.g. 2000MiB chunks and merge those chunks back into
  1319. the original file late.
  1320. $ split -b 2000m large_file
  1321. $ cat x* > large_file
  1322. Please make sure you do not have any files starting with"x" to avoid name
  1323. crashes.
  1324. ## invisible disk space consumption
  1325. All deleted but open files consume disk space although they are not visible
  1326. from normal du. They can be listed with their size by the following.
  1327. # lsof -s -X / | grep deleted
  1328. $ lsof -i # to list all open network connections
  1329. ## pretty print a manual page
  1330. You can print a manual page in PostScript nicely by one of the following
  1331. commands.
  1332. $ man -Tps some_manpage | lpr
  1333. $ man -Tps some_manpage | mpage -2 | lpr # the second example prints 2 pages
  1334. on 1 sheet
  1335. ## merge two ps and pdf files
  1336. You can merge two postscript and portable document format files using gs of
  1337. ghostscript.
  1338. gs -q -dNOPAUSE -dBATCH -sDEVICE=pswrite -sOutputFile=bla.ps -f f1.ps f2.ps
  1339. gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=bla.pdf -f f1.pdf f2.pdf
  1340. https://www.ibm.com/developerworks/library/l-lpic1-map/index.html
  1341. ## parted - a partition manipulation program
  1342. parted --list # lists partition layout on all block devices
  1343. parted --help # displays a help message
  1344. parted --machine # displays machine parseable output
  1345. ## lpinfo - show available devices or drivers
  1346. lpinfo -v # list all devices
  1347. lpinfo -m # list all drivers
  1348. lpinfo --make-and-model "HP LaserJet" -m # list drivers matching "HP LaserJet"
  1349. ## Shell Scripting Tricks
  1350. # To see how much disk space is left
  1351. df
  1352. df -h # for a human readable format in megs & gigs
  1353. # To see where all my big files are
  1354. cd /somewhere
  1355. du -sk * | sort -nr
  1356. Repeat as necessary
  1357. # To see big directories instead of files
  1358. du -x /somewhere | sort -nr | head -10
  1359. This shows the 10 largest directories under /somewhere
  1360. Another way:
  1361. find /somewhere -size +2000k -ls
  1362. This shows all files over 2000 kilobytes under /somewhere
  1363. If you want to keep your .debs, you can filter them out of the list:
  1364. find / -size +2000k ! -name "*.deb" -ls
  1365. This shows all files on your entire system over 2000 kilobytes that
  1366. are not debian pkg.
  1367. # To rename them all with underscores instead of spaces
  1368. rename 's/ /_/g' *.mp3
  1369. This rename command is not a general Unix command but it's included with Perl
  1370. which is of course installed by default in Debian.
  1371. # To do that recursively
  1372. That's a bit tricky. You can get a list of files to pass to rename using find,
  1373. but if some of the directories are being renamed as well, that's not something
  1374. rename can keep track of. You have to use -depth with find to make sure any
  1375. files are renamed before the directories they're in.
  1376. cd /somewhere
  1377. find . -depth -name '* *' -type f -print0 | xargs -r0 rename 's/ /_/g'
  1378. # Systemd
  1379. systemd-analyze
  1380. systemd-analyze blame (results pipe to less by default, can use --no-pager)
  1381. systemd-analyze plot > /tmp/boot_plot.svg
  1382. # systemctl (not to be confused with sysctl) is used to manage units
  1383. systemctl start sshd.service # starting a unit
  1384. systemctl stop sshd.service # stopping a unit
  1385. systemctl restart sshd.service # restarting a unit
  1386. systemctl enable sshd.service # enable a unit to start at boot
  1387. systemctl disable sshd.service # disabling service so it does not run at boot
  1388. systemctl cat sshd.service # displaying the contents of a unit file
  1389. systemctl status sshd.service # to get information about a unit
  1390. systemctl suspend # sleep (suspend to RAM)
  1391. systemctl hibernate # hibernate (suspend to Disk)
  1392. # /sbin/shutdown task
  1393. systemctl reboot # reboot
  1394. systemctl halt # halt system (without powering off)
  1395. systemctl poweroff # power off system
  1396. systemctl --type service --state active # list services
  1397. systemctl list-unit-files --type=service # list all services
  1398. systemctl list-dependencies multi-user.target --no-pager # list all services by target
  1399. systemctl list-units --type target # view list of currently loaded targets
  1400. systemctl # lots of options...
  1401. systemctl- # lots of new commands...
  1402. # journalctl is used to interact with the journal
  1403. journalctl /path/to/executable # show all messages by a specific executable
  1404. journalctl _PID=456 # show all messages by a specific PID (ex. 456)
  1405. journalctl _SYSTEMD_INIT=sshd.service # show all messages by a specific unit
  1406. journalctl # show all messages in journal (view basic logs)
  1407. journalctl -n 10 # view most recent logs (-f to follow)
  1408. journalctl -p err # filter by priority
  1409. journalctl -p err --since "2015-2-17 18:00:00" --until "2015-2-17 18:10:00"
  1410. # filter by time and priority
  1411. # similar to the tail command, the -f flag can be used to follow the journal,
  1412. while the -n flag can be used to limit results to a number of most recent
  1413. messages, run man journalctl for the full list of options
  1414. # mpv
  1415. mpv [options] filename
  1416. mpv --shuffle /folder-path/*
  1417. mpv --playlist=filename.pls
  1418. # to activate the gapless audio optiona
  1419. mpv --gapless-audio --playlist=filename.pls
  1420. mpv --help
  1421. mpv --list-options
  1422. mpv link_to_youtube_vid --no-video # audio only format
  1423. # route
  1424. route -n
  1425. # nslookup - query Internet name servers interactively
  1426. nslookup <url>
  1427. nslookup -query=mx <url>
  1428. nslookup -type=ns <url> # query name server
  1429. nslookup -type=any <url> # query DNS record
  1430. nslookup -type-soa <url> # query start of authority
  1431. nslookup -port 56 <url? # query port number
  1432. # dig - a tool for querying DNS nameservers for information about host address,
  1433. mail exchanges, nameservers, and related information
  1434. dig <url>
  1435. dig <url> +nocomments # turn off comment lines
  1436. dig <url> +noauthority # turn off authrity section
  1437. dig <url> +noadditional # turn off additional section
  1438. dig <url> +nostats # turn off stats section
  1439. dig <url> +noanswer # turn off answer section
  1440. dig <url> +noall # disable all section at once
  1441. # uptime - verify what happened actually when the server was unattended
  1442. # wall "mesg" - sends mesg to everybody logged with their mesg permission yes
  1443. # mesg [n|y] - contrl people who can use the "write" command
  1444. # write <user_name> - send text directly to the screen of another linux machine
  1445. # talk <username> - lets you talk to the logged in users
  1446. # w - combination of uptime and who commands
  1447. # mysqldump
  1448. mysqldump -u root -p -all-databases > /home/server/Desktop/backupfile.sql
  1449. # mkpasswd
  1450. mkpasswd -l 10
  1451. # imagemagick
  1452. convert source.jpg -colorspace Gray destination.jpg # true grayscale only
  1453. convert source.jpg -monochrome destination.jpg # true black and white
  1454. convert source.jpg -separate destination.jpg # separate into gray channels
  1455. identify <image> # list size of image
  1456. convert -crop +0+100 <input_image> <output_image> # crop the image from top
  1457. convert -crop +0-100 <input_image> <output_image> # crop the image from bottom
  1458. convert -crop -5+0 <input_image> <output_image> # crop the image from right
  1459. convert -crop +5+0 <input_image> <output_image> # crop the image from left
  1460. # Installing the same selection of packages several times
  1461. It can be useful to systematically install the same list of packages on several
  1462. computers. This can be done quite easily.
  1463. First, retrieve the list of packages installed on the computer which will
  1464. serve as the "model" to copy.
  1465. $ dpkg --get-selections > pkg-list
  1466. The pkg-list file then contains the list of installed packages. Next, transfer
  1467. the pkg-list file onto the computers you want to update and use the following
  1468. commands:
  1469. ## Update dpkg's database of known packages
  1470. # avail='mktemp'
  1471. # apt-cache dumpavail > "$avail"
  1472. # dpkg --merge-avail "$avail"
  1473. # rm -f "$avail"
  1474. ## Update dpkg's selections
  1475. # dpkg --set-selections < pkg-list
  1476. ## Ask apt-get to install the selected packages
  1477. # apt-get dselect-upgrade
  1478. The first commands records the list of available packages in the dpkg database,
  1479. then dpkg --set-selections restores the selection of packages that you wish to
  1480. install, and the apt-get invocation executes the required operations! aptitude
  1481. does not have this command.
  1482. [Sources: pg. 108 The Debian Administrator's Handbook]
  1483. # deborphan
  1484. deborphan -sz
  1485. sudo apt remove --purge $(deborphan)
  1486. $ count the number of sub-directories
  1487. find ./* -type d | wc -l
  1488. Note: Remember to use ./* if you don't want to include the current directory
  1489. itself in the total
  1490. Note: Always read offical installation guide for Debian/Ubuntu
  1491. # find
  1492. find . -print # print all files and directories in current directory
  1493. find . -type f -ls # print all files with details
  1494. find . -type f # print only files in current directory, no directory
  1495. find . -type d # print only directories in current directory, no files
  1496. find ~ -name bu -type d # print only 'bu' directories in ~
  1497. find . -name my_file.txt # print only my_file.txt in .
  1498. find ~ -name '*.txt' # search for '*.txt' in ~
  1499. find . -iname '*.jpg' # find files by case-insensitive extension (ex: .jpg)
  1500. find . -type f -perm 777 # to find files by octal permission
  1501. find . -size +10M -print # find all files larger than 10M
  1502. find . -type f -mmin -60 # find all files that were changed within last 60 min.
  1503. find . -type f -exec mv {} {}.py # add all files with ".py" at the end
  1504. find . -type f -name "*cmd*" # find files whose names have the string "cmd"
  1505. # find files whose names have the string
  1506. find . -type f -name "*cmd*" or -name "*line*"
  1507. # find files whose names have the string
  1508. find . -type f -name "*cmd*" and -name "*line*"
  1509. # find all directories in the current directory and their disk usage
  1510. find * -prune -type d -exec du -skh {} \;
  1511. # wn - command line interface to WordNet lexical database
  1512. wn perusing -over # to find definition of word perusing
  1513. # Text
  1514. less -M # for file name, the current and total lines
  1515. iostat
  1516. # history
  1517. history -c # to clear shell history
  1518. ctrl P / ctrl N # backward & forward of commands in history in the shell prompt
  1519. # wn - command line interface to WordNet lexical database
  1520. wn <word> -over # read wn man page
  1521. # nmap - Network exploration tool and security/port scanner
  1522. nmap -h # Nmap help
  1523. nmap scanme.nmap.org # default scan 1000 ports
  1524. nmap -p 22 scanme.nmap.org # scan port 22 alone
  1525. nmap -A scanme.nmap.org # OS information
  1526. nmap -F scanme.nmap.org # most important targeted ports
  1527. nmap -sV scanme.nmap.org # short information
  1528. nmap --open scanme.nmap.org # open ports alone
  1529. nmap -A -T4 slackware.com
  1530. ifconfig
  1531. ipcalc 192.168.42.136
  1532. nmap -F 192.168.42.8/24
  1533. sudo arp-scan -l
  1534. https://nmap.org/
  1535. https://www.nirsoft.net/countryip/ # Major IP Addresses Blocks by Country
  1536. who is <ip_address> # in web browser
  1537. geoiplookup.net/ip-addresses/<ip_address>
  1538. # checking package integrity
  1539. The md5sum command is used to compute a 128-bit fingerprint that is strongly
  1540. dependant upon the contents of the file to which it is applied. It can be used
  1541. to compare against a previously-generated sum to determine whether the file
  1542. has changed. It is commonly used to ensure the integrity of updated packages
  1543. distributed by a vendor:
  1544. sudo md5sum <package-name>
  1545. # ufw
  1546. sudo ufw app list # available applications
  1547. sudo ufw allow OpenSSH # to allow SSH connections
  1548. sudo ufw enable # enable the firewall
  1549. sudo ufw status # status of the firewall
  1550. sudo ufw status verbose
  1551. Block an IP Address
  1552. To block all network connections that originate from a specific IP address,
  1553. 15.15.15.51
  1554. $ sudo ufw deny from 15.15.15.51
  1555. [source IP address - 15.15.15.51, subnet IP address - 15.15.15.0/24]
  1556. Note: the source IP address can be specified in any firewall rule
  1557. Block connections to a Network interface:
  1558. To block connections from a specific IP address, eg. 15.15.15.51, to a specific
  1559. network interface, eg. eth0, use this command.
  1560. $ sudo ufw deny in on eth0 from 15.15.15.51
  1561. This is the same as the previous example, with the addition of in on eth0.
  1562. The netwoek interface can be specified in any firewall rule and is a great
  1563. way to limit the rule to a particular network.
  1564. Reference:
  1565. https://www.digitalocean.com/community/tutorials/ufw-essentials-common-
  1566. firewall-rules-and-commands
  1567. https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-
  1568. with-ufw-on-ubuntu-16-04
  1569. # apt-file
  1570. apt-file is a command line tool for searching packages in Debian repositories
  1571. sudo apt install apt-file # to install apt-file
  1572. sudo apt-file update # to update apt-file database
  1573. apt-file search <package_name> # to query the database for <package_name>
  1574. apt-file search path/to/<package_name>
  1575. apt-file list <package_name> # to list the content of an uninstalled package
  1576. sudo apt-file purge # to delete the cache files
  1577. # user
  1578. # add user Mark [-m tells Linux to create home directory]
  1579. sudo useradd -m mark
  1580. # to create password for Mark
  1581. sudo passwd mark
  1582. # to remove a user by name mark
  1583. sudo userdel mark
  1584. # set date on which the account will expire
  1585. sudo usermod -e 2017-12-31 mark
  1586. # to change Mark's login name to Henry
  1587. sudo usermod -l henry mark
  1588. # to temporarily lock Mark out of his account
  1589. sudo usermod -L mark
  1590. # using -U will unlock and -G will add/remove membership group
  1591. sudo usermod -G sudo mark
  1592. # to force users to change password (no < 5 but no > 30 days)
  1593. sudo chage -m 5 -M 30 mark
  1594. # to send Mark a warning seven days before his deadline
  1595. sudo chage -W 7 mark
  1596. # to list Mark's current settings
  1597. sudo chage --list mark
  1598. Note: Referance Practical_LPIC-1.pdf (page:102)
  1599. # user and permissions
  1600. ## create a user called ashley
  1601. useradd --create-home ashley
  1602. ## create a user in groups "users" and "dev"
  1603. useradd --create-home --groups users dev ashley
  1604. ## create a user with the UID 1337
  1605. useradd --create-home --uid 1337 ashley
  1606. ## create or change a user password
  1607. passwd ashley
  1608. <enter password>
  1609. ## add user to a group "coder"
  1610. usermod --append --groups coder ashley
  1611. ## remove a user from a group "coder"
  1612. gpasswd --delete ashley coder
  1613. ## delete a user from the system
  1614. userdel ashley
  1615. ## delete a user and all user data from the system
  1616. userdel --remove ashley
  1617. ## show which users are currently logged in
  1618. w
  1619. ## show login history
  1620. last
  1621. ## set default permission of files to 644
  1622. echo "umask 022" >> /etc/profile
  1623. ## set default permission of files to 664
  1624. echo "umask 002" >> /etc/profile
  1625. ## change ownership of a file "example.txt" to user "ashley"
  1626. chown ashley:users example.txt
  1627. ## give read permission to user, group, and others
  1628. chmod ugo+r example.txt
  1629. ## give write permissions to user and group
  1630. chmod ug+w example.txt
  1631. ## remove write permission to a file for group members
  1632. chmod g-w example.txt
  1633. ## make a file executable
  1634. chmod +x example.txt
  1635. ## log in as a different user
  1636. su - ashley
  1637. ## run a command "ls" as a different user
  1638. su - ashley --command ls
  1639. # vagrant
  1640. # cfdisk
  1641. # Basic text analysis with command line tools in Linux
  1642. Book from Internet Archive for text analysis.
  1643. Jane Andrews, The Stories Mother Nature Told Her Children (1888, 1894)
  1644. (Project Gutenberg collection)
  1645. wget http://archive.org/download/thestoriesmother05792gut/stmtn10.txt
  1646. file stmtn10.txt
  1647. stmtn10.txt: C source, ASCII text, with CRLF line terminators
  1648. Note: The output of the file command confirms that this is an ASCII text,
  1649. guesses that it is some code in the C programming language (which is incorrect)
  1650. and tells us that the ends of the lines in the file are coded with both a
  1651. carriage return and a line feed.
  1652. This is standard for window computers. Linux expect the ends of lines in an
  1653. ASCII text file to be coded only with a line feed. If we want to move text
  1654. files between operating systems, this is one thing we have to pay attention to.
  1655. The head & tail commands show us the first few and last few lines of the file.
  1656. head stmtn10.txt
  1657. tail stmtn10.txt
  1658. Before modifying files, it is usually a good idea to make a copy of the
  1659. original. We can do this with the cp command.
  1660. cp stmtn10.txt stmtn10-backup.txt
  1661. less -N stmtn10.txt # option -N to include line numbers at the beginning
  1662. of each line
  1663. # command to delete all of the material between lines 2206 and 2525
  1664. sed '2206,2525d' stmtn10.txt > stmtn10-nofooter.txt # sed - Linux stream editor
  1665. sed '1,40d' stmtn10-nofooter.txt > stmtn10-trimmed.txt
  1666. wc -l stmtn10-trimmed.txt # number of lines
  1667. wc -m stmtn10-trimmed.txt # number of characters
  1668. grep # pattern-matching command
  1669. # command below shows lines which contain the word giant,
  1670. this pattern is case sensitive
  1671. grep -n "giant" stmtn10-trimmed.txt # option -n to include line numbers
  1672. grep -E -n "(G|g)iant" stmtn10-trimmed.txt
  1673. grep -i, --ignore-case
  1674. grep -o
  1675. grep -v
  1676. grep -A NUM, --after-context=NUM
  1677. grep -B NUM, --before-context=NUM
  1678. grep -C NUM, -NUM, --context=NUM
  1679. # When we are analyzing the words in a text, it is usually convenient to
  1680. create a standardized version that eliminates whitespace and punctuation
  1681. and converts all characters to lowercase. We use the tr command to translate
  1682. and delete characters of our trimmed text, to create a standardized version.
  1683. Note that in this case the tr command requires that we use the redirection
  1684. operators to specify both the input file (<) and the output file (>).
  1685. # delete all punctuation
  1686. tr -d [:punct:] < stmtn10-trimmed.txt > stmtn10-nopunct.txt
  1687. # upper to lower
  1688. tr [:upper:] [:lower:] < stmtn10-nopunct.txt > stmtn10-lowercase.txt
  1689. # Counting word frequencies
  1690. # translate ' ' to '\n'
  1691. tr ' ' '\n' < stmtn10-lowercaself.txt > stmtn10-oneword.txt
  1692. # to sort that file so the words are in alphabetical order,
  1693. and so that if a given word appears a number of times, these
  1694. are listed one after another.
  1695. sort stmtn10-newword.txt > stmtn10-onewordsort.txt
  1696. # uniq command with the -c option to count the number of repetitions
  1697. of each line
  1698. uniq -c stmtn10-onewordsort.txt > stmtn10-wordfreq.txt
  1699. # all commands in one line
  1700. tr ' ' '\n' < stmtn10-lowercaself.txt | sort | uniq -c > stmtn10-wordfreq2.txt
  1701. # search for a particular term with the forward slash (/giant, for example)
  1702. Ref: https://williamjturkel.net/2013/06/15/basic-text-analysis-with-command-
  1703. line-tools-in-linux/
  1704. # Virtual Machine
  1705. virtinst - Program to create and clone virtual machines
  1706. virt-install
  1707. virt-manager
  1708. # Running Linux as a guest VM
  1709. Reference: Linux_Kernel_Programming.pdf (page no. 14)
  1710. # pdftotext
  1711. pdftotext -layout report.pdf report.txt
  1712. # calcurse
  1713. calcurse -t # List all todo items
  1714. calcurse -a # Print the appointments and events for the current day and exit
  1715. calcurse -r7 # Print appointments and events for the next seven days
  1716. # Reviewing what you did today
  1717. # To list all the files in your home directory tree, excluding direcotries,
  1718. that were accessed today: $ find ` -daystart -atime -1 \! -type d
  1719. # To list all the files in your home directory tree, excluding directories,
  1720. that were modified today: $ find ~ -daystart -mtime -1 \! -type d
  1721. # To list all the files in your home directory tree, excluding diretories,
  1722. that were accessed between now and two days ago:
  1723. $ find ~ -daystart -atime -2 \! -type d
  1724. # To list all the files in your home directory tree, excluding directories,
  1725. that were modified exactly two days ago: $ find ~ -daystart -mtime 2 \! -type d
  1726. # To find out what you did on September 11, 2001, type:
  1727. $ touch -d "Sep 11 2001" /tmp/911
  1728. $ touch -d "Sep 12 2001" /tmp/912
  1729. $ find ~ -daystart -newer /tmp/911 \! -daystart -newer /tmp/912
  1730. # expand and unexpand
  1731. expand -t 10 filename # convert every tab to ten spaces
  1732. unexpand -t 3 filename # convert every three spaces to tabs
  1733. # format text
  1734. fmt -w 60 filename # start a new line after 60 characters
  1735. fmt -t filename # indent all but the first line of a paragraph
  1736. # docker
  1737. Method 1: Managing services in linux with systemd
  1738. systemctl list-unit-files --type service -all # list all services
  1739. sudo systemctl | grep running # list running services
  1740. systemctl start docker.service # start a service
  1741. systemctl start docker.socket
  1742. systemctl stop docker.service # stop a service
  1743. systemctl stop docker.socket
  1744. systemctl restart docker.service # restart a service
  1745. systemctl restart docker.socket
  1746. systemctl status docker.service # check the status of a service
  1747. systemctl status docker.socket
  1748. Method 2: Managing services in linux with init
  1749. service --status-all # list all services ([-] are disabled and [+] are enabled)
  1750. service <service-name> start # start a service
  1751. service <service-name> stop # stop a service
  1752. service <service-name> restart # restart a service
  1753. service <service-name> status # check the status of a service
  1754. # Format USB Drive
  1755. Step 1: Insert USB and Identify Volume
  1756. Insert a USB drive into your system and identify your USB drive correctly. This
  1757. is the step you need to take care, because you may format the wrong disk if not
  1758. correctly identify your disk.
  1759. $ df -h
  1760. Step 2: Format USB Drive in Linux
  1761. Whenever we attach a USB drive, it automatically mounted to the system. We can
  1762. not format any disk on Linux systems which are already mounted. So first
  1763. un-mount /dev/sdc1 USB drive on your system.
  1764. $ sudo umount /dev/sdc1
  1765. Step 3: Format with vFat file system $ sudo mkfs.vfat /dev/sdc1
  1766. Format with NTFS file system $ sudo mkfs.ntfs /dev/sdc1
  1767. Format with EXT4 file system $ sudo mkfs.ext4 /dev/sdc1
  1768. # Translate html to text
  1769. cat index.html | w3m -dump -T text/html > index.txt
  1770. # Permissions and their likely uses (chmod 700 /home/user/file)
  1771. Permission Octal_Code Meaning
  1772. rwxrwxrwx 777 Read, write, and execute permissions for all users
  1773. rwxr-xr-x 755 Read and execute permission for all users. The file
  1774. owner also has write permission.
  1775. rwxr-x--- 750 Read and execute permission for the owner and group.
  1776. The file's owner also has write permission. Users
  1777. who are not the file's owner or members of the group
  1778. have no access to the file.
  1779. rwx------ 700 Read, write, and execute permissions for the file's
  1780. owner only; all others have no access.
  1781. rw-rw-rw- 666 Read and write permissions for all users. No execute
  1782. permissions to anybody.
  1783. rw-rw-r-- 664 Read and write permissions to the owner and group.
  1784. Read-only permission to all others.
  1785. rw-rw---- 660 Read and write permissions to the woner and group.
  1786. No world permissions.
  1787. rw-r--r-- 644 Read and write permissions to the owner. Read-only
  1788. permission to all others.
  1789. rw-r----- 640 Read and write permissions to the owner, and read-
  1790. only permission to the group. No permission to other
  1791. rw------- 600 Read and write permissions to the owner. No permiss-
  1792. ion to anybody else.
  1793. r-------- 400 Read permission to the owner. No permission to any-
  1794. body else.
  1795. # netstat
  1796. netstat -p > net_connections.txt # redirect stdoutput to file
  1797. netstat -p 2> error_messages.txt # redirect stderror to file
  1798. netstat -p &> net_connections.txt # redirect stdoutput and stderror to file
  1799. # Common Environment variables and their meanings
  1800. Variable_Name Explanation
  1801. $USER This is your current username. It's a variable that's
  1802. maintained by the system.
  1803. $SHELL This variable holds the path to the current command shell.
  1804. $PWD This is the present working directory. This environment
  1805. variable is maintained by the system. Programs may use it to
  1806. search for files when you don't provide a complete pathname.
  1807. $HOSTNAME This is the current TCP/IP hostname of the computer.
  1808. $PATH This is an unusually important environment variable. It sets
  1809. the path for a session; the path is a coon-delimited list of
  1810. directories in which Linux searches for executable programs
  1811. when you type a program name. For instance, if PATH is
  1812. /bin:/usr/bin and you type ls, Linux looks for an executable
  1813. program called ls in /bin and then in /usr/bin If the command
  1814. you type isn't on the path, Linux responds with a command not
  1815. found error. The $PATH variable is typically built up in
  1816. several configuration files, such as /etc/profile and the
  1817. .bashrc file in the user's home directory.
  1818. $HOME This variable points to your home directory. Some programs
  1819. use it to help them look for configuration files or as a
  1820. default location in which to store files.
  1821. $LD_LIBRARY_PATH A few programs use this environment variable to indicate
  1822. directories in which library files may be found. It wroks
  1823. much like PATH.
  1824. $PS1 This is the default prompt in bash. It generally includes
  1825. variables of its own, such as \u (for the username),
  1826. \h (for the hostname), and \# (for the current working
  1827. directory). This value is frequently set in /etc/profile,
  1828. but it is often overridden by users.
  1829. $TERM This variable is the name of the current terminal type.
  1830. $DISPLAY This variable identifies the display used by X. It's usually
  1831. :0.0, which means the first (numbered from 0) display on the
  1832. current computer. When you use X in a networked environment,
  1833. though, this value mey be preceded by the name of the
  1834. computer at which you're sitting, as in machine4.example.com:
  1835. 0.0. This value is set automatically when you log in, but you
  1836. may change it if necessary. You can run multiple X sessions
  1837. on one computer, in which case each one gets a different
  1838. DISPLAY number - for instance, :0.0 for the first session
  1839. and :1.0 for the second.
  1840. $EDITOR Some programs launch the program pointed to by this
  1841. environment variable when they need to call a text editor
  1842. for you to use.
  1843. # Verify that the hash matches the downloaded image:
  1844. You need to verify that the hash matches the downloaded image, and then verify
  1845. that the hash was signed by an official Debian key - as explained in
  1846. (https://linuxconfig.org/how-to-verify-an-authenticity-of-downloaded-debian-
  1847. iso-images).
  1848. 1. Download your CD image, a SHA 512 hash, and the hash signature. (debian.org)
  1849. 2. Verify that the hash matches the image
  1850. $ sha512sum debian-8.3.0-i386-netinst.iso > my_hash.txt
  1851. $ diff -q my_hash.txt SHA512SUMS
  1852. 3. Verify the hash is properly signed. You'll probably have to do it twice:
  1853. once to get the key ID, and again after you have downloaded the public key.
  1854. $ gpg --verify SHA512SUMS.sign SHA512SUMS
  1855. gpg: Signature made Mon 25 Jan 2016 05:00:46 AEDT using RSA key ID 6294BE9B
  1856. $ gpg --keyserver keyring.debian.org --recv 6294B#9B
  1857. $ gpg --verify SHA512SUMS.sign SHA512SUMS
  1858. 4. Verify that the key fingerprint (the last printed line) is legitimate.
  1859. Ideally, you should do this via a web of trust
  1860. (https://www.gnupg.org/gph/en/manual/x547.html).
  1861. However you can check the key fingerprint against the keys listed on Debian's
  1862. website (https://www.debian.org/CD/verify).
  1863. Ref: https://unix.stackexchange.com/questions/138603/how-to-verify-debian-iso-
  1864. integrity
  1865. # Check the Hard Disk Serial Number in Linux
  1866. # to know the device names of your disks
  1867. df -h
  1868. # displays the hard drive model and vendor but not serial number
  1869. hwinfo
  1870. # displays the list of hardware installed on your machine
  1871. lshw
  1872. # displays the serial number
  1873. lshw -class disk
  1874. # is a tool part of the smartmontools package (sudo apt install smartmontools)
  1875. smartctl
  1876. # displays the serial number
  1877. smartctl -i /dev/sda
  1878. # displays the serial number
  1879. hdparm -i /dev/sda
  1880. # Hex codes
  1881. Hex: #101718 RGBA(16,23,24,1)
  1882. HeX: #1f2a2e RGBA(31,42,46,1)
  1883. # awk
  1884. awk 'NR==100' filename.txt # print text in line number 100 from filename.txt
  1885. awk 'NR>=100 && NR<=110' filename.txt # print text between lines 100 and 110
  1886. # set default web browser
  1887. sudo update-alternatives --list x-www-browser
  1888. sudo update-alternatives --config x-www-browser
  1889. # xdg-open
  1890. xdg-open file.csv # opens file.csv in default application
  1891. # tee
  1892. echo "institute of mathematical sciences" | tee -a institute.txt
  1893. # display cursor size in debian
  1894. gsettings get org.gnome.desktop.interface cursor-size
  1895. gsettings set org.gnome.desktop.interface cursor-size 20
  1896. # show history of recently installed packages, their version number, and the
  1897. date/time they were installed:
  1898. grep "install" /var/log/dpkg.log
  1899. # show a list of recently upgraded packages, the date/time they were upgraded,
  1900. as well as the old and new package version:
  1901. grep "upgrade" /var/log/dpkg.log
  1902. # show a history of recently removed packages and the date/time they were
  1903. removed:
  1904. grep "remove" /var/log/dpkg.log
  1905. # /var/log/dpkg.log contains the package install, update and remove history
  1906. for the current month. For the previous month, read the /var/log/dpkg.log.1
  1907. log file.
  1908. grep "install" /var/log/dpkg.log.1
  1909. # want to go back even more in the dpkg history? Use zgrep instead of grep,
  1910. and read /var/log/dpkg.log.2.gz, /var/log/dpkg.log.3.gz, /var/log/dpkg.log.4.gz
  1911. and so on, which go back two, three and respectively four months:
  1912. zgrep "upgrade" /var/log/dpkg.log.2.gz
  1913. This is because by default, the dpkg log is set to rotate once a month, keeping
  1914. 12 old logs (so for 12 months), and compress rotated files by using gzip (.gz).
  1915. You can check the Debian Logrotate configuration for dpkg by using cat
  1916. /etc/logrotate.d/dpkg
  1917. # to check sudo access for a user
  1918. sudo -l
  1919. # to check init or systemd
  1920. ps --no-headers -o comm 1
  1921. # init service commands
  1922. sudo service ssh status/start/stop/restart/reload/condrestart
  1923. # public IP address
  1924. curl ifconfig.me
  1925. # private IP address
  1926. hostname -I
  1927. ip addr
  1928. ifconfig
  1929. # rename user in linux
  1930. usermod -l nname oname
  1931. # ssh with port number
  1932. ssh -p 22 user@hostname
  1933. # cat two files
  1934. cat -n {file1.txt,file2.txt}
  1935. cat -n file1.txt file2.txt
  1936. # make directory with mode
  1937. mkdir -m777 <directoryname>
  1938. # MySQL
  1939. sudo dpkg-reconfigure mysql-apt-config
  1940. apt-policy mysql-server
  1941. dpkg -l | grep -i 'mysql'
  1942. # List only sub-directories of the current directory
  1943. ls -d */
  1944. # qutebrowser
  1945. .venv/bin/python -m qutebrowser --temp-basedir
  1946. # change bash shell prompt
  1947. PS1="g62231tx:~$ "
  1948. # extract .7z file
  1949. sudo apt-get install p7zip p7zip-full p7zip-rar
  1950. man p7zip; man 7za
  1951. 7za e <filename>.7z
  1952. # reference the last argument of the previous command
  1953. ls Downloads/
  1954. cd $_
  1955. # work on files and directories
  1956. mkdir -v dir_{rpm,txt,zip,pdf}
  1957. # find command by example
  1958. find . -type f -name '*statistical*' | less -N
  1959. find . -iname '*statistical*' | less -N
  1960. # xdg-open
  1961. xdg-open <filename>
  1962. # access last argument of the previous command
  1963. mkdir Example
  1964. cd !$ (equivalent to 'cd Example')
  1965. # shellcheck
  1966. shellcheck file.sh
  1967. # change to previous directory and change to directory
  1968. cd ../Directory
  1969. # locate command
  1970. sudo updatedb # update database
  1971. locate -i 'searchtext'
  1972. # aspell
  1973. echo word | aspell -a
  1974. aspell check text.txt
  1975. # path of the command
  1976. type -P <command>
  1977. which <command>
  1978. # display one-line manual page descriptions
  1979. whatis <command>
  1980. # linux version
  1981. cat /etc/os-release
  1982. hostnamectl
  1983. lsb_release -a
  1984. uname -r
  1985. # merge images in command line
  1986. convert image1.png image2.png image3.png -append Sprite/verticalsprite.png
  1987. convert image1.png image2.png image3.png +append Sprite/horizontalsprite.png
  1988. convert image{1..12}.png -append Sprite/verticalsprite.png
  1989. convert image{1..12}.png +append Sprite/horizontalsprite.png
  1990. gm convert image1.png image2.png image3.png -append Sprite/verticalsprite.png
  1991. gm convert image1.png image2.png image3.png +append Sprite/horizontalsprite.png
  1992. # resize an image [Ref: https://imagemagick.org/]
  1993. magick mogrify -resize 50% image.jpg # reduce the size of image.jpg by 50%
  1994. magick mogrify -resize 256x256 image.jpg # resize image.jpg to a dimension of 256x256
  1995. magick mogrify -format jpg image.png # convert PNG format image.png to the JPEG format
  1996. convert input.png -resize 200x100 output.png # preserve the aspect ratio
  1997. convert input.png -resize 200x100! output.png # don't preserve the aspect ratio
  1998. convert input.png -resize 200 output.png # resize an image to a width of 200
  1999. convert input.png -resize x100 output.png # resize an image to a height of 100
  2000. # rotate an image
  2001. convert input.jpg -rotate 180 output.jpg
  2002. for image in *.jpg; do convert $image -rotate 90 $image; done
  2003. mogrify -rotate 90 image.jpg
  2004. # applying effects
  2005. convert input.png -charcoal 2 output.png # apply charcoal effect to an image (2=strength)
  2006. convert input.png -implode 1 output.png # apply implode effect to an image
  2007. # combining operations
  2008. convert input.png -resize 400x400 -rotate 180 -charcoal 4 -quality 95 output.png
  2009. # xset - user preference utility for X
  2010. xset q - information on the current settings
  2011. # package management
  2012. aptitude update # updating package database
  2013. aptitude upgrade --simulate # showing available updates
  2014. aptitude install pkg1 pkg2 # updating a particular package
  2015. apt-get install pkg1 pkg2 # installing packages
  2016. apt-get install --reinstall pkg1 pkg1 # reinstalling a particular package
  2017. apt-cache search <searchword> # searching the package database
  2018. apt-cache search --full --names-only <searchword> # long package information
  2019. apt-get remove package1 package2 # removing packages
  2020. apt-get remove --purge package1 package2 # remove along with all configuration files
  2021. apt-get install --download-only pkg1 pkg2 # only downloading packages
  2022. apt-get clean # cleaning up downloaded packages
  2023. apt-get autoclean # remove outdated packages
  2024. # 50 linux commands
  2025. Linux commands for navigating the file system:
  2026. pwd - print work directory
  2027. ls - list files
  2028. cd - change directory
  2029. mkdir - make directory
  2030. rmdir - remove empty directory
  2031. lsblk - list block devices
  2032. mount - mount SD card or USB in existing filesystem
  2033. df - information about the disk space on filesystem
  2034. Linux commands for manipulating the system:
  2035. uname - system information (name, version, ...)
  2036. ps - processes currently running
  2037. kill - stop processes that are struck due to resource constraints
  2038. service - invoke system-wide services (System V init)
  2039. batch - run system services in apre-defined schedule (automation shell scripts)
  2040. shutdown - shutdown the system
  2041. Linux commands for taking care of your files:
  2042. touch - creating a valid empty file (command for changing timestamps)
  2043. cat - concatenating multiple files
  2044. head - view the beginning of a file
  2045. tail - vies the ending of a file
  2046. cp - copy a file or directory
  2047. mv - move/rename a file or directory
  2048. comm - compare two files for common and distinct lines
  2049. less - viewing the contents of a file
  2050. ln - creating symbolic links to a file
  2051. cmp - compare two files and print the result tot the standard output stream
  2052. dd - copy and convert files from one type to another (creating bootable live USB sticks)
  2053. alias - replace a word by another string in files directly from the terminal
  2054. Funny Linux commands to explore:
  2055. cal - calendar in an ASCII text format
  2056. fortune - print poignant, inspirational, or silly phrases in terminal
  2057. history - history of terminal sessions
  2058. yes - ouput a string repeatedly until killed
  2059. banner - ASCII banners
  2060. rev - print text reversing each character
  2061. Linux commands for network administrators:
  2062. wget - download files from the web from the terminal
  2063. iptables - control the incoming and outgoing internet traffic on a host machine
  2064. traceroute - determine the route a network packet takes on its way form machine to another
  2065. curl - transferring files over a network (network related shell scripts)
  2066. Linux commands for search and regular expression:
  2067. find - search for files based on file permissions, ownership, modification date, size, ...
  2068. which - locate the path of a command
  2069. locate - location of a specific file by regular expression
  2070. grep - search for patterns
  2071. sed - manipulate a file or stream by replacing specific parts
  2072. Linux commands that deal with I/O and ownership:
  2073. clear - clear out existing terminal screen
  2074. echo - output a specific text to the terminal console
  2075. sort - sort out a file in an alphabetical or reverse manner
  2076. sudo - lets non-privileged users access
  2077. chmod - change/modify the access permissions of system files or directory
  2078. chown - change/modify the ownership of a file or directory
  2079. Linux command miscellaneous for use:
  2080. man - manual
  2081. tar - archiving files and extracting them
  2082. whatis - display one-line manual page descriptions
  2083. # column
  2084. dpkg -S $(which column)
  2085. dpkg -l | grep -i 'util-linux'
  2086. man column
  2087. column -t /etc/passwd
  2088. column -t -s ":" -n /etc/passwd
  2089. column -e -t -s "," file.txt
  2090. column -x file.txt
  2091. # rotate screen in linux with xrandr
  2092. xrandr -o left # orientation left
  2093. xrandr -o right # orientation right
  2094. xrandr -o normal # orientation normal
  2095. # sponge command to replace changes/manipulates in data file
  2096. column -t data.csv | sponge data.csv
  2097. # list installed deb packages by size
  2098. dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
  2099. wajig large
  2100. dpigs
  2101. dpkg-query -W --showformat='$PInstalled-Size}\t${Package}\n' | sort -nr | less
  2102. glimpse
  2103. nethogs
  2104. # display the GPU info
  2105. sudo lshw -C display -short
  2106. lspci -v | less
  2107. # GPU performance testing tool
  2108. apt-get install mesa-utils
  2109. glxgears
  2110. # command-line based download accelerator
  2111. sudo apt-get install axel
  2112. axel https://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso
  2113. # uuencode
  2114. sudo apt-get install sharutils
  2115. # identify (required imagemagick)
  2116. identify -verbose <filename.jpg>
  2117. # ffprobe
  2118. ffprobe <filename.mp3> # information regarding audio file
  2119. # mediainfo
  2120. mediainfo <filename.mp3>
  2121. # sox
  2122. soxi file.wav # metadata
  2123. soxi -D file.wav # duration in seconds
  2124. soxi -d file.wav # duration in hh:mm:ss.ss
  2125. play file.wav echo 0.7 0.6 50 0.2
  2126. play file.wav echos 0.4 0.6 900.0 0.25 900.0 0.3
  2127. play file.wav echo 0.7 0.89 1000.0 0.1
  2128. sox file.wav trim 0 10 trimmed.wav
  2129. sox file.wav -t nul /dev/null trim 0 0.5 noiseprof profile
  2130. play file.wav noisered profile
  2131. play file.wav chorus 0.6 0.9 50.0 0.4 0.25 2.0 -t 60.0 0.32 0.4 1.3 -s
  2132. play file.wav fade 5
  2133. play file.wav reverse
  2134. https://www.linuxjournal.com/content/powerful-multimedia-command-line-tools-part-i-sox
  2135. # unoconv - convert any document from and to any LibreOffice supported format
  2136. # change default cursor theme
  2137. list of cursors theme available:
  2138. crystalcursors dmz-cursor-theme xcursor-themes comixcursors Chamelon-cursor-theme
  2139. installing crystalcursors:
  2140. sudo apt-get install crystalcursors
  2141. run the update-alternative to set/change the current-cursor-theme:
  2142. sudo update-alternatives --config x-cursor-theme
  2143. # hide the cursor pointer
  2144. sudo apt-get install unclutter
  2145. put the following in a script 'unclutter.sh': unclutter -idle 1 -root -grab -visible
  2146. chmod u+x unclutter.sh
  2147. unclutter &
  2148. [add this line to ~/.xinitrc: unclutter &]
  2149. to stop unclutter: sudo killall unclutter
  2150. put "SDL_VIDEO_X11_DGAMOUSE=0" in ~/.profile [Ref: https://wiki.debian.org/unclutter]
  2151. # copy and paste with xclip
  2152. $ xclip -sel clip ~/.ssh/id_ed25519.pub
  2153. $ tail -n 30 logfile.log | xclip -sel clip
  2154. $ pandoc -t html file.md | xclip -sel clip
  2155. $ cat /etc/apt/sources.list | xclip -sel clip
  2156. $ xclip -o -sel clip > file.txt
  2157. # list installed packages in DEB based systems
  2158. apt-cache policy
  2159. /etc/apt/sources.list.d/
  2160. # tar files:
  2161. 1. compress an entire directory /home/saran/Tardirectory/
  2162. $ tar -czvf file.tar.gz /home/saran/Tardirectory/
  2163. 2. compress multiple directories and files:
  2164. $ tar -czvf file.tar.gz /home/saran/Documents/ /home/saran/Music/
  2165. /home/saran/Pictures/image.png
  2166. 3. bzip2 compression instead of gzip by passing -j option:
  2167. $ tar -cjvf file.tar.bz2 /home/saran/Tardirectory/
  2168. 4. exclude files when using tar:
  2169. $ tar -czvf archive.tar.gz --exclude='file.txt' /home/saran/Directory/
  2170. 5. exclude ~/Downloads directory:
  2171. $ tar -czvf /nfs/backup.tar.gz --exclude="Downloads" /home/saran/
  2172. 6. view files stored in an archive:
  2173. $ tar -ztvf file.tar.gz
  2174. $ tar -jtvf file.tar.bz2
  2175. 7. extracting an archive:
  2176. $ tar -xzvf file.tar.gz
  2177. $ tar -xjvf file.tar.bz2
  2178. 8. extract the contents of the archive into a specific directory:
  2179. $ tar -xzvf file.tar.gz -C /home/saran/Backup/
  2180. $ tar -xjvf file.tar.bz2 -C /home/saran/Backup/
  2181. # check ip address in termux: (check for 'UP')
  2182. ip -br addr | grep -v DOWN
  2183. sshd # start ssh demeon in termux
  2184. # ssh to termux:
  2185. ssh -p 8022 u0_a499@192.168.43.128 [5Tw@4rEWn3]
  2186. scp -P 8022 file.tar.gz u0_a499@192.168.43.128:~/Tardirectory/
  2187. scp -v -P 8022 file.tar.gz u0_a499@192.168.43.128:~/Tardirectory/
  2188. ssh -p 8022 u0_a275@192.168.29.121 # realme
  2189. # bootable usb
  2190. sudo mkfs -t vfat /dev/sdb1
  2191. sudo umount /dev/sdb1 /media/user/
  2192. sudo dd bs=4M if=/home/saran/file.iso of=/dev/sdb1 status=progress oflag=sync
  2193. # command
  2194. command ls
  2195. command -V ls
  2196. # check which shells are installed
  2197. cat /etc/shells
  2198. # analsys of text speech
  2199. cat speech.txt | tr ' ' '\n' | tr -d '[:punct:]' | tr '[A-Z]' '[a-z]' | sort | \
  2200. uniq -c | sort -nr | less
  2201. # directory usage
  2202. du -sh * | less
  2203. mv `ls | grep -i 'cheat'` /path/to/directory/
  2204. # number of lines in a file
  2205. nl <filename>
  2206. # graphics card [Ref: https://wiki.debian.org/GraphicsCard]
  2207. If your graphic card was manufactured in 2007 and newer, try uninstalling the
  2208. xserver-xorg-video-intel package and use the builtin modesetting driver xserver-xorg-core
  2209. instead. For older devices: xserver-xorg-video-intel
  2210. # change console font type and size
  2211. In Debian, you can use "console-setup" configuration file for "setupcon" which is used to
  2212. configure font and keyboard layout for the console. The standard location of the
  2213. console-setup configuration file is /etc/default/console-setup
  2214. sudo dpkg-reconfigure console-setup
  2215. # factor
  2216. factor 12
  2217. # hostnamectl
  2218. 1. static hostname
  2219. 2. icon name
  2220. 3. chassis
  2221. 4. machine id
  2222. 5. boot id
  2223. 6. operating system
  2224. 7. kernel
  2225. 8. architecture
  2226. # debian version
  2227. cat /etc/debian_version
  2228. # install kernel headers
  2229. apt-get install linux-headers-$(uname -r)
  2230. # getting started with dpkg
  2231. dpkg --get-selections # listing installed software packages
  2232. dpkg --print-avail # display available version details about installed packages
  2233. dpkg-query --list # display software package information in a tabular form
  2234. sudo dpkg --install ~/Downloads/qutebrowser_amd64.deb # installing software packages
  2235. sudo apt install -f # restoring dependencies
  2236. dpkg --audit # to check for broken packages (missing dependencies)
  2237. sudo dpkg-reconfigure virtualbox-6.1 # re-configuring a software package
  2238. sudo dpkg --remove qutebrowser # removing software package
  2239. sudo dpkg --purge qutebrowser # removing software package and its configurations
  2240. sudo dpkg --info ~/Downloads/qutebrowser_amd64.deb # information about a software package
  2241. dpkg --contents ~/Downloads/qutebrowser_amd64.deb # inspecting software package content
  2242. sudo dpkg --status zathura # finding out if a package is installed
  2243. dpkg --help # to learn more about the dpkg command
  2244. man dpkg # for more detailed info about the dpkg command
  2245. # fslint (whereis fslint) [Note: read man fslint]
  2246. /usr/share/fslint/fslint/findup - find duplicate files
  2247. /usr/share/fslint/fslint/findnl - find name lint (problems with filenames)
  2248. /usr/share/fslint/fslint/findu8 - find filenames with invalid utf8 encoding
  2249. /usr/share/fslint/fslint/findbl - find bad links (various problems with symlinks)
  2250. /usr/share/fslint/fslint/findsn - find same name (problems with clashing names)
  2251. /usr/share/fslint/fslint/finded - find empty directories
  2252. /usr/share/fslint/fslint/findid - find files with dead user IDs
  2253. /usr/share/fslint/fslint/findns - find non stripped executables
  2254. /usr/share/fslint/fslint/findrs - find redundant whitespace in files
  2255. /usr/share/fslint/fslint/findtf - find temporary files
  2256. /usr/share/fslint/fslint/findul - find possibly unused libraries
  2257. /usr/share/fslint/fslint/zipdir - reclaim wasted space in ext2 directory entries
  2258. # check disk partitioning scheme in command line (check system uses MBR or GPT partition)
  2259. sudo parted -l # in the output, look for the line starting with Partition Table
  2260. # check if you are using UEFI or BIOS
  2261. ls /sys/firmware/efi # the directory will be missing if system is using BIOS
  2262. sudo apt-get install efibootmgr
  2263. sudo efibootmgr # to check UEFI or BIOS
  2264. # check whether computer is 32-bit or 64-bit
  2265. lscpu # if 64-bit system, it's better (and recommended) to install 64-bit OS
  2266. uname -m
  2267. arch
  2268. # uname
  2269. uname -s # kernel name
  2270. uname -r # kernel release
  2271. uname -v # kernel version
  2272. uname -n # network node name (hostname)
  2273. uname -m # machine architecture
  2274. uname -p # processor architecture
  2275. uname -i # hardware platform (os architecture)
  2276. uname -o # operating system
  2277. # check weather in terminal
  2278. curl wttr.in/chennai
  2279. # display worldmap in terminal
  2280. telnet mapscii.me
  2281. # view package update history
  2282. grep installed /var/log/dpkg.log
  2283. # view the previous install log
  2284. grep installed /var/log/dpkg.log.l
  2285. # view the archived logs
  2286. zgrep installed /var/log/dpkg.log.2.gz
  2287. # view apt history
  2288. /var/log/apt/history.log
  2289. # cd to raman's home directory
  2290. cd ~raman
  2291. # correct and tidy up the markup of HTML, XHTML, and XML files
  2292. tidy file.html
  2293. # print sensor chips information (e.g. temperature)
  2294. sensors
  2295. # perf - performance analysis tools for linux
  2296. sudo apt-get install linux-perf
  2297. sudo sh -c 'echo 1 > /proc/sys/kernel/perf_event_paranoid' # run perf as normal user
  2298. # performance counters of a program using perf
  2299. perf stat -e cycles,instructions,cache-references,cache-misses,branches,branch-misses,\
  2300. task-clock,faults,minor-faults,cs,migrations python program.py
  2301. # using cat to edit a file
  2302. cat > filename # edit a file
  2303. cat >> filename # append to a file
  2304. ctrl + D # save and exist the file
  2305. # display file size
  2306. ls -sh filename
  2307. du -sh filename
  2308. # find the MAC address
  2309. ip addr sh [lint/ether MACID]
  2310. ip link show [link/ether MACID]
  2311. sudo lshw -C network [serial: MACID]
  2312. # network interface [/etc/network/interfaces] [/etc/network/interfaces.d/setup]
  2313. ## The loopback network interface
  2314. auto lo
  2315. iface lo inet loopback
  2316. ## The eno1 network interface
  2317. auto eno1
  2318. allow-hotplug eno1
  2319. iface eno1 inet dhcp
  2320. ## The enp0s20u1 network interface
  2321. auto enp0s20u1
  2322. allow-hotplug enp0s20u1
  2323. iface enp0s20u1 inet dhcp
  2324. ## The enp0s20u2 network interface
  2325. auto enp0s20u2
  2326. allow-hotplug enp0s20u2
  2327. iface enp0s20u2 inet dhcp
  2328. # "no public key available" on apt-get update [Ref: https://keyring.debian.org/]
  2329. Debian Public Key Server
  2330. gpg --keyserver keyring.debian.org --recv-keys <PUBLIC KEY>
  2331. # To run history event number 1, type:
  2332. $ !1
  2333. # find the number of CPU cores
  2334. cat /proc/cpuinfo
  2335. # find the number of physical CPUs
  2336. cat /proc/cpuinfo | grep "^physical id" | sort | uniq | wc -l
  2337. # find the number of cores per CPU
  2338. cat /proc/cpuinfo | grep "^cpu cores" | uniq
  2339. # find the total number of processors
  2340. cat /proc/cpuinfo | grep "^processor" | wc -l
  2341. # to check which program is using a port
  2342. sudo lsof -i:<port_number> -n -P
  2343. # to list all open TCP ports along with their associated process
  2344. sudo lsof -i -n -P | grep TCP
  2345. # enable X11 forwarding using SSH
  2346. X11 forwarding is a mechanism that allows graphical interfaces of X11 programs running on
  2347. a remote server to be displayed on a local client machine.
  2348. ## Server-side preparation:
  2349. sudo apt-get install xauth
  2350. Enable X11 forwarding system-wide:
  2351. sudo vi /etc/ssh/sshd_config
  2352. X11Forwarding yes
  2353. sudo /etc/init.d/sshd restart
  2354. Enable X11 forwarding on a per-user basis:
  2355. vi $HOME/.ssh/config
  2356. ForwardX11 yes
  2357. ## Client-side test
  2358. Unlike a remote server host, a local client machine needs to have X11 system installed.
  2359. ssh -X user@remote_server
  2360. # speed up X11 forwarding in SSH over wide area networks
  2361. use less computation heavy ciphers in SSH, the default 'AES' cipher used by OpenSSH is
  2362. known to be slow. 'arcfour' and 'blowfish' ciphers are faster than 'AES'. 'blowfish' is a
  2363. fast block cipher which is also very secure, 'arcfour' stream cipher is known to be nore
  2364. vulnerable than common block ciphers.
  2365. $ ssh -XC -c blowfish-cbc,arcfour user@remote_server
  2366. ## specify these options in an SSH configuration file
  2367. to edit system-wide SSH configuration file
  2368. $ sudo vi /etc/ssh/ssh_config
  2369. to edit per-user SSH configuration file
  2370. $ vi ~/.ssh/config
  2371. in either SSH configuration file, add the following:
  2372. Host remote_server
  2373. Compression yes
  2374. ForwardX11 yes
  2375. Ciphers blowfish-cbc,arcfour
  2376. then SSH to the remote host without using any command-line options
  2377. $ ssh user@remote_server
  2378. Note that there are some caveats in switching to a different cipher in SSH. The
  2379. performance of a particular cipher may vary across different processor architecture. In
  2380. recent generations of Intel processors come with hardware support for 'AES'.
  2381. # build RPM or DEB package from the source with checkinstall
  2382. installating a linux program from its source by running 'make install', it becomes really
  2383. tricky to remove it completely, unless the author of the program provides an uninstall
  2384. target in the Makefile.
  2385. installing checkinstall in debian
  2386. sudo apt-get install checkinstall
  2387. build an DEB package with checkinstall
  2388. sudo ./configure
  2389. sudo checkinstall
  2390. # check battery status using command line
  2391. cat /sys/class/power_supply/BAT0/capacity # for the battery capacity
  2392. find /sys/class/power_supply/BAT0/ -type f | xargs -tn1 cat # detailed battery info
  2393. Ref: https://www.linuxjournal.com/content/how-check-battery-status-using-linux-command-line
  2394. # scan IP address connected to the network
  2395. sudo nmap -sn <ip address being used locally>
  2396. Example: sudo nmap -sn 192.168.30.0/22
  2397. # nmap commands
  2398. nmap 192.168.1.1
  2399. sudo nmap -O -Pn 192.168.1.1
  2400. nmap -Pn -p 22,24 192.168.1.1
  2401. nmap -F 192.168.1.1
  2402. nmap -Pn --open 192.168.1.1
  2403. # display file system type
  2404. df -Th
  2405. sudo fsck -N /dev/sda1
  2406. lsblk -f
  2407. sudo file -sL /dev/sda1
  2408. # df commands to check disk space
  2409. df # check file system disk space usage
  2410. df -a # display information of all file system disk space usage
  2411. df -h # show disk space usage in human readable format
  2412. df -hT /home # display information of /home file system
  2413. df -k # display information of file system in bytes
  2414. df -m # display information of file system in MB
  2415. df -h # display information of file system in GB
  2416. df -i # display file system inodes
  2417. df -T # display file system type
  2418. df -t ext3 # include certain file system type
  2419. df -x ext3 # exclude certain file system type
  2420. df --help # display information of df command
  2421. # system and hardware info
  2422. uname # system name
  2423. uname -s # kernel name
  2424. uname -n # network hostname
  2425. uname -v # kernel version
  2426. uname -r # kernel release
  2427. uname -m # machine hardware name
  2428. uname -a # all the above info
  2429. sudo lshw # print information about Linux system hardware
  2430. sudo lshw -short # print a summary of hardware information
  2431. sudo lshw -html > lshw.html # generate output as html file
  2432. lscpu # information about CPU
  2433. lsblk # information about block devices
  2434. lsblk -a # view all block devices on system
  2435. lsusb # information about USB controllers and all devices connected
  2436. lsusb -v # generate detailed information about each USB device
  2437. lspci # print information about PCI devices
  2438. lspci -t # produce output in tree format
  2439. lspci -v # produce detailed information about each connected device
  2440. lsscsi # print SCSI devices information
  2441. lsscsi -s # show device sizes
  2442. sudo hdparm /dev/sda1 # information about sata devices on system
  2443. sudo hdparm -g /dev/sda1 # information about device geometry
  2444. sudo fdisk -l # information file system partitions
  2445. sudo dmidecode -t memory # print information about memory
  2446. sudo dmidecode -t system # print information about system
  2447. sudo dmidecode -t bios # print information about bios
  2448. sudo dmidecode -t processor # print information about processor
  2449. # print how many seconds the current shell has been running
  2450. echo $SECONDS
  2451. units '1624 seconds' 'minutes'
  2452. # outputing a random number
  2453. echo $RANDOM
  2454. yes `echo $RANDOM`
  2455. # controlling processes
  2456. ps # list of the processes running on system
  2457. ps -aux # list all running processes
  2458. ps -a # list all processors from all users
  2459. ps -u # list more information including user names, %cpu usage, and %mem usage etc
  2460. ps -x # list processes without controlling terminals
  2461. ps -l # display information including UID and nice value
  2462. ps --forest # to see the process hierarchy
  2463. pstree # displays the processes in the form of a tree structure
  2464. pgrep <process_name> # finding the process id of a particular process
  2465. pgrep -u <user_name> -l <process_name> # find the process id of particular process by user
  2466. # command to find function meanings
  2467. declare
  2468. # network manager
  2469. sudo apt-get install network-manager
  2470. sudo systemctl restart network-manager
  2471. # make unmanaged network interface to connected with nmcli
  2472. [check first if the ip address is displayed then follow the steps below]
  2473. nmcli dev status # if [device] eno1 [type] ethernet [state] unmanaged
  2474. sudo vi /etc/NetworkManager/NetworkManager.conf
  2475. [ifupdown]
  2476. managed=true # change managed=false to managed=true
  2477. sudo systemctl restart network-manager # restart the network manager
  2478. nmcli dev status # check the interface status
  2479. ping -c 3 startpage.com # check if able to ping
  2480. # exit an unresponsive ssh session without closing the terminal
  2481. press [Enter] ----> press [~] ----> press [.]
  2482. # recursively lists package dependencies
  2483. apt-rdepends <package_name>
  2484. # check installed architectures
  2485. # verify 64-bit architecture
  2486. dpkg --print-architecture # should respond with "amd64"
  2487. # verify if 32-bit architecture is already installed
  2488. dpkg --print-foreign-architectures # should respond with "i386"
  2489. # if it does not display "i386"
  2490. sudo dpkg --add-architecture i386
  2491. # re-check
  2492. dpkg --print-foreign-architectures
  2493. # convert-im6.q16: attempt to perform an operation not allowed by the security policy
  2494. Error message:
  2495. convert-im6.q16: attempt to perform an operation not allowed by the security policy
  2496. `PDF' @ error/constitute.c/IsCoderAuthorized/426.
  2497. ImageMagick disables many ghostscript format types.
  2498. This can be seen in the file: /etc/ImageMagick-6/policy.xml
  2499. <!-- disable ghostscript format types -->
  2500. <policy domain="coder" rights="none" pattern="PS" />
  2501. <policy domain="coder" rights="none" pattern="PS2" />
  2502. <policy domain="coder" rights="none" pattern="PS3" />
  2503. <policy domain="coder" rights="none" pattern="EPS" />
  2504. <policy domain="coder" rights="none" pattern="PDF" />
  2505. <policy domain="coder" rights="none" pattern="XPS" />
  2506. Modify this to allow: rights="read|write"
  2507. # transform a text file into an image
  2508. convert -size 360x360 xc:white -font "FreeMono" -pointsize 12 -fill black
  2509. -draw @file.txt image.png
  2510. convert -size 360x360 xc:white -font "FreeMono" -pointsize 12 -fill black
  2511. -annotate +15+15 @file.txt image.png
  2512. convert -size 1000x2000 xc:white -font "FreeMono" -pointsize 12 -fill black
  2513. -annotate +15+15 @file.txt -trim -bordercolor "#FFF" -border 10 +repage img.png
  2514. convert -list font # display all of the possible arguments to -font
  2515. Reference:
  2516. https://unix.stackexchange.com/questions/138804/how-to-transform-a-text-file-
  2517. into-a-picture
  2518. # manually installing Xorg (https://adercon.com/posts/manually-installing-xorg)
  2519. Xorg install with a simple 'apt-get install xorg' pulls in all drivers - most
  2520. of which not need and install Xorg in a minimalistic approach.
  2521. First need to find the video card (and driver) for the video card:
  2522. * find video card: lspci | grep -i 'vga'
  2523. The result of the above command should be something similar to the following:
  2524. 00:02.0 VGA compatible controller: Intel Corporation 3rd Gen Core processor
  2525. Graphics Controller (rev 09)
  2526. In the above output, "00:02.0" is the device id.
  2527. * get card details: lspci -v -s DEVICE-ID
  2528. The above command should return something similar to the following:
  2529. 00:02.0 VGA compatible controller: Intel Corporation 3rd Gen Core processor
  2530. Graphics Controller (rev 09) (prog-if 00 [VGA controller])
  2531. Subsystem: Hewlett-Packard Company 3rd Gen Core processor Graphics Controller
  2532. Flags: bus master, fast devsel, latency 0, IRQ 29
  2533. Memory at c3000000 (64-bit, non-prefetchable) [size=4M]
  2534. Memory at b0000000 (64-bit, prefetchable) [size=256M]
  2535. I/O ports at 5000 [size=64]
  2536. [virtual] Expansion ROM at 000c0000 [disabled] [size=128K]
  2537. Capabilities: <access denied>
  2538. Kernel driver in use: i915
  2539. Kernel modules: i915
  2540. * you want to note the vendor ("Intel Corporation")
  2541. and the kernel driver ("1915")
  2542. * now install Xorg with the following:
  2543. apt-get install xserver-xorg-core xserver-xorg-input-all
  2544. xserver-xorg-video-fbdev xserver-xorg-video-(yourcard:
  2545. can be intel, nouveau, or ati)
  2546. # remove all Xorg
  2547. The following code will remove xorg, display managers, etc. and leave you
  2548. with a more clean/trim server:
  2549. apt-get remove --purge xorg*
  2550. apt-get remove --purge nautilus*
  2551. apt-get remove --purge desktop-base
  2552. apt-get remove --purge python-gnome*
  2553. apt-get remove --purge gdm3
  2554. apt-get remove --purge x11-*
  2555. apt-get remove --purge gnome-*
  2556. apt-get autoremove --purge
  2557. # cleanup unused package configs
  2558. # (https://adercon.com/posts/cleanup-unused-package-configs/)
  2559. apt-get purge `dpkg --get-selections | grep deinstall | cut -f1`
  2560. # Possible missing firmware /lib/firmware/rtl_nic/rtl8105e-1.fw of module r8169
  2561. sudo apt-get install firmware-realtek
  2562. Ref:
  2563. https://unix.stackexchange.com/questions/682990/linux-upgrade-debian-possible-
  2564. missing-firmware-problem
  2565. # for info on Graphics
  2566. inxi -G
  2567. # convert epub to pdf
  2568. https://ebook.online-convert.com/convert-to-pdf
  2569. Base font size: 10
  2570. Embed font: Serif
  2571. Change input encoding: Automatic detection
  2572. Enable ASCII output
  2573. Enable heuristics
  2574. Target ebook reader: Default
  2575. Add border: 0-20 cm
  2576. # patching st terminal
  2577. $ git clone https://git.suckless.org/st
  2578. $ mv st/ .st/
  2579. $ cd .st/
  2580. $ wget https://st.suckless.org/patches/anysize/st-expected-anysize-0.9.diff
  2581. $ patch -Np1 -i st-expected-anysize-0.9.diff (in directory ~/.st/)
  2582. $ doas make clean install [Note: edit config.h before make clean install]
  2583. # tmux not sourcing my .tmux.conf
  2584. Binding keys in tmux: https://www.seanh.cc/2020/12/28/binding-keys-in-tmux/
  2585. tmux ls
  2586. tmux kill-server
  2587. Ref:
  2588. https://unix.stackexchange.com/questions/66606/tmux-not-sourcing-my-tmux-conf/
  2589. # mod + ctrl + (workspace)
  2590. # top command options
  2591. top # to launch top
  2592. press the z key # to change the color of the output
  2593. press the 1 key # to see a graphical representation of each CPU core
  2594. press the m key # display memory usage graphically
  2595. top -u 'username' # display processes started by a specific user
  2596. top -i # list of idle processes on your system
  2597. top -d 5 # update interval to an arbitrary value in seconds
  2598. top -n 2 # number of iterations to two and then exits
  2599. Press 'shift + L' to locate a process by name. This creates a prompt just above
  2600. the bold table header line. Type in the name of the process you're looking for
  2601. and then press 'Enter' to see the instances of that process highlighted in the
  2602. newly sorted process list.
  2603. Stop or 'kill' a running process. Find the process you want to stop using
  2604. 'shift + L'. Next, press K and enter the process ID you want to stop.
  2605. Ref: https://opensource.com/article/22/3/linux-top-command
  2606. # change font type and size in st terminal
  2607. st -f "Inconsolata:style=Regular:size=14"
  2608. # compare two files
  2609. cmp file1.txt file2.txt # if file1.txt == file2.txt then no output printed
  2610. # display the differences between two files
  2611. diff file1.txt file2.txt # if file1.txt == file2.txt then no output printed
  2612. # croping pdf file
  2613. pdfcrop --margins '-100 -15 -100 -490' input.pdf output.pdf
  2614. # google sign-in issues
  2615. for versions between v1.10.0 (inclusive) and v2.3.1 (exclusive), run
  2616. :set -u https://accounts.google.com/* content.headers.user_agent
  2617. "Mozilla/5.0 ({0s_info}; rv:90.0) Gecko/20100101 Firefox/90.0" for versions
  2618. between v1.2.0 (inclusive) and v1.10.0 (exclusive), use X11; Linux x86_64 in
  2619. place of {os_info}.
  2620. # config in qutebrowser
  2621. :set zoom.default 70
  2622. :set url.start_pages "https://startpage.com/{}"
  2623. ~/.config/qutebrowser/config.py
  2624. config.load_autoconfig()
  2625. c.url.start_pages = ["https://startpage.com/{}"]
  2626. c.url.searchengines = {
  2627. "DEFAULT": "https://startpage.com/{}"
  2628. }
  2629. # install liberation mono (https://wiki.debian.org/Fonts)
  2630. sudo apt-get install fonts-liberation/fonts-liberation2
  2631. # ssh
  2632. sudo apt-get update
  2633. sudo apt-get install openssh-server
  2634. sudo systemctl status ssh
  2635. sudo systemctl start ssh # in case not started, start ssh service
  2636. sudo systemctl enable ssh # to enable the ssh service on system boot
  2637. ssh saravanan@10.21.106.28 # login the remote machine
  2638. # scp
  2639. scp file.txt saravanan@10.21.106.28:~/Documents/ # copy local file to remote
  2640. scp saravanan@10.21.106.28:~/Documents/file.txt /home/saran/ # remote to local
  2641. # find number of CPU cores
  2642. nproc command shows the number of processing units available
  2643. $ nproc
  2644. lscpu gathers CPU architecture information from /proc/cpuinfo in human-readable
  2645. $ lscpu
  2646. /proc/cpuinfo and sysfs stores info about CPU architecture like number of CPUs,
  2647. threads, cores, sockets, NUMA nodes, information about CPU caches, CPU family
  2648. less /proc/cpuinfo
  2649. # youtube-dl
  2650. xclip -o -selection clipboard > url.txt
  2651. youtube-dl -F $(< url.txt)
  2652. youtube-dl -f bestaudio+bestvideo $(< url.txt)
  2653. # list of sound cards
  2654. $ cat /proc/asound/cards
  2655. $ lspci | grep -i audio
  2656. $ aplay --list-devices
  2657. # setting the default device sound card
  2658. Find your desired card with:
  2659. $ cat /proc/asound/cards
  2660. and then create /etc/asound.conf with following:
  2661. defaults.pcm.card 1
  2662. defaults.ctl.card 1
  2663. Note: Replace "1" with number of your card determined above.
  2664. Ref: https://www.alsa-project.org/wiki/Setting_the_default_device
  2665. -----------------------------
  2666. SOFTWARE | Applications |
  2667. -----------------------------
  2668. |
  2669. -----------------------------
  2670. | PipeWire | JACK |
  2671. SYSTEM SOFTWARE -----------------------------
  2672. SOUND SERVERS | PulseAudio |
  2673. -----------------------------
  2674. |
  2675. -----------------------------
  2676. | Advanced Linux |
  2677. KERNEL, DRIVERS | Sound Architecture |
  2678. | (ALSA) |
  2679. -----------------------------
  2680. |
  2681. -----------------------------
  2682. | Equalizer | Sound board |
  2683. -----------------------------
  2684. HARDWARE | Mixer | Sound card |
  2685. -----------------------------
  2686. | ... |
  2687. -----------------------------
  2688. # enable sound in debian linux
  2689. $ doas apt-get install alsa-utils
  2690. $ alsamixer
  2691. press F6 to select sound card [HDA Intel PCH]
  2692. Ref: https://vitux.com/how-to-control-audio-on-the-debian-command-line/
  2693. # using amixer to control audio properties through commands
  2694. $ amixer --help
  2695. $ amixer -c [card-number] set [control] [value] # amixer command example
  2696. $ amixer scontrols # view the list of controls
  2697. $ amixer -c 0 set Master 100% # set the volume on the Master of 1st sound card to 100%
  2698. $ amixer -c 1 set Speaker 50% # set the volume on the Speaker of 2nd sound card to 50%
  2699. $ amixer -c 1 set Speaker 3db # set the volume on the Speaker of 2nd sound card to 3db
  2700. $ amixer -c 1 set Speaker 2db+ # increase the volume on the Speaker of 2nd card by 2db
  2701. $ amixer -c 0 set Mic mute # mute the Mic of 1st sound card
  2702. $ amixer -c 0 set Mic unmute # unmute the Mic of 1st sound card
  2703. # pipewire
  2704. $ doas apt-get install pipewire-audio
  2705. # change cursor theme
  2706. /usr/share/icons/default/index.theme
  2707. /usr/share/icons/Adwaita/cursor.theme
  2708. # git commands
  2709. git config
  2710. git config --global init.defaultBranch master
  2711. # remove welcome screen text in termux
  2712. Open termux app and type:
  2713. cd ../usr/etc/
  2714. rm motd
  2715. # Fonts
  2716. # Console /usr/share/consolefonts/Lat15-Fixed16.psf.gz
  2717. Encoding to use on the console: UTF-8
  2718. Please choose the character set that should be supported by the console font:
  2719. Latin1 and Latin5 - western Europe and Turkic languages
  2720. Font for the console: Fixed
  2721. Font size: 8x16
  2722. # St terminal
  2723. apt-get install fonts-unifont
  2724. st -f "Unifont:pixelsize=16:antialias=true:autohint=true"
  2725. # set console fonts
  2726. setfont /usr/share/consolefonts/Lat15-Fixed16.psf.gz
  2727. # commandline system information
  2728. inxi --recommends # after installation check dependencies & directories
  2729. inxi # show linux system information
  2730. inxi -S # show linux kernel and distribution info
  2731. inxi -M # show linux machine information
  2732. inxi -C # show CPU and CPU speed information
  2733. inxi -G # show graphic card information
  2734. inxi -A # show audio/sound card information
  2735. inxi -N # show network card information
  2736. inxi -D # show hard disk information
  2737. inxi -b # summarize full system information
  2738. inxi -p # show hard disk partition details
  2739. inxi -F # show full system information
  2740. inxi -I # monitor linux processes memory usage
  2741. inxi -t c # monitoring processes by CPU usage
  2742. inxi -t m # monitoring processes by memory usage
  2743. inxi -t cm # monitoring processes by CPU and memory usage
  2744. inxi -t cm10 # monitoring top 10 most active processes eating CPU and memory
  2745. inxi -Nni # monitor linux network interfaces
  2746. inxi -s # monitor linux CPU temperature and fan speed
  2747. inxi -w # show weather report (inxi -W Tokyo,Japan)
  2748. inxi -r # show all linux repository information
  2749. inxi -B # show battery information
  2750. inxi -V # show inxi version
  2751. inxi -h # show inxi help
  2752. # get the GPU information
  2753. sudo lshw -C display # shows product, vendor, physical id, bus info, clock
  2754. glxinfo # OpenGL information for the graphics processor
  2755. nvidia-smi # show information for nvidia gpu
  2756. lspci | grep -i 'nvidia'# device id of VGA compatible controller & audio device
  2757. cat /proc/driver/nvidia/gpus/<device id>/information # gpu model and uuid
  2758. nvidia-smi -q # display more detailed gpu information
  2759. nvidia-smi --list-gpus # list names of the video cards on the machine
  2760. gpustat -cp # gpu memory information
  2761. # installing custom fonts
  2762. * create a folder .fonts in $HOME directory
  2763. * download fonts of choice (ttf or odf format to ~/.fonts)
  2764. * refresh the fonts cache with fc-cache -fv
  2765. * verify if fonts got added to the cache using fc-list
  2766. example: fc-list -f "%{family}\n" | sort -u | grep -i 'inconsolata'
  2767. # system reboot with users logedin
  2768. systemctl reboot -i
  2769. # finding nvidia cuda version
  2770. nvcc --version # nvidia cuda compiler
  2771. nvidia-smi # to check CUDA version
  2772. cat /usr/lib/cuda/version.txt (find /usr -type d -name cuda; whereis cuda)
  2773. cat "$(dpkg -L nvidia-cuda-toolkit | grep 'version.txt')"
  2774. apt info nvidia-cuda-toolkit
  2775. # check nvidia driver supports kernel version
  2776. uname -r
  2777. dkms status
  2778. apt-cache policy nvidia-driver-470
  2779. # nvidia driver is not loaded
  2780. sudo prime-select nvidia
  2781. sudo reboot
  2782. # soft link creation for nvcc
  2783. sudo ln -s /usr/local/cuda-11.4/bin/nvcc /usr/bin/nvcc
  2784. # issue: # updates could not be installed automatically.
  2785. For more details, see /var/log/unattended-upgrades/unattended-upgrades.log
  2786. Find the pin in /etc/apt/preferences.d: ls /etc/apt/preferences.d
  2787. We can obtain the packages that have been kept back:
  2788. /var/lib/unattended-upgrades/kept-back
  2789. solution 1: sudo apt-get --with-new-pkgs upgrade
  2790. solution 2: sudo apt-get install nvidia-driver-470
  2791. solution 3: sudo apt-get dist-upgrade
  2792. solution 4: sudo apt purge cuda*
  2793. sudo rm /etc/apt/preferences.d/cuda-repository-pin-600
  2794. sudo apt autoremove
  2795. sudo apt autoclean
  2796. using apt-get install <pkg> instead will mark <pkg> as 'manually installed !'
  2797. to mark it again as 'automatically installed' use apt-mark auto <pkg>
  2798. Ref: https://askubuntu.com/questions/601/the-following-packages-have-been-kept-
  2799. back-why-and-how-do-i-solve-it
  2800. https://askubuntu.com/questions/1344136/unattended-upgrades-could-not-be-
  2801. installed-automatically
  2802. profiling python program
  2803. # Failed to connect to https://changelogs.ubuntu.com/meta-release-lts.
  2804. # Check your Internet connection or proxy settings.
  2805. sudo truncate -s 0 /var/lib/ubuntu-release-upgrader/release-upgrade-available
  2806. # aptitude safe-upgrade instead of apt-get dist-upgrade
  2807. sudo aptitude safe-upgrade
  2808. # fonts selection
  2809. fc-match sans-serif
  2810. fc-match serif
  2811. fc-match monospace
  2812. # convert pdf to jpg
  2813. pdftoppm -jpeg -r 300 file.pdf output
  2814. # darkweb definition (Ref: page: 6, Weaving the Dark Web)
  2815. Although Freenet, Tor and I2P implement anonymous web technologies in very
  2816. different ways, they all provide readers and publishers with anonymity by
  2817. allowing them to browse and publish anonymous websites. Here, the connotation
  2818. of "darkness" in Dark Web has more to do with encryption, annonymization, and
  2819. leaving standard communications channels (as in the phrase used by James Comey,
  2820. "going dark", meaning avoiding overly public communications channels). "Web"
  2821. refers, of course, to websites, web browsers, HTML, and CSS.
  2822. If anything, the Dark Web functions much like the regular web - with the key
  2823. exception that one needs special routing software to access it, software that
  2824. can protect the identity of site readers and publishers. It is not deeper than
  2825. the regular web in any logical sense.
  2826. # xterm
  2827. xterm -bg black -fg white -fa 'Iosevka' -fs 10
  2828. # bash shell tricks
  2829. Ctrl + x and Ctrl + V # find the version of the bash shell
  2830. type $ and press tab key twice # system environment variables
  2831. type ~ and press tab key twice # show all user from /etc/passwd file
  2832. s=$((5*5)) then type echo $s # arithmetic operation in bash shell
  2833. PS1="$ " # change the bash shell prompt by assigning PS1 variable
  2834. env | less # show the environment
  2835. set | less # display the names and values of shell variables
  2836. # paste in st terminal
  2837. Ctrl + Shift + V
  2838. # removing password from pdf file
  2839. gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputfile=unencrypted.pdf -c
  2840. .setpdfwrite -f encrypted.pdf
  2841. # regex
  2842. $ cd nmsc
  2843. $ find . -regex ".*leg\.py"
  2844. ./scripts/python/gaussquad/gaussleg.py
  2845. ./Endsem/Scripts/gaussleg.py
  2846. This search tells find to start from the current directory (the ".") and find
  2847. all files that have zero or more characters (the ".*") before the string "leg",
  2848. which comes before the "." (which must be escaped because "." normally means
  2849. "any single character"), followed by the file extension of python.
  2850. # list namespaces
  2851. $ sudo lsns
  2852. # build html file from rst file
  2853. $ rst2html5.py --link-stylesheet --cloak-email-addresses --toc-top-backlinks
  2854. --stylesheet=book.css --stylesheet-dirs=. book.rst
  2855. # grammer-check a text file
  2856. $ diction textfile.txt | less
  2857. # grammer checking using gramma (install with nodejs npm)
  2858. # check file
  2859. gramma check [file] # interactive fix
  2860. gramma check -p [file] # just print potential mistakes and return status code
  2861. # check string
  2862. gramma listen [text] # interactive fix
  2863. gramma listen -p [text] # just print potential mistakes and return status code
  2864. # apt-cache search lisp scheme
  2865. scm - Scheme language interpreter
  2866. sloccount - programs for counting physical source lines of code (SLOC)
  2867. src2tex - converter from source program files to TeX format files
  2868. texify - Beautify source code for use with LaTeX
  2869. # set the date for 02:07:30 PM on August 19 without changing the year
  2870. $ sudo date 08191407.30
  2871. # find difference between two directories using diff
  2872. To know what files/subdirectories are common in the two directories, those that
  2873. are present in one directory but not in the other. The conventional syntax for
  2874. running diff is as follows:
  2875. $ diff directory1/ directory2/
  2876. By default, its output is ordered alphabetically by files/subdirectory name. In
  2877. this command, the -q switch tells diff to report only when files differ.
  2878. $ diff -q directory1/ directory2/
  2879. Again diff doesn't go into the subdirectories, but we can use the -r switch to
  2880. read the subdirectories as well.
  2881. $ diff -qr directory1/ directory2/
  2882. # numactl
  2883. $ numactl --hardware
  2884. $ numactl --show
  2885. # linux malware incident response tools
  2886. netcat - arbitrary TCP and UDP connections and listens
  2887. cryptcat - twofish encryption enabled version of nc
  2888. memdump - memory dumper
  2889. dc3dd - convert and copy a file
  2890. linuxinfo - displays system information about system
  2891. logname - print user's login name
  2892. printenv - print all or part of environment
  2893. acct - switch process accounting on or off
  2894. fuser - identify processes using files or sockets
  2895. route - route traffic control filter
  2896. procinfo - tools to display information from /proc and /sys
  2897. pslist - utility that controls a process and its descendants
  2898. ss - another utility to investigate sockets
  2899. users - print the user names of users currently logged in to the current host
  2900. w - show who is logged on and what they are doing
  2901. w --ip-addr - display IP address instead of hostname for from field
  2902. w <username> - show information about the specified user only
  2903. moreutils - additional unix utilities (ifdata, ifne, isutf8, lckdo, parallel)
  2904. # remove logo with the ffmpeg delogo
  2905. ffplay input.mp4 -vf "delogo=x=1400:y=20:w=500:h=480:show=1"
  2906. # combine/concat multiple audio tracks into single audio
  2907. ffmpeg -f concat -safe 0 -1 list.txt audio.mp3
  2908. list.txt contains paths to all segments:
  2909. file audiofile1.mp3
  2910. file audiofile2.mp3
  2911. file audiofile3.mp3
  2912. # combine one image + one audio file to make one video using ffmpeg
  2913. ffmpeg -r 1 -loop 1 -i image.jpg -i audio.mp3 -acodec copy -r 1 -shortest -vf
  2914. scale=1280:720 video.mp4
  2915. # combine/concat multiple video files into single video
  2916. ffmpeg -f concat -i list.txt video.mp4
  2917. list.txt contains paths to all segments:
  2918. file videofile1.mp4
  2919. file videofile2.mp4
  2920. file videofile3.mp4
  2921. # 32 bits or 64 bits
  2922. $ getconf LONG_BIT
  2923. # list all bash shortcuts
  2924. $ bind -P
  2925. # quick access to ASCII code of a key
  2926. $ showkey --ascii # display the decimal/octal/hex values of the keys
  2927. # simulate typing
  2928. echo "You can simulate on-screen typing just like in the movies" | pv -qL 10
  2929. # set audible alarm when an IP address comes online
  2930. ping -i 60 -a IP_address
  2931. # base conversions with bc
  2932. $ echo "obase=2; 27" | bc -l
  2933. # identify long lines in a file
  2934. $ awk 'length>80' file.txt
  2935. # find if the command has an alias
  2936. $ type -all <command> | grep aliased
  2937. # dictionaries with dict command (http://www.dict.org/)
  2938. Install dict on Linux:
  2939. $ sudo apt-get install dictd dict-gcide
  2940. No additional configuration is required. The minimalistic
  2941. /usr/share/doc/dictd/dict1.conf file specifies the remote server for the
  2942. dictionary databases. This tool uses the Dictionary Server Protocol (DCT) on
  2943. port 2628.
  2944. In a terminal session as a non-root user, type dict <word> to get a list of
  2945. definitions from one or more dictionaries and the thesaurus.
  2946. $ dict <word> | less
  2947. You can also look up multi-word phrases by enclosing them in quotes, either
  2948. double or single.
  2949. $ dict 'air gapped'
  2950. The dict command uses several online dictionaries, including legal & technical
  2951. ones. Dictionaries are also available for many languages. You can list the
  2952. available dictionary databases as shown here:
  2953. $ dict -D | less
  2954. You can specify individual dictionaries with the -d option:
  2955. $ dict -d gcide
  2956. # sharing linux terminals with tmux
  2957. [https://www.admin-magazine.com/HPC/Articles/Sharing-Linux-Terminals]
  2958. $ tmux new -s remote
  2959. tmux new, starts a new session, with the name of the session, remote, placed
  2960. after the -s flag.
  2961. # yt-dlp
  2962. Download the latest version of yt-dlp from GitHub repository:
  2963. with curl:
  2964. $ doas curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
  2965. -o /usr/local/bin/yt-dlp
  2966. with wget:
  2967. $ doas wget -qO /usr/local/bin/yt-dlp
  2968. https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
  2969. $ doas chmod a+rx /usr/local/bin/yt-dlp
  2970. $ yt-dlp --help
  2971. $ yt-dlp --version
  2972. $ doas yt-dlp --update
  2973. $ yt-dlp --list-formats "$(< url.txt)"
  2974. $ yt-dlp -f 'bv*+ba/b' "$(< url.txt)"
  2975. $ doas rm -rf /usr/local/bin/yt-dlp # uninstall yt-dlp
  2976. Reference: https://linuxconfig.org/yt-dlp-vs-youtube-dl
  2977. # yt-dlp commands
  2978. 1. To keep the program up to date, use the -U option
  2979. $ yt-dlp -U
  2980. 2. View the available formats and resolutions of a video with the --list-formats
  2981. option
  2982. $ yt-dlp --list-formats <url>
  2983. 3. Download the highest quality video stream and the highest quality audio
  2984. stream for a video, and combine them into a single file
  2985. $ yt-dlp -f 'bv*+ba' <url>
  2986. 4. Download 1080p video quality and combine it with the best possible audio
  2987. stream
  2988. $ yt-dlp -f 'bv*[height=1080]+ba' <url>
  2989. 5. Save only the audio stream (best quality possible) and put into an mp3 file
  2990. $ yt-dlp -f 'ba' -x --audio-format mp3 <url>
  2991. 6. Playlist video to start at (default is 1)
  2992. $ yt-dlp --playlist-start NUMBER <url>
  2993. 7. Playlist video to end at (default is last)
  2994. $ yt-dlp --playlist-end NUMBER <url>
  2995. 8. Playlist video items to download
  2996. $ yt-dlp --playlist-items 1-3,7,10-13 <url> [index: 1, 2, 3, 7, 10, 11, 12, 13]
  2997. # report the number of hyperthreads
  2998. grep processor /proc/cpuinfo
  2999. grep -c processor /proc/cpuinfo
  3000. # find exact linux installation date and time
  3001. 1. using stat command (stat command is part of GNU coreutils package)
  3002. $ stat / | grep 'Birth' | sed 's/Birth: //g' | cut -b 2-11
  3003. $ stat / | awk '/Birth: /{print $2}'
  3004. $ stat -c %w /
  3005. 2. analyze pacman logs on arch linux
  3006. $ head -n1 /var/log/pacman.log
  3007. 3. check syslog entries on debian-based systems
  3008. $ sudo head -n1 /var/log/installer/syslog
  3009. # physical cpu cores vs logical cpu cores
  3010. (https://unix.stackexchange.com/questions/88283/
  3011. so-what-are-logical-cpu-cores-as-opposed-to-physical-cpu-cores)
  3012. $ lscpu
  3013. Architecture: i686
  3014. CPU op-mode(s): 32-bit, 64-bit
  3015. Byte Order: Little Endian
  3016. Address sizes: 36 bits physical, 48 bits virtual
  3017. CPU(s): 2
  3018. On-line CPU(s) list: 0,1
  3019. Thread(s) per core: 1
  3020. Core(s) per socket: 2
  3021. Socket(s): 1
  3022. Vendor ID: GenuineIntel
  3023. CPU family: 6
  3024. Model: 42
  3025. Model name: Intel(R) Pentium(R) CPU B950 @ 2.10GHz
  3026. Stepping: 7
  3027. CPU MHz: 798.120
  3028. CPU max MHz: 2100.0000
  3029. CPU min MHz: 800.0000
  3030. BogoMIPS: 4190.20
  3031. L1d cache: 64 KiB
  3032. L1i cache: 64 KiB
  3033. L2 cache: 512 KiB
  3034. L3 cache: 2 MiB
  3035. * In the above Intel(R) Pentium(R) laptop has 2 "CPUs" in total.
  3036. CPU(s): 2
  3037. * Of which there are 2 physical cores (1 socket x 2 cores/socket = 2 cores)
  3038. Core(s) per socket: 2
  3039. Socket(s): 1
  3040. * Of which each can run upto 1 threads
  3041. Thread(s) per core: 1
  3042. at the same time. These threads are the core's logical capabilities.
  3043. $ sudo dmidecode | egrep "Socket Designation: Proc|((Thread|Core) Count)"
  3044. Socket Designation: Proc 1
  3045. Core Count: 14
  3046. Thread Count: 28
  3047. Socket Designation: Proc 2
  3048. Core Count: 14
  3049. Thread Count: 28
  3050. * Two sockets.
  3051. * Each socket has 14 physical cores.
  3052. * Each core has two threads (28/14).
  3053. * Total number of logical "cpus" or logical processing units is 56.
  3054. (that's what top and some other commands would show you as number of "cpus")
  3055. # show applications using the internet
  3056. $ lsof -i | awk '{print $1}' | uniq | tail -n +2
  3057. * lsof -i shows us a lot of information pertaining to
  3058. processes accessing the Internet
  3059. * awk '{print $1}' filters the last output to only shown
  3060. us the COMMAND column
  3061. * uniq filters out multiple occurrences of a single application
  3062. * tail -n +2 removes the first COMMAND line
  3063. # concatenating pdf files in linux
  3064. To convert an image to a pdf we can use imagemagick:
  3065. $ convert -quality 100 image.pdf scanned.pdf
  3066. To combine or concatenate multiple pdf files, we can use ghostscript:
  3067. $ gs -sDEVICE=pdfwrite \
  3068. -sOUTPUTFILE=output.pdf \
  3069. -dNOPAUSE \
  3070. -dBATCH \
  3071. input0.pdf input1.pdf input2.pdf
  3072. Flag Description
  3073. -sDEVICE Device used for processing the output file type. Use
  3074. pdfwrite to write to a pdf file.
  3075. -sOUTPUTFILE Path to save the resulting file output.
  3076. -dNOPAUSE Disables the prompting and pausing at the end of each page.
  3077. -dBATCH Finishes interpreting after processing the inputted files.
  3078. Alternatively you can use pdftk:
  3079. $ pdftk input0.pdf input1.pdf input2.pdf \
  3080. cat output output.pdf
  3081. Lastly, you can also use imagemagick. Do note, however, that this program
  3082. often leads to larger file sizes.
  3083. $ convert input0.pdf input1.pdf input2.pdf output.pdf
  3084. One issue is that if the pages were of different sizes. This is often because
  3085. the pages can be of different pixel densities.
  3086. To check run pdfimages and look at the 3rd to last and 2nd to last columns:
  3087. $ pdfimages -list filename.pdf
  3088. We can then use imagemagick to enforce a certain pixel density. The tradeoff
  3089. being that the file size might increase.
  3090. $ convert -density 300 input.pdf output.pdf
  3091. # brief cheat sheat with curl
  3092. $ curl cheat.sh/<command>
  3093. # change and print terminal line settings
  3094. $ stty --all # print all current settings in human-readable form
  3095. $ stty --save # print all current settings in a stty-readable form
  3096. $ stty --file=DEVICE # open and use the specified DEVICE instead of stdin
  3097. $ stty --help # display this help and exit
  3098. $ stty --version # output version information and exit
  3099. # use plaintext gmail
  3100. 1. Compose a new message
  3101. 2. On the bottom right, click the three-dotted icon
  3102. 3. Select the plaintext option
  3103. Gmail will remember your preference next time.
  3104. Gmail wraps plain text messages at 78 characters.
  3105. # how to add swap space on debian 11
  3106. Swap is a portion of hard drive storage that has been set aside for the
  3107. operating system to temporarily store data that it can no longer hold in RAM.
  3108. checking the system for swap information:
  3109. $ sudo swapon --show # if the system has any configured swap
  3110. If you don't get back any output, this means your system does not have swap
  3111. space available currently.
  3112. $ free -h # verify that there is no active swap using the free utility
  3113. checking available space on the hard drive partition:
  3114. $ df -h # check current disk usage to make sure we have enough space
  3115. The device with / in the 'Mounted on' column is our disk in this case.
  3116. creating a swap file:
  3117. We will allocate a file of the size that we want called swapfile in our root
  3118. directory.
  3119. $ sudo fallocate -l 4G /swapfile # creating a swap file with the fallocate
  3120. $ ls -lh /swapfile # verify that the correct amount of space was reserved
  3121. enabling the swap file:
  3122. $ sudo chmod 600 /swapfile # make the file only accessible to root
  3123. $ ls -lh /swapfile # verify the permissions change
  3124. $ sudo mkswap /swapfile # mark the file as swap space
  3125. $ sudo swapon /swapfile # enable the swap file, allowing our system to use
  3126. $ sudo swapon --show # verify that the swap is available
  3127. $ free -h # check the output of the free utility again to corroborate
  3128. making the swap file permanent:
  3129. $ sudo cp /etc/fstab /etc/fstab.bk # back up the /etc/fstab file
  3130. Add the swap file information to the end of your /etc/fstab file
  3131. $ echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
  3132. adjusting the swappiness property:
  3133. The swappiness parameter configures how often your system swaps data out of RAM
  3134. to the swap space. This is a value between 0 and 100 that represents a
  3135. percentage.
  3136. $ cat /proc/sys/vm/swappiness # the current swappiness value
  3137. $ sudo sysctl vm.swappiness=10 # using the sysctl command to set swappiness
  3138. This setting will persist until the next reboot. We can set this value
  3139. automatically at restart by adding the line to /etc/sysctl.conf file
  3140. $ sudo vi /etc/sysctl.conf
  3141. At the bottom, you can add
  3142. vm.swappiness=10
  3143. adjusting the cache pressure setting:
  3144. This setting configures how much the system will choose to cache inode and
  3145. dentry information over other data.
  3146. $ cat /proc/sys/vm/vfs_cache_pressure # current value by querying the proc
  3147. $ sudo sysctl vm.vfs_cache_pressure=50 # set the cache pressure setting value
  3148. This setting will persist until the next reboot. We can set this value
  3149. automatically at restart by adding the line to /etc/sysctl.conf file
  3150. $ sudo vi /etc/sysctl.conf
  3151. At the bottom, add the line that specifies the new value
  3152. vm.vfs_cache_pressure=50
  3153. Ref: digitalocean.com/community/tutorials/how-to-add-swap-space-on-debian-11
  3154. # find ip address of remote machine for ssh connection
  3155. 1. find ip address of local machine
  3156. $ ip addr [192.168.29.175/24]
  3157. 2. use nmap to find all ip address in the network
  3158. $ nmap -sn 192.168.29.0/24
  3159. $ nmap -sn 192.168.29.1-254/24 | egrep "scan report" | awk '{print $5}'
  3160. $ doas arp-scan --interface=eno1 --localnet # discover all hosts on the local network
  3161. # drivers used by sound card
  3162. $ lspci -knn | grep -iA2 audio
  3163. # swiss army knife
  3164. strace
  3165. ngrep
  3166. netstat
  3167. wireshark
  3168. eBPF
  3169. /proc
  3170. perf
  3171. ps
  3172. # strace - diagnostic, instructional, and debugging tool
  3173. $ strace ./revlist.py
  3174. $ strace -e file ./revlist.py # file calls
  3175. $ strace -e read ./revlist.py # read calls
  3176. $ strace -e write ./revlist.py # write calls
  3177. $ strace -e network ./revlist.py # network calls
  3178. $ strace -e network curl mark.mcnally.je # network socket information
  3179. $ strace -e connect curl mark.mcnally.je # connect information
  3180. $ strace -p <process id> -e connect # network calls <process id> making
  3181. $ strace -o file.txt ./revlist.py # save output in file.txt
  3182. $ strace -t ./revlist.py # include time stamp
  3183. $ strace -c ./revlist.py # summarize
  3184. $ strace -p <vim process id> -e read # strace vim read calls
  3185. # regex
  3186. $ grep text file.txt
  3187. $ grep text file.txt -o | wc -l
  3188. $ grep Text file.txt -o | wc -l
  3189. $ grep [tT]ext file.txt -o | wc -l
  3190. $ grep "^t" file.txt # ^ - matches t at start of the line
  3191. $ grep "t$" file.txt # $ - matches t at end of the line
  3192. $ grep "t." file.txt # . - matches t and one char after t
  3193. $ grep "t.*" file.txt # * - matches t and all other char after t
  3194. $ grep -E [t]{2} file.txt # repeat t twice (example: tt in twitter)
  3195. $ grep -E "^[a-z]*@.*$" file.txt # grep email address (E - extended)
  3196. # fzf - a general-purpose command-line fuzzy finder
  3197. # install
  3198. $ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
  3199. $ ~/.fzf/install
  3200. # upgrading
  3201. $ cd ~/.fzf && git pull && ./install
  3202. # command-line
  3203. $ history | fzf
  3204. # find and replace string with sed
  3205. Ref: https://linuxize.com/post/how-to-use-sed-to-find-and-replace-string-in-files/
  3206. $ sed -i 's/search_regex/replacement/g' *.txt
  3207. where,
  3208. -i By default, sed writes its output to the standard output. This
  3209. option tells sed to edit files in place. If an extension is supplied
  3210. (ex: i.bak), a backup of the original file is created.
  3211. s The substitute command, probably the most used command in sed.
  3212. / / / Delimiter character. It can be any character but usually the slash (/)
  3213. character is used.
  3214. search_regex Normal string or a regular expression to search for.
  3215. replacement The replacement string.
  3216. g Global replacement flag. By default, sed reads the file line by line
  3217. and changes only the first occurrence of the search_regex on a line.
  3218. When the replacement flag is provided, all occurrences are replaced.
  3219. Note: It is a good practice to put quotes around the argument so the shell
  3220. meta-characters won't expand.
  3221. # command line tool for manipulating multi-page djvu document
  3222. Reference: https://manpages.debian.org/testing/djvulibre-bin/index.html
  3223. $ doas apt-get install djvulibre-bin
  3224. $ man djvused
  3225. $ djvused -e n file.djvu # print the number of pages of the file file.djvu
  3226. $ djvm -delete file.djvu 2 # remove page 2 from file.djvu and save as file.djvu
  3227. $ djvused -v file.djvu # interactive mode
  3228. djvused: type "help" to see available commands.
  3229. djvused: ok.
  3230. <Ctrl> C
  3231. # djvu -> ps -> pdf
  3232. $ djvups -mode=foreground -gray input.djvu output.ps
  3233. $ djvups -mode=black input.djvu output.ps
  3234. $ djvups -mode=color input.djvu output.ps # default -mode=color
  3235. $ ps2pdf output.ps
  3236. # djvu rendering library
  3237. $ doas apt-get install djvulibre-bin
  3238. * djvm - manipulate bundled multi-page DjVu documents
  3239. * djvudigital - creates DjVu files from PS or PDF files
  3240. * djvuextract - extract chunks from DjVu image files
  3241. * djvups - convert DjVu documents to PostScript
  3242. * djvutoxml - DjVuLibre XML tools
  3243. * djvuxmlparser - DjvuLibre XML tools
  3244. * djvmcvt - convert multi-page DjVu documents
  3245. * djvudump - display internal structure of DjVu files
  3246. * djvumake - assemble DjVu image files
  3247. * djvused - multi-purpose DjVu document editor
  3248. * djvutxt - extract the hidden text from DjVu documents
  3249. # compare directories
  3250. $ diff -qr /path/to/directory1 /path/to/directory2
  3251. $ diff -qrs /path/to/directory1 /path/to/directory2
  3252. options:
  3253. -q (--brief) report only when files differ
  3254. -r (--recursive) recursively compare any subdirectories found
  3255. -s (--report-identical-files) report when two files are the same
  3256. # pdf rendering library
  3257. $ doas apt-get install poppler-utils
  3258. * pdfdetach - lists or extracts embedded files (attachments)
  3259. * pdffonts - font analyzer
  3260. * pdfimages - image extractor
  3261. * pdfinfo - document information
  3262. * pdfseparate - page extraction tool
  3263. * pdfsig - verifies digital signatures
  3264. * pdftocairo - PDF to PNG/JPEG/PDF/PS/EPS/SVG converter using Cairo
  3265. * pdftohtml - PDF to HTML converter
  3266. * pdftoppm - PDF to PPM/PNG/JPEG image converter
  3267. * pdftops - PDF to PostScript (PS) converter
  3268. * pdftotext - text extraction
  3269. * pdfunite - document merging tool
  3270. # pdfjam
  3271. pdfjam is part of the TeX Live distribution.
  3272. $ doas apt-get install texlive-extra-utils
  3273. Among other features, it can be used to adjust PDF page sizes with an intuitive
  3274. syntax:
  3275. $ pdfjam --outfile output.pdf --paper a2paper input.pdf
  3276. $ pdfsize output.pdf
  3277. The --paper option must be followed by a valid LaTeX paper size. However, we can
  3278. use custom sizes with this syntax:
  3279. $ pdfjam --outfile output.pdf --papersize '{200mm,350mm}' input.pdf
  3280. $ pdfsize output.pdf
  3281. Unfortunately, hyperlinks and bookmarks are lost.
  3282. $ pdfjam infile1.pdf '{},2-' infile2.pdf '10,3-6' --outfile outfile.pdf
  3283. $ pdfjam infile.pdf --fitpaper true '4-' --outfile outfile.pdf
  3284. # pdfposter
  3285. pdfposter is to create posters by printing multiple pages of a PDF. However, we
  3286. can also use it to resize a PDF.
  3287. $ doas apt-get install pdfposter
  3288. Let's do a US letter to A2 conversion:
  3289. $ pdfposter -mA2 input.pdf output.pdf
  3290. $ pdfsize output.pdf
  3291. We can also specify custom sizes, 200x350mm:
  3292. $ pdfposter -m200x350mm input.pdf output.pdf
  3293. $ pdfsize output.pdf
  3294. # find minimum and maximum values
  3295. $ cut -f1 -d ' ' filename.txt | sort -n | head -1 # minimum
  3296. $ cut -f1 -d ' ' filename.txt | sort -n | tail -1 # maximum
  3297. # scan IP address connected to the network
  3298. nmap -sn 192.168.29.0/24 # disable port scanning, host discover only
  3299. ssh user@192.168.29.132
  3300. # Ly TUI display manager
  3301. src/login.c:13:10: fatal error: security/pam_appl.h: No such file or directory
  3302. #include <security/pam_appl.h>
  3303. On Debian-based distros running apt install build-essential libpam0g-dev
  3304. libxcb-xkb-dev as root should install all the dependencies for you.
  3305. Clone the repository:
  3306. $ git clone --recurse-submodules https://github.com/fairyglade/ly
  3307. Change the directory to ly: $ cd ly
  3308. Compile: $ make
  3309. Test in the configured tty (tty2 by default) or a terminal emulator
  3310. (but desktop environments won't start): # make run
  3311. Install Ly and the provided systemd service file: # make install installsystemd
  3312. Enable the service: # systemctl enable ly.service
  3313. Reference: https://github.com/fairyglade/ly
  3314. # verify Tor Browser's signature
  3315. 1. Installing GnuPG
  3316. 2. Fetching the Tor Developers key
  3317. gpg --auto-key-locate nodefault,wkd --locate-keys torbrowser@torproject.org
  3318. This should show you something like:
  3319. gpg: key 4E2C6E8793298290: public key "Tor Browser Developers (signing key)
  3320. <torbrowser@torproject.org>" imported
  3321. gpg: Total number processed: 1
  3322. gpg: imported: 1
  3323. pub rsa4096 2014-12-15 [C] [expires: 2025-07-21]
  3324. EF6E286DDA85EA2A4BA7DE684E2C6E8793298290
  3325. uid [ unknown] Tor Browser Developers (signing key) <torbrowser@torproject.org>
  3326. sub rsa4096 2018-05-26 [S] [expires: 2020-12-19]
  3327. After importing the key, you can save it to a file (identifying it by its
  3328. fingerprint here):
  3329. gpg --output ./tor.keyring --export 0xEF6E286DDA85EA2A4BA7DE684E2C6E8793298290
  3330. This command results in the key being saved to a file found at the path
  3331. ./tor.keyring, ie. in the current directory.
  3332. 3. Verifying the signature
  3333. To verify the signature of the package you downloaded, you will need to
  3334. download the corresponding ".asc" signature file as well as the installer
  3335. file itself, and verify it with a command that asks GnuPG to verify the file
  3336. that you downloaded.
  3337. For GNU/Linux users (change x86_64 to i686 if you have the 32-bit package):
  3338. gpgv --keyring ./tor.keyring ~/Downloads/tor-browser-linux-x86_64-13.0.1.tar.xz.asc
  3339. ~/Downloads/tor-browser-linux-x86_64-13.0.1.tar.xz
  3340. The result of the command should contain:
  3341. gpgv: Good signature from "Tor Browser Developers (signing key)
  3342. <torbrowser@torproject.org>"
  3343. Reference: https://support.torproject.org/tbb/how-to-verify-signature/