linux:ubuntu:useful-commands
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
linux:ubuntu:useful-commands [2024/02/08 02:37] – odefta | linux:ubuntu:useful-commands [2024/02/08 17:12] (current) – [[user] Change mode] odefta | ||
---|---|---|---|
Line 4: | Line 4: | ||
< | < | ||
file file.txt | file file.txt | ||
+ | </ | ||
+ | |||
+ | ===== [cat] Add line numbers to a file ===== | ||
+ | < | ||
+ | cat -n file.txt | ||
+ | nl file.txt | ||
</ | </ | ||
Line 260: | Line 266: | ||
< | < | ||
sudo ip link show | sudo ip link show | ||
+ | </ | ||
+ | |||
+ | ===== [ip] UP / DOWN states of network interfaces ===== | ||
+ | |||
+ | Display only the names and states (UP / DOWN) of the network interfaces on the system, using the format interface_name: | ||
+ | |||
+ | < | ||
+ | ip link show | awk '/ | ||
+ | </ | ||
+ | Output: | ||
+ | < | ||
+ | lo:DOWN | ||
+ | ens33:UP | ||
+ | ens34:UP | ||
+ | docker0: | ||
+ | br1:DOWN | ||
+ | br2:DOWN | ||
</ | </ | ||
Line 285: | Line 308: | ||
ping -c 4 10.125.50.50 | ping -c 4 10.125.50.50 | ||
</ | </ | ||
- | c - number of packets to send (by default | + | c - number of packets to send (by default |
===== [ip] Show routing table / find default gateway ===== | ===== [ip] Show routing table / find default gateway ===== | ||
Line 297: | Line 320: | ||
{{: | {{: | ||
+ | To extract just the default gateway ip: | ||
+ | < | ||
+ | ip route show | awk 'NR==1 {print $3}' | ||
+ | </ | ||
+ | {{: | ||
===== [ip] [nmcli] Find DNS Servers ===== | ===== [ip] [nmcli] Find DNS Servers ===== | ||
< | < | ||
Line 477: | Line 505: | ||
grep -o ' | grep -o ' | ||
</ | </ | ||
- | o - print each occurrence on a separate line | + | o - print each occurrence on a separate line \\ |
l (from wc) - count lines | l (from wc) - count lines | ||
Line 490: | Line 518: | ||
grep -nri search workspace/ | grep -nri search workspace/ | ||
</ | </ | ||
- | n - show line number | + | n - show line number |
- | r - recursive | + | r - recursive |
i - case insensitive | i - case insensitive | ||
Line 731: | Line 759: | ||
ls [abc]*.txt | ls [abc]*.txt | ||
</ | </ | ||
- | [abc] - characters a, b or c | + | [abc] - characters a, b or c \\ |
- | * - any number of characters (including 0) | + | * - any number of characters (including 0) \\ |
.txt - ends with txt | .txt - ends with txt | ||
Line 1052: | Line 1080: | ||
echo -e " | echo -e " | ||
</ | </ | ||
- | e - interpret escape sequences | + | e - interpret escape sequences |
n - numbers (sort as numbers) | n - numbers (sort as numbers) | ||
Line 1167: | Line 1195: | ||
< | < | ||
history | awk ' | history | awk ' | ||
+ | </ | ||
+ | |||
+ | ===== [for] Start 10 processes in background then kill them ===== | ||
+ | |||
+ | < | ||
+ | for i in {1..10}; do sleep 3000 & done; pkill sleep | ||
+ | </ | ||
+ | |||
+ | ===== [for] Create 15 files - their names contains numbers ===== | ||
+ | |||
+ | Using a one-liner, create 15 files with names ranging from final-exam-00.txt to final-exam-15.txt. | ||
+ | |||
+ | < | ||
+ | for i in {0..15}; do touch final-exam-$(printf " | ||
</ | </ | ||
Line 1469: | Line 1511: | ||
{{: | {{: | ||
- | ===== [bash] [sec] [hash] Script to real all lines from a file and print the SHA256 sum of each ===== | + | ===== [bash] [sec] [hash] Script to read all lines from a file and print the SHA256 sum of each ===== |
Suppose the input file is called parole.txt. | Suppose the input file is called parole.txt. | ||
- | < | + | < |
#!/bin/bash | #!/bin/bash | ||
Line 1482: | Line 1524: | ||
</ | </ | ||
{{: | {{: | ||
+ | |||
+ | ===== [bash] [ps] Script to display every second the process with highest CPU usage ===== | ||
+ | |||
+ | <code bash top.sh> | ||
+ | #!/bin/bash | ||
+ | while true; do | ||
+ | clear | ||
+ | #echo " | ||
+ | echo " | ||
+ | ps -eo %cpu, | ||
+ | sleep 1 | ||
+ | done | ||
+ | </ | ||
+ | {{: | ||
===== [git] Configure initial settings ===== | ===== [git] Configure initial settings ===== | ||
Line 1719: | Line 1775: | ||
< | < | ||
w | awk ' | w | awk ' | ||
+ | </ | ||
+ | |||
+ | ===== [user] Display the users who have opened a terminal on the host system ===== | ||
+ | |||
+ | < | ||
+ | who | awk '$2 ~ /^tty/ {print $1}' | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | ~ - equals for regular expressions | ||
+ | / / - delimitates a regular expression | ||
+ | ^tty - starts with tty. | ||
</ | </ | ||
Line 1888: | Line 1956: | ||
</ | </ | ||
- | Eliminare | + | Eliminate |
< | < | ||
chmod 601 file.txt | chmod 601 file.txt | ||
Line 1894: | Line 1962: | ||
</ | </ | ||
- | Eliminare | + | Eliminate |
< | < | ||
chmod ugo-w file.txt | chmod ugo-w file.txt |
linux/ubuntu/useful-commands.1707352655.txt.gz · Last modified: 2024/02/08 02:37 by odefta