Intro#
This section is focused in options of using/configuring linux.
Bash#
Bash is a shell commonly used in Linux-based operating systems. Mastering Bash allows you to combine results from Linux utilities and create your own, which is a straightforward way to optimize tasks. Find out more on the specific page or in the official manual.
The following example shows how to extract raw JSON using the curl
command, format it nicely with the jp
tool, and transform it to YAML format using the yp
tool. To perform all this, we use just two Bash command operators: |
and $
.
docker run -itd --name temp_http --rm -p 80:80 kennethreitz/httpbin
json_output=$(curl -s localhost:80/json)
echo $json_output | jq
echo "============================================================"
echo "$json_output" | jq '.' | yq -P
docker stop temp_http
5d54c061747cf404cb1b6623515f3836d562367470208a9e008c4f7c7f0c2b75
{
"slideshow": {
"author": "Yours Truly",
"date": "date of publication",
"slides": [
{
"title": "Wake up to WonderWidgets!",
"type": "all"
},
{
"items": [
"Why <em>WonderWidgets</em> are great",
"Who <em>buys</em> WonderWidgets"
],
"title": "Overview",
"type": "all"
}
],
"title": "Sample Slide Show"
}
}
============================================================
slideshow:
author: Yours Truly
date: date of publication
slides:
- title: Wake up to WonderWidgets!
type: all
- items:
- Why <em>WonderWidgets</em> are great
- Who <em>buys</em> WonderWidgets
title: Overview
type: all
title: Sample Slide Show
temp_http
Exit status#
When your program exits, it returns a number that describes the circumstances under which the program finished. This output is stored in the $?
variable, allowing you to check the state of the command.
Code |
Description |
---|---|
0 |
Success: The program or command completed successfully. |
1 |
General error: A generic error occurred. |
2 |
Misuse of shell builtins: Incorrect usage of a shell command or builtin. |
126 |
Command invoked cannot execute: Found but not executable. |
127 |
Command not found: Command not found in system PATH or misspelled. |
128 |
Invalid exit argument: Program returned a value outside the valid exit range. |
130 |
Terminated by Ctrl+C: Process killed by SIGINT signal. |
137 |
Killed by SIGKILL: Process terminated by |
139 |
Segmentation fault: Process terminated by SIGSEGV. |
128+N |
Termination by signal (N): Exit code represents signal (N). |
10 |
(Custom) Missing configuration file. |
20 |
(Custom) Resource unavailable. |
The following cells shows examples of invoking ?
varable in different cases.
The basic case is when a program finishes successfully, resulting in 0
:
echo "hello world"
echo $?
hello world
0
In cases where a command is passed a parameter it cannot handle, such as with the ls
command, it returns a status code of 2
.
ls -w
echo $?
ls: option requires an argument -- 'w'
Try 'ls --help' for more information.
2
An example of invoking a Command not found
exception.
this_command_doesnt_exist
echo $?
this_command_doesnt_exist: command not found
127
Tiny commands#
There are some commands that are really primitive to use. They literally have 1-3 options. It doesn’t make sense to have a separate section for all such commands, so we’ll cover them all in this section.
Print the number of processing units available to the current process, which may be less than the number of online processors.
nproc
32
Print how long system have been running.
uptime
16:29:57 up 3:13, 1 user, load average: 1,13, 1,39, 1,19
Shows or sets the system’s hostname.
hostname
MBD843AE246AC7
Print working directory.
pwd
/home/f.kobak@maxbit.local/Documents/knowledge/other
Pause the execution flow for a certain amount of time. The following example shows that the second execution of uptime
is delayed by sleep
when compared to the first execution of uptime
.
uptime
sleep 3
uptime
18:54:35 up 42 min, 1 user, load average: 1.02, 0.86, 0.57
18:54:39 up 42 min, 1 user, load average: 1.02, 0.86, 0.57
Manage input/ouput#
There is a number of tools that are commonly used to work with the terminal.
Tool |
Description |
---|---|
|
Passes the result of one command to another command. |
|
Searches for patterns in the output of a command. |
|
Redirects the command output to a file. |
|
Simultaneously redirects the output to both the standard output and a file. |
Heredoc |
Allows you to write multi-line instructions directly in the terminal. |
Check more details in the special page.
Variables#
You can define variables in the current shell session using the syntax <variable_name>=<value>
. To access a variable, use the syntax $variable_name
. These variables will be substituted in the current command.
There is a special type of variable widely used in practice — environment variables. Environment variables are variables inherited by nested shells. The environment passed to any executed command includes the shell’s initial environment. Use the syntax export <variable_name>=<value>
to set an environment variable.
Check:
Particular page on this website.
Environmennt desciription on bash documentation.
The following code demonstrates defining a variable and substituting its value into the echo
command.
MY_VAR=10
echo $MY_VAR
10
The following cell defines an environment variable and a regular variable, then attempts to access both from a nested bash
shell:
export env_var="environment"
just_var="local"
bash -c "echo \"\$just_var \$env_var\""
environment
As a result, only the value for the environment variable exists in the nested shell.
Filesystem#
In this section considered set of tools that allows to work with filesystem in Linux.
The following table shows groups of commands and their descriptions. Check more specific description for some of them in the corresponding page.
Category |
Utility |
Description |
---|---|---|
File and Directory Management |
|
List files and directories. |
|
Change directory. |
|
|
Create directories. |
|
|
Remove empty directories. |
|
|
Remove files and directories. |
|
|
Move or rename files and directories. |
|
|
Copy files and directories. |
|
|
Create empty files or update timestamps. |
|
|
Search for files and directories. |
|
|
Quickly find files by name (uses a prebuilt database). |
|
|
Display directories as a tree structure. |
|
Viewing File Contents |
|
View file contents. |
|
View file contents interactively, with scrolling. |
|
|
View file contents page by page. |
|
|
Display the first few lines of a file. |
|
|
Display the last few lines of a file. |
|
|
Text editors for viewing and editing files. |
|
File Information |
|
Display detailed information about a file. |
|
Determine the type of a file. |
|
|
Display disk usage for files and directories. |
|
|
Show disk space usage of filesystems. |
|
|
List information about block devices (disks and partitions). |
|
|
Mount/unmount filesystems. |
|
|
Display block device attributes (UUID, filesystem type). |
|
|
Check file types and compare values |
|
File Permissions and Ownership |
|
Change file permissions. |
|
Change file ownership. |
|
|
Change file group ownership. |
|
|
Set default permissions for new files. |
|
File Archiving and Compression |
|
Archive files into tarballs. |
|
Compress files. |
|
|
Decompress files. |
|
Filesystem Checks and Maintenance |
|
Filesystem check and repair. |
|
Create a new filesystem. |
|
|
Resize ext2/ext3/ext4 filesystems. |
|
|
Adjust tunable parameters on ext2/ext3/ext4 filesystems. |
|
|
Filesystem check specifically for ext filesystems. |
|
Symbolic and Hard Links |
|
Create hard or symbolic links. |
|
Display the target of a symbolic link. |
|
Advanced Utilities |
|
Synchronize files and directories across locations. |
|
Securely copy files between systems. |
|
|
List open files by processes. |
|
|
Monitor filesystem events in real time. |
|
|
Trim unused space on filesystems for SSDs. |
|
|
Display free disk space on mounted filesystems. |
|
File and Directory Management |
|
List files and directories. |
|
Change directory. |
|
|
Create directories. |
|
|
Remove empty directories. |
|
|
Remove files and directories. |
|
|
Move or rename files and directories. |
|
|
Copy files and directories. |
|
|
Create empty files or update timestamps. |
|
|
Search for files and directories. |
|
|
Quickly find files by name (uses a prebuilt database). |
|
|
Display directories as a tree structure. |
|
Viewing File Contents |
|
View file contents. |
|
View file contents interactively, with scrolling. |
|
|
View file contents page by page. |
|
|
Display the first few lines of a file. |
|
|
Display the last few lines of a file. |
|
|
Text editors for viewing and editing files. |
|
File Information |
|
Display detailed information about a file. |
|
Determine the type of a file. |
|
|
Display disk usage for files and directories. |
|
|
Show disk space usage of filesystems. |
|
|
List information about block devices (disks and partitions). |
|
|
Mount/unmount filesystems. |
|
|
Display block device attributes (UUID, filesystem type). |
|
File Permissions and Ownership |
|
Change file permissions. |
|
Change file ownership. |
|
|
Change file group ownership. |
|
|
Set default permissions for new files. |
|
File Archiving and Compression |
|
Archive files into tarballs. |
|
Compress files. |
|
|
Decompress files. |
|
Filesystem Checks and Maintenance |
|
Filesystem check and repair. |
|
Create a new filesystem. |
|
|
Resize ext2/ext3/ext4 filesystems. |
|
|
Adjust tunable parameters on ext2/ext3/ext4 filesystems. |
|
|
Filesystem check specifically for ext filesystems. |
|
Symbolic and Hard Links |
|
Create hard or symbolic links. |
|
Display the target of a symbolic link. |
|
Advanced Utilities |
|
Synchronize files and directories across locations. |
|
Securely copy files between systems. |
|
|
List open files by processes. |
|
|
Monitor filesystem events in real time. |
|
|
Trim unused space on filesystems for SSDs. |
|
|
Display free disk space on mounted filesystems. |
System information#
This section looks at a number of utilities that can be used to check system status information.
Check the
/etc/os-release
file to find out more about system’s release.The
ps
(process status) command allows you to view processes in your system and some information about them.Check resource limit with the
ulimit
command.
There is more detailed description on the special page.
Network#
There are tons of utilies in linux related to network configuration core utilities are listed in the table below:
Utility |
Description |
---|---|
|
Test the reachability of a host on a network and measure round-trip time. |
|
Trace the route packets take to a network host. |
|
Display network connections, routing tables, interface statistics, and more. |
|
Display detailed information on network connections (modern replacement for |
|
Configure and display network interfaces (deprecated, replaced by |
|
Show/manipulate routing, devices, policy routing, and tunnels. |
|
Query Internet domain name servers (DNS). |
|
A flexible tool for querying DNS servers. |
|
Simple utility for performing DNS lookups. |
|
Manipulate the system’s ARP cache (deprecated, replaced by |
|
Manage neighbor objects (ARP and NDP tables). |
|
Display or change Ethernet device settings. |
|
Configure and display wireless devices and settings. |
|
Configure wireless network interfaces (deprecated, replaced by |
|
Transfer data from or to a server using protocols like HTTP, FTP, etc. |
|
Non-interactive network downloader. |
|
Network packet analyzer. |
|
Network discovery and security auditing tool. |
|
Query databases for domain ownership and registration details. |
|
Versatile networking utility for debugging and exploration (Netcat). |
|
Basic network communication tool (insecure, often replaced by SSH). |
|
Secure Shell for remote login and command execution. |
|
Securely copy files between hosts. |
|
Synchronize files and directories over SSH or local systems. |
|
File Transfer Protocol client (deprecated, replaced by modern secure options). |
|
Configure Linux kernel firewall (replaced by |
|
Configure and manage firewall rules and NAT. |
|
NetworkManager command-line interface. |
|
Command-line utility for interacting with wpa_supplicant. |
|
Combines traceroute and ping for real-time network path monitoring. |
|
OpenSSH daemon for allowing secure connections. |
Find out more accurate description in the special page.
Here is a simple example of using the most popular command for me - curl
. With it you can send any request to the given URL.
Here is request to google.com
, -L
option says to follow redirections.
curl -L google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="be"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="NykFejol5mcXpvA9RS0yHA">(function(){var _g={kEI:'5B9QZ6HoC6OiptQPxMS40AI',kEXPI:'0,3700318,631,435,538661,2872,2891,8349,34679,30022,350740,2006,8155,23351,22435,9779,62657,1340,90685,1804,21011,26071,1635,13492,15784,21780,5208500,11060,8834435,73,66,71,36,15,68,27978220,16672,25212009,100481,16825,5798,15164,8182,10492,38937,9929,11739,6756,22594,1285,9138,4600,328,4459,1766,7974,1989,13444,6,4577,5633,688,7851,24,21979,1346,13703,15634,14520,3291,12565,797,16870,21659,775,1621,16296,41,2950,8931,1758,1,1517,3413,2540,636,1,1482,46,875,336,304,1897,1,6502,2380,950,971,2594,3225,1317,310,6224,1528,49,192,895,3,7,1154,1125,1189,4123,1651,1777,854,2,1547,129,1462,2175,183,343,2,207,3,3258,1,485,2532,1691,1228,122,1260,646,259,960,957,1086,192,1190,2354,706,417,1385,759,1550,5,71,194,55,283,62,257,967,347,1,143,368,421,412,1228,3,2,973,867,468,159,993,19,1,6,448,651,1278,774,712,245,134,53,49,969,915,340,801,459,628,256,35,5,4,4,4,2,70,261,27,1,5,4,4,4,126,3,86,314,159,246,282,25,92,283,564,484,45,651,235,37,187,342,165,346,1269,270,25,275,278,668,296,226,96,247,87,20,265,33,282,36,169,30,3,204,23,37,1,562,19,236,144,548,188,167,148,1232,662,81,265,478,178,129,852,387,2361,562,3,21005428,397113,18,458,1546,1478,868,1779,3661,372,910,1044,6,763,2510,3675862,4189600',kBL:'0lBZ',kOPI:89978449};(function(){var a;((a=window.google)==null?0:a.stvsc)?google.kEI=_g.kEI:window.google=_g;}).call(this);})();(function(){google.sn='webhp';google.kHL='be';})();(function(){
var g=this||self;function k(){return window.google&&window.google.kOPI||null};var l,m=[];function n(a){for(var b;a&&(!a.getAttribute||!(b=a.getAttribute("eid")));)a=a.parentNode;return b||l}function p(a){for(var b=null;a&&(!a.getAttribute||!(b=a.getAttribute("leid")));)a=a.parentNode;return b}function q(a){/^http:/i.test(a)&&window.location.protocol==="https:"&&(google.ml&&google.ml(Error("a"),!1,{src:a,glmm:1}),a="");return a}
function r(a,b,d,c,h){var e="";b.search("&ei=")===-1&&(e="&ei="+n(c),b.search("&lei=")===-1&&(c=p(c))&&(e+="&lei="+c));var f=b.search("&cshid=")===-1&&a!=="slh";c="&zx="+Date.now().toString();g._cshid&&f&&(c+="&cshid="+g._cshid);(d=d())&&(c+="&opi="+d);return"/"+(h||"gen_204")+"?atyp=i&ct="+String(a)+"&cad="+(b+e+c)};l=google.kEI;google.getEI=n;google.getLEI=p;google.ml=function(){return null};google.log=function(a,b,d,c,h,e){e=e===void 0?k:e;d||(d=r(a,b,e,c,h));if(d=q(d)){a=new Image;var f=m.length;m[f]=a;a.onerror=a.onload=a.onabort=function(){delete m[f]};a.src=d}};google.logUrl=function(a,b){b=b===void 0?k:b;return r("",a,b)};}).call(this);(function(){google.y={};google.sy=[];var d;(d=google).x||(d.x=function(a,b){if(a)var c=a.id;else{do c=Math.random();while(google.y[c])}google.y[c]=[a,b];return!1});var e;(e=google).sx||(e.sx=function(a){google.sy.push(a)});google.lm=[];var f;(f=google).plm||(f.plm=function(a){google.lm.push.apply(google.lm,a)});google.lq=[];var g;(g=google).load||(g.load=function(a,b,c){google.lq.push([[a],b,c])});var h;(h=google).loadAll||(h.loadAll=function(a,b){google.lq.push([a,b])});google.bx=!1;var k;(k=google).lx||(k.lx=function(){});var l=[],m;(m=google).fce||(m.fce=function(a,b,c,n){l.push([a,b,c,n])});google.qce=l;}).call(this);google.f={};(function(){
document.documentElement.addEventListener("submit",function(b){var a;if(a=b.target){var c=a.getAttribute("data-submitfalse");a=c==="1"||c==="q"&&!a.elements.q.value?!0:!1}else a=!1;a&&(b.preventDefault(),b.stopPropagation())},!0);document.documentElement.addEventListener("click",function(b){var a;a:{for(a=b.target;a&&a!==document.documentElement;a=a.parentElement)if(a.tagName==="A"){a=a.getAttribute("data-nohref")==="1";break a}a=!1}a&&b.preventDefault()},!0);}).call(this);</script><style>#gbar,#guser{font-size:13px;padding-top:1px !important;}#gbar{height:22px}#guser{padding-bottom:7px !important;text-align:right}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}@media all{.gb1{height:22px;margin-right:.5em;vertical-align:top}#gbar{float:left}}a.gb1,a.gb4{text-decoration:underline !important}a.gb1,a.gb4{color:#00c !important}.gbi .gb4{color:#dd8e27 !important}.gbf .gb4{color:#900 !important}
</style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:0;overflow-y:scroll}#gog{padding:3px 8px 0}td{line-height:.8em}.gac_m td{line-height:17px}form{margin-bottom:20px}.h{color:#1967d2}em{font-weight:bold;font-style:normal}.lst{height:25px;width:496px}.gsfi,.lst{font:18px arial,sans-serif}.gsfs{font:17px arial,sans-serif}.ds{display:inline-box;display:inline-block;margin:3px 0 4px;margin-left:4px}input{font-family:inherit}body{background:#fff;color:#000}a{color:#681da8;text-decoration:none}a:hover,a:active{text-decoration:underline}.fl a{color:#1967d2}a:visited{color:#681da8}.sblc{padding-top:5px}.sblc a{display:block;margin:2px 0;margin-left:13px;font-size:11px}.lsbb{background:#f8f9fa;border:solid 1px;border-color:#dadce0 #70757a #70757a #dadce0;height:30px}.lsbb{display:block}#WqQANb a{display:inline-block;margin:0 12px}.lsb{background:url(/images/nav_logo229.png) 0 -261px repeat-x;color:#000;border:none;cursor:pointer;height:30px;margin:0;outline:0;font:15px arial,sans-serif;vertical-align:top}.lsb:active{background:#dadce0}.lst:focus{outline:none}.Ucigb{width:458px}</style><script nonce="NykFejol5mcXpvA9RS0yHA">(function(){window.google.erd={jsr:1,bv:2124,de:true,dpf:'to0k34x1-IZFePa84heRFuGwPtN8W1HauRhFCjl9bAI'};
var g=this||self;var k,l=(k=g.mei)!=null?k:1,n,p=(n=g.sdo)!=null?n:!0,q=0,r,t=google.erd,v=t.jsr;google.ml=function(a,b,d,m,e){e=e===void 0?2:e;b&&(r=a&&a.message);d===void 0&&(d={});d.cad="ple_"+google.ple+".aple_"+google.aple;if(google.dl)return google.dl(a,e,d,!0),null;b=d;if(v<0){window.console&&console.error(a,b);if(v===-2)throw a;b=!1}else b=!a||!a.message||a.message==="Error loading script"||q>=l&&!m?!1:!0;if(!b)return null;q++;d=d||{};b=encodeURIComponent;var c="/gen_204?atyp=i&ei="+b(google.kEI);google.kEXPI&&(c+="&jexpid="+b(google.kEXPI));c+="&srcpg="+b(google.sn)+"&jsr="+b(t.jsr)+
"&bver="+b(t.bv);t.dpf&&(c+="&dpf="+b(t.dpf));var f=a.lineNumber;f!==void 0&&(c+="&line="+f);var h=a.fileName;h&&(h.indexOf("-extension:/")>0&&(e=3),c+="&script="+b(h),f&&h===window.location.href&&(f=document.documentElement.outerHTML.split("\n")[f],c+="&cad="+b(f?f.substring(0,300):"No script found.")));google.ple&&google.ple===1&&(e=2);c+="&jsel="+e;for(var u in d)c+="&",c+=b(u),c+="=",c+=b(d[u]);c=c+"&emsg="+b(a.name+": "+a.message);c=c+"&jsst="+b(a.stack||"N/A");c.length>=12288&&(c=c.substr(0,12288));a=c;m||google.log(0,"",a);return a};window.onerror=function(a,b,d,m,e){r!==a&&(a=e instanceof Error?e:Error(a),d===void 0||"lineNumber"in a||(a.lineNumber=d),b===void 0||"fileName"in a||(a.fileName=b),google.ml(a,!1,void 0,!1,a.name==="SyntaxError"||a.message.substring(0,11)==="SyntaxError"||a.message.indexOf("Script error")!==-1?3:0));r=null;p&&q>=l&&(window.onerror=null)};})();</script></head><body bgcolor="#fff"><script nonce="NykFejol5mcXpvA9RS0yHA">(function(){var src='/images/nav_logo229.png';var iesg=false;document.body.onload = function(){window.n && window.n();if (document.images){new Image().src=src;}
if (!iesg){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.focus();}
}
})();</script><div id="mngb"><div id=gbar><nobr><b class=gb1>Пошук</b> <a class=gb1 href="https://www.google.com/imghp?hl=be&tab=wi">Відарысы</a> <a class=gb1 href="http://maps.google.by/maps?hl=be&tab=wl">Карты</a> <a class=gb1 href="https://play.google.com/?hl=be&tab=w8">Play</a> <a class=gb1 href="https://www.youtube.com/?tab=w1">YouTube</a> <a class=gb1 href="https://news.google.com/?tab=wn">Навіны</a> <a class=gb1 href="https://mail.google.com/mail/?tab=wm">Gmail</a> <a class=gb1 href="https://drive.google.com/?tab=wo">Дыск</a> <a class=gb1 style="text-decoration:none" href="https://www.google.by/intl/be/about/products?tab=wh"><u>Яшчэ</u> »</a></nobr></div><div id=guser width=100%><nobr><span id=gbn class=gbi></span><span id=gbf class=gbf></span><span id=gbe></span><a href="http://www.google.by/history/optout?hl=be" class=gb4>Гісторыя пошуку</a> | <a href="/preferences?hl=be" class=gb4>Налады</a> | <a target=_top id=gb_70 href="https://accounts.google.com/ServiceLogin?hl=be&passive=true&continue=http://www.google.com/&ec=GAZAAQ" class=gb4>Увайсці</a></nobr></div><div class=gbh style=left:0></div><div class=gbh style=right:0></div></div><center><br clear="all" id="lgpd"><div id="XjhHGf"><img alt="Google" height="92" src="/images/branding/googlelogo/1x/googlelogo_white_background_color_272x92dp.png" style="padding:28px 0 14px" width="272" id="hplogo"><br><br></div><form action="/search" name="f"><table cellpadding="0" cellspacing="0"><tr valign="top"><td width="25%"> </td><td align="center" nowrap=""><input name="ie" value="ISO-8859-1" type="hidden"><input value="be" name="hl" type="hidden"><input name="source" type="hidden" value="hp"><input name="biw" type="hidden"><input name="bih" type="hidden"><div class="ds" style="height:32px;margin:4px 0"><div style="position:relative;zoom:1"><input class="lst Ucigb" style="margin:0;padding:5px 8px 0 6px;vertical-align:top;color:#000;padding-right:38px" value="" title="Пошук Google" maxlength="2048" name="q" size="57"><img src="/textinputassistant/tia.png" style="position:absolute;cursor:pointer;right:5px;top:4px;z-index:300" data-script-url="/textinputassistant/13/be_tia.js" id="tsuid_5B9QZ6HoC6OiptQPxMS40AI_1" alt="" height="23" width="27"><script nonce="NykFejol5mcXpvA9RS0yHA">(function(){var id='tsuid_5B9QZ6HoC6OiptQPxMS40AI_1';document.getElementById(id).onclick = function(){var s = document.createElement('script');s.src = this.getAttribute('data-script-url');document.body.appendChild(s);};})();</script></div></div><br style="line-height:0"><span class="ds"><span class="lsbb"><input class="lsb" value="Пошук Google" name="btnG" type="submit"></span></span><span class="ds"><span class="lsbb"><input class="lsb" id="tsuid_5B9QZ6HoC6OiptQPxMS40AI_2" value="Мне пашанцуе" name="btnI" type="submit"><script nonce="NykFejol5mcXpvA9RS0yHA">(function(){var id='tsuid_5B9QZ6HoC6OiptQPxMS40AI_2';document.getElementById(id).onclick = function(){if (this.form.q.value){this.checked = 1;if (this.form.iflsig)this.form.iflsig.disabled = false;}
else top.location='/doodles/';};})();</script><input value="AL9hbdgAAAAAZ1At9DNknXcATTkb4obkKikH1B6X3Sa4" name="iflsig" type="hidden"></span></span></td><td class="fl sblc" align="left" nowrap="" width="25%"><a href="/advanced_search?hl=be&authuser=0">Пашыраны пошук</a></td></tr></table><input id="gbv" name="gbv" type="hidden" value="1"><script nonce="NykFejol5mcXpvA9RS0yHA">(function(){var a,b="1";if(document&&document.getElementById)if(typeof XMLHttpRequest!="undefined")b="2";else if(typeof ActiveXObject!="undefined"){var c,d,e=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];for(c=0;d=e[c++];)try{new ActiveXObject(d),b="2"}catch(h){}}a=b;if(a=="2"&&location.search.indexOf("&gbv=2")==-1){var f=google.gbvu,g=document.getElementById("gbv");g&&(g.value=a);f&&window.setTimeout(function(){location.href=f},0)};}).call(this);</script></form><div style="font-size:83%;min-height:3.5em"><br><div id="gws-output-pages-elements-homepage_additional_languages__als"><style>#gws-output-pages-elements-homepage_additional_languages__als{font-size:small;margin-bottom:24px}#SIvCob{color:#474747;display:inline-block;line-height:28px;}#SIvCob a{padding:0 3px;}.H6sW5{display:inline-block;margin:0 2px;white-space:nowrap}.z4hgWe{display:inline-block;margin:0 2px}</style><div id="SIvCob">Даступная мова: <a href="http://www.google.com/setprefs?sig=0_x3Nhk1H3WTGE3KW-rVH--3Gf6wQ%3D&hl=ru&source=homepage&sa=X&ved=0ahUKEwih6v7U5Y2KAxUjkYkEHUQiDioQ2ZgBCAY">русский</a> </div></div></div><span id="footer"><div style="font-size:10pt"><div style="margin:19px auto;text-align:center" id="WqQANb"><a href="/intl/be/ads/">Рэклама</a><a href="/intl/be/about.html">Усё пра Google</a><a href="http://www.google.com/setprefdomain?prefdom=BY&prev=http://www.google.by/&sig=K_DBCofuRI2uP2GBsI-Z2O7XkQGiA%3D">Google.by</a></div></div><p style="font-size:8pt;color:#70757a">© 2024</p></span></center><script nonce="NykFejol5mcXpvA9RS0yHA">(function(){window.google.cdo={height:757,width:1440};(function(){var a=window.innerWidth,b=window.innerHeight;if(!a||!b){var c=window.document,d=c.compatMode=="CSS1Compat"?c.documentElement:c.body;a=d.clientWidth;b=d.clientHeight}if(a&&b&&(a!=google.cdo.width||b!=google.cdo.height)){var e=google,f=e.log,g="/client_204?&atyp=i&biw="+a+"&bih="+b+"&ei="+google.kEI,h="",k=window.google&&window.google.kOPI||null;k&&(h+="&opi="+k);f.call(e,"","",g+h)};}).call(this);})();</script> <script nonce="NykFejol5mcXpvA9RS0yHA">(function(){google.xjs={basecomb:'/xjs/_/js/k\x3dxjs.hp.en.KEkCYfO_aiw.es5.O/ck\x3dxjs.hp.i_QW66W2dnc.L.X.O/am\x3dBAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQBAAAAAAAAAAAMAACMBgAAgAAAAQIAAAAAAAAAAAAAACIAAAUAYQIAACC-IwAQAIsAAPAC/d\x3d1/ed\x3d1/dg\x3d0/ujg\x3d1/rs\x3dACT90oGWj8D9Y5KYfNgUysYZlQd_rUL19A',basecss:'/xjs/_/ss/k\x3dxjs.hp.i_QW66W2dnc.L.X.O/am\x3dBAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAACMAAAAgAAAAQIAAAAAAAAAAAAAACIAAAUAYQI/rs\x3dACT90oGw42FLx1nOBpxxIe5LW4gxh4vlJg',basejs:'/xjs/_/js/k\x3dxjs.hp.en.KEkCYfO_aiw.es5.O/am\x3dAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAMAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACC-IwAQAIsAAPAC/dg\x3d0/rs\x3dACT90oGbJERp3w2xbPtGwQ1BpMIr5KV90g',excm:[]};})();</script> <script nonce="NykFejol5mcXpvA9RS0yHA">(function(){var u='/xjs/_/js/k\x3dxjs.hp.en.KEkCYfO_aiw.es5.O/am\x3dAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAMAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACC-IwAQAIsAAPAC/d\x3d1/ed\x3d1/dg\x3d3/rs\x3dACT90oGbJERp3w2xbPtGwQ1BpMIr5KV90g/m\x3dd';var st=1;var amd=1000;var mmd=0;var pod=true;
var e=this||self;function f(){var a,b,d;if(b=a=(b=window.google)==null?void 0:(d=b.ia)==null?void 0:d.r.B2Jtyd)b=a.m,b=b===1||b===5;return b&&a.cbfd!=null&&a.cbvi!=null?a:void 0};function g(){var a=[u];if(!google.dp){for(var b=0;b<a.length;b++){var d=a[b],c=document.createElement("link");c.as="script";c.href=d;c.rel="preload";document.body.appendChild(c)}google.dp=!0}};google.ps===void 0&&(google.ps=[]);function h(){var a=u,b=function(){};google.lx=google.stvsc?b:function(){k(a);google.lx=b};google.bx||google.lx()}function l(a,b){b&&(a.src=b);var d=a.onload;a.onload=function(c){d&&d(c);google.ps=google.ps.filter(function(C){return a!==C})};google.ps.push(a);document.body.appendChild(a)}google.as=l;function k(a){google.timers&&google.timers.load&&google.tick&&google.tick("load","xjsls");var b=document.createElement("script");b.onerror=function(){google.ple=1};b.onload=function(){google.ple=0};google.xjsus=void 0;l(b,a);google.aple=-1;google.dp=!0};function m(a){var b=a.getAttribute("jscontroller");return(b==="UBXHI"||b==="R3fhkb"||b==="TSZEqd")&&a.hasAttribute("data-src")}function n(){for(var a=document.getElementsByTagName("img"),b=0,d=a.length;b<d;b++){var c=a[b];if(c.hasAttribute("data-lzy_")&&Number(c.getAttribute("data-atf"))&1&&!m(c))return!0}return!1}for(var p=document.getElementsByTagName("img"),q=0,r=p.length;q<r;++q){var t=p[q];Number(t.getAttribute("data-atf"))&1&&m(t)&&(t.src=t.getAttribute("data-src"))};var w,x,y,z,A,B;function D(){google.xjsu=u;e._F_jsUrl=u;A=function(){h()};w=!1;x=(st===1||st===3)&&!!google.caft&&!n();y=f();z=(st===2||st===3)&&!!y&&!n();B=pod}function E(){w||x||z||(A(),w=!0)}setTimeout(function(){google&&google.tick&&google.timers&&google.timers.load&&google.tick("load","xjspls");D();if(x||z){if(x){var a=function(){x=!1;E()};google.caft(a);window.setTimeout(a,amd)}z&&(a=function(){z=!1;E()},y.cbvi.push(a),window.setTimeout(a,mmd));B&&(w||g())}else A()},0);})();window._ = window._ || {};window._DumpException = _._DumpException = function(e){throw e;};window._s = window._s || {};_s._DumpException = _._DumpException;window._qs = window._qs || {};_qs._DumpException = _._DumpException;(function(){var t=[4,65536,0,0,0,0,0,0,66560,0,134218752,587595779,268440582,134479882,10485760,0,0,335544456,2494480,797442048,135266339,556,47];window._F_toggles = window._xjs_toggles = t;})();window._F_installCss = window._F_installCss || function(css){};(function(){google.jl={bfl:0,dw:false,ine:false,ubm:false,uwp:true,vs:false};})();(function(){var pmc='{\x22d\x22:{}}';google.pmc=JSON.parse(pmc);})();(function(){var b=function(a){var c=0;return function(){return c<a.length?{done:!1,value:a[c++]}:{done:!0}}};
var e=this||self;var g,h;a:{for(var k=["CLOSURE_FLAGS"],l=e,n=0;n<k.length;n++)if(l=l[k[n]],l==null){h=null;break a}h=l}var p=h&&h[610401301];g=p!=null?p:!1;var q,r=e.navigator;q=r?r.userAgentData||null:null;function t(a){return g?q?q.brands.some(function(c){return(c=c.brand)&&c.indexOf(a)!=-1}):!1:!1}function u(a){var c;a:{if(c=e.navigator)if(c=c.userAgent)break a;c=""}return c.indexOf(a)!=-1};function v(){return g?!!q&&q.brands.length>0:!1}function w(){return u("Safari")&&!(x()||(v()?0:u("Coast"))||(v()?0:u("Opera"))||(v()?0:u("Edge"))||(v()?t("Microsoft Edge"):u("Edg/"))||(v()?t("Opera"):u("OPR"))||u("Firefox")||u("FxiOS")||u("Silk")||u("Android"))}function x(){return v()?t("Chromium"):(u("Chrome")||u("CriOS"))&&!(v()?0:u("Edge"))||u("Silk")}function y(){return u("Android")&&!(x()||u("Firefox")||u("FxiOS")||(v()?0:u("Opera"))||u("Silk"))};var z=v()?!1:u("Trident")||u("MSIE");y();x();w();var A=!z&&!w(),D=function(a){if(/-[a-z]/.test("ved"))return null;if(A&&a.dataset){if(y()&&!("ved"in a.dataset))return null;a=a.dataset.ved;return a===void 0?null:a}return a.getAttribute("data-"+"ved".replace(/([A-Z])/g,"-$1").toLowerCase())};var E=[],F=null;function G(a){a=a.target;var c=performance.now(),f=[],H=f.concat,d=E;if(!(d instanceof Array)){var m=typeof Symbol!="undefined"&&Symbol.iterator&&d[Symbol.iterator];if(m)d=m.call(d);else if(typeof d.length=="number")d={next:b(d)};else throw Error("b`"+String(d));for(var B=[];!(m=d.next()).done;)B.push(m.value);d=B}E=H.call(f,d,[c]);if(a&&a instanceof HTMLElement)if(a===F){if(c=E.length>=4)c=(E[E.length-1]-E[E.length-4])/1E3<5;if(c){c=google.getEI(a);a.hasAttribute("data-ved")?f=a?D(a)||"":"":f=(f=
a.closest("[data-ved]"))?D(f)||"":"";f=f||"";if(a.hasAttribute("jsname"))a=a.getAttribute("jsname");else{var C;a=(C=a.closest("[jsname]"))==null?void 0:C.getAttribute("jsname")}google.log("rcm","&ei="+c+"&tgtved="+f+"&jsname="+(a||""))}}else F=a,E=[c]}window.document.addEventListener("DOMContentLoaded",function(){document.body.addEventListener("click",G)});}).call(this);</script></body></html>
Finally you just got the html code of the goole main page.
Package management#
This section covers package management techniques, focusing specifically on the apt
(Advanced Packaging Tool) package manager. However, various other tools exist for managing packages. Check more in official ubuntu documentation. For advanced overview of some features visit correspongind page in this website.
Here’s a brief example demonstrating how package management works in Linux using the apt
package manager. It covers basic operations such as listing available packages, installing a package, and removing it.
docker run -itd --rm --name package_management ubuntu
5c58fb6219b16d0f13403b1d031a5048368737003927c391ab31f2461e9502d0
You can list installed packages with apt list --installed
.
docker exec package_management apt list --installed | head -n 10
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Listing...
apt/now 2.7.14build2 amd64 [installed,local]
base-files/now 13ubuntu10.1 amd64 [installed,local]
base-passwd/now 3.6.3build1 amd64 [installed,local]
bash/now 5.2.21-2ubuntu4 amd64 [installed,local]
bsdutils/now 1:2.39.3-9ubuntu6.1 amd64 [installed,local]
coreutils/now 9.4-3ubuntu6 amd64 [installed,local]
dash/now 0.5.12-6ubuntu5 amd64 [installed,local]
debconf/now 1.5.86ubuntu1 all [installed,local]
debianutils/now 5.17build1 amd64 [installed,local]
The following cell shows that there are no installed vim
package by default.
docker exec package_management apt list --installed | grep vim;
true
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
With apt install <package_name>
, you can install a package.
Note: apt
needs up-to-date information about available packages before installation. Therefore, it’s often necessary to run apt update
to refresh the package index.
The following code installs vim
and shows that appropriate lines appear in the list of installed packages.
docker exec package_management bash -c "apt update && apt install -y vim" &> /dev/null
docker exec package_management apt list --installed | grep vim
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
vim-common/noble-updates,noble-security,now 2:9.1.0016-1ubuntu7.5 all [installed,automatic]
vim-runtime/noble-updates,noble-security,now 2:9.1.0016-1ubuntu7.5 all [installed,automatic]
vim/noble-updates,noble-security,now 2:9.1.0016-1ubuntu7.5 amd64 [installed]
Note: Several additional packages were installed because the vim
package depends on other packages. These dependencies are necessary for vim
to function correctly.
To remove installed package use apt remove <package_name>
. The following cell shows the process.
docker exec package_management apt remove -y vim &> /dev/null
docker exec package_management apt list --installed | grep vim
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
vim-common/noble-updates,noble-security,now 2:9.1.0016-1ubuntu7.5 all [installed,auto-removable]
vim-runtime/noble-updates,noble-security,now 2:9.1.0016-1ubuntu7.5 all [installed,auto-removable]
The vim
package has been removed, but it’s requirements are still in the system.
docker stop package_management
package_management
Users & groups#
There are tools to organize users of the system:
/etc/passwd
file: contains information about all users in the system.useradd
command: adds a new user to the system.userdel
command: deletes a specified user from the system.
Find out more in the corresponding page.
The following cell uses the useradd
command to add users to the system:
useradd fedor
Now by running cat
on /etc/passwd
you can check the available users in the system:
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
_apt:x:42:65534::/nonexistent:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:998:998:systemd Network Management:/:/usr/sbin/nologin
systemd-timesync:x:997:997:systemd Time Synchronization:/:/usr/sbin/nologin
messagebus:x:100:101::/nonexistent:/usr/sbin/nologin
polkitd:x:996:996:polkit:/nonexistent:/usr/sbin/nologin
fedor:x:1001:1001::/home/fedor:/bin/sh
There is a user we just created. Try the userdel
command to delete fedor
from the system. The following cell deletes the user and lists available users:
userdel fedor
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
_apt:x:42:65534::/nonexistent:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:998:998:systemd Network Management:/:/usr/sbin/nologin
systemd-timesync:x:997:997:systemd Time Synchronization:/:/usr/sbin/nologin
messagebus:x:100:101::/nonexistent:/usr/sbin/nologin
polkitd:x:996:996:polkit:/nonexistent:/usr/sbin/nologin
Path#
In Linux, PATH
is an environment variable that specifies where the system should look for commands to be executed. Each path is separated by a colon (:
). When you type any command in the terminal, the system searches through each path listed in the PATH
variable for the corresponding command.
The following cell displays the PATH
value of the environment the notebook is running in.
echo $PATH
/root/.vscode-server/bin/cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba/bin/remote-cli:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Consider the contents of /usr/local/bin
, one of the folders typically listed in the PATH
.
ls /usr/local/bin
2to3 ipython jupyter-troubleshoot pygmentize
2to3-3.12 ipython3 pip python
debugpy jupyter pip3 python-config
filetype jupyter-kernel pip3.12 python3
idle jupyter-kernelspec pydoc python3-config
idle3 jupyter-migrate pydoc3 python3.12
idle3.12 jupyter-run pydoc3.12 python3.12-config
Some of the names correspond to commands commonly used for managing Jupyter.
Cron#
Cron is a utility that allows you to schedule commands in a Linux system. You can manage cron jobs using crontab
, a special utility that handles the file defining jobs for cron.
To set up a cron job, type crontab -e
to open the editor where you can define jobs using the following syntax:
minute hour day month weekday command
Each line represents a new cron job.
Find out more at the particular page.
The following cell shows the default cron schedule for Alpine Linux, allowing you to learn the typical format of a cron schedule.
docker run --rm -it alpine crontab -l
# do daily/weekly/monthly maintenance
# min hour day month weekday command
*/15 * * * * run-parts /etc/periodic/15min
0 * * * * run-parts /etc/periodic/hourly
0 2 * * * run-parts /etc/periodic/daily
0 3 * * 6 run-parts /etc/periodic/weekly
0 5 1 * * run-parts /etc/periodic/monthly
GnuPG#
GnuPG (GPG) is a tool that implements the PGP protocol in Linux. Here, we will explore how to use it. Find out more in the specific page.
To avoid displaying GPG information from my local machine, we will demonstrate an example using Docker. The Docker container has GPG pre-installed and includes a pre-generated key.
Note: The sample key for the purpose has been created without a password, which you will generally need to enter when interacting with the secret key.
docker run -itd --name gpg_example --rm fedorkobak/gpg-example:2
1485149a6b2309a0af2003dacfaa460218cb2f90297c5fd0bbe6f0a24fca1421
Use the --generate-key
flag to initiate generation of private/public keys. It’s impossible to display it in text form - it requires tty. Just use the command: docker exec gpg_example gpg --generate-key
and follow the instructions.
After creating a key, you can list it with the --list-keys
flag. Example container already contains generated gpg key.
docker exec gpg_example gpg --list-keys
[keyboxd]
---------
pub ed25519 2024-12-15 [SC] [expires: 2027-12-15]
2218FDFB1F24C0511F22AD226D5C29F6233CA6B7
uid [ultimate] fed <fakeemail@wow.com>
sub cv25519 2024-12-15 [E] [expires: 2027-12-15]
Don’t forget to stop the container afterall.
docker stop gpg_example
gpg_example