User Tools

Site Tools


linux:ubuntu:useful-commands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
linux:ubuntu:useful-commands [2024/02/08 02:56] – [[user] Display the users who have opened a terminal on the host system] odeftalinux:ubuntu:useful-commands [2024/02/08 17:12] (current) – [[user] Change mode] odefta
Line 4: Line 4:
 <code> <code>
 file file.txt file file.txt
 +</code>
 +
 +===== [cat] Add line numbers to a file =====
 +<code>
 +cat -n file.txt
 +nl file.txt
 </code> </code>
  
Line 260: Line 266:
 <code> <code>
 sudo ip link show sudo ip link show
 +</code>
 +
 +===== [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:state.
 +
 +<code>
 +ip link show | awk '/^[0-9]+:/ {print $2 " " $9}' | sed 's/://g' | awk '{print $1 ":" ($2=="UP"?"UP":"DOWN")}'
 +</code>
 +Output:
 +<code>
 +lo:DOWN
 +ens33:UP
 +ens34:UP
 +docker0:DOWN
 +br1:DOWN
 +br2:DOWN
 </code> </code>
  
Line 285: Line 308:
 ping -c 4 10.125.50.50 ping -c 4 10.125.50.50
 </code> </code>
-c - number of packets to send (by default in infinite)+c - number of packets to send (by default is infinite)
  
 ===== [ip] Show routing table / find default gateway ===== ===== [ip] Show routing table / find default gateway =====
Line 482: Line 505:
 grep -o 'searched_string' file.txt | wc -l grep -o 'searched_string' file.txt | wc -l
 </code> </code>
-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 495: Line 518:
 grep -nri search workspace/C/ | less grep -nri search workspace/C/ | less
 </code> </code>
-n - show line number +n - show line number \\  
-r - recursive+r - recursive \\ 
 i - case insensitive i - case insensitive
  
Line 736: Line 759:
 ls [abc]*.txt ls [abc]*.txt
 </code> </code>
-[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 1057: Line 1080:
 echo -e "5\n3\n8\n1" | sort -n echo -e "5\n3\n8\n1" | sort -n
 </code> </code>
-e - interpret escape sequences+e - interpret escape sequences \\ 
 n - numbers (sort as numbers) n - numbers (sort as numbers)
  
Line 1172: Line 1195:
 <code> <code>
 history | awk '{$1=""; print $0}' | sort | uniq -c | sort -nr -k1 | head -10 | awk '{$1=""; print $0}' history | awk '{$1=""; print $0}' | sort | uniq -c | sort -nr -k1 | head -10 | awk '{$1=""; print $0}'
 +</code>
 +
 +===== [for] Start 10 processes in background then kill them =====
 +
 +<code>
 +for i in {1..10}; do sleep 3000 & done; pkill sleep
 +</code>
 +
 +===== [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.
 +
 +<code>
 +for i in {0..15}; do touch final-exam-$(printf "%02d" $i).txt; done
 </code> </code>
  
Line 1487: Line 1524:
 </code> </code>
 {{:linux:ubuntu:pasted:20240208-023728.png}} {{:linux:ubuntu:pasted:20240208-023728.png}}
 +
 +===== [bash] [ps] Script to display every second the process with highest CPU usage =====
 +
 +<code bash top.sh>
 +#!/bin/bash
 +while true; do
 +    clear
 +    #echo "Update on: $(date)"
 +    echo "Process with highest CPU usage:"
 +    ps -eo %cpu,pid,command --sort=-%cpu | head -n 2
 +    sleep 1
 +done
 +</code>
 +{{:linux:ubuntu:pasted:20240208-030524.png}}
 +
 ===== [git] Configure initial settings ===== ===== [git] Configure initial settings =====
  
Line 1904: Line 1956:
 </code> </code>
  
-Eliminare read permission for group:+Eliminate read permission for group:
 <code> <code>
 chmod 601 file.txt chmod 601 file.txt
Line 1910: Line 1962:
 </code> </code>
  
-Eliminare write permission for all:+Eliminate write permission for all:
 <code> <code>
 chmod ugo-w file.txt chmod ugo-w file.txt
linux/ubuntu/useful-commands.1707353815.txt.gz · Last modified: 2024/02/08 02:56 by odefta