Useful Linux Command Line Stuff: Difference between revisions
Created page with "==Networking== *Get the IP address of all interfaces **networkctl status *Display all IP addresses of the host - hostname -I *Enable/disable interface - ip link set <interface> up *ip link set <interface> down *Manage firewall rules **enable firewall: sudo ufw enable **list rules: sudo ufw status **allow port: sudo ufw allow <port> **deny port: sudo ufw deny <port> *Connect remotely through SSH **ssh <user>@<host IP> Packages Search for packages apt search <string> sna..." |
mNo edit summary |
||
Line 1: | Line 1: | ||
==Networking== | ==Networking== | ||
====Get the IP address of all interfaces==== | |||
*networkctl status | |||
====Display all IP addresses of the host==== | |||
*hostname -I | |||
*Enable/disable interface - ip link set <interface> up | *Enable/disable interface - ip link set <interface> up | ||
*ip link set <interface> down | *ip link set <interface> down |
Revision as of 10:04, 10 July 2024
Networking
Get the IP address of all interfaces
- networkctl status
Display all IP addresses of the host
- hostname -I
- Enable/disable interface - ip link set <interface> up
- ip link set <interface> down
- Manage firewall rules
- enable firewall: sudo ufw enable
- list rules: sudo ufw status
- allow port: sudo ufw allow <port>
- deny port: sudo ufw deny <port>
- Connect remotely through SSH
- ssh <user>@<host IP>
Packages
Search for packages
apt search <string>
snap find <string>
List available updates
apt list --upgradable
Apply all available updates
sudo apt update && sudo apt upgrade
Install from the Ubuntu archive:
sudo apt install <package>
Install from the snap store:
sudo snap install <package>
Which package provides this file?
sudo apt install apt-file
sudo apt-file update
apt-file <filename or command>
Files
List files
ls
List files with permissions and dates
ls -al
Common file operations
create empty: touch <filename>
create with content: echo "<content>" > <filename>
append content: echo "<content>" >> <filename>
display a text file: cat <file>
copy: cp <file> <target filename>
move/rename: mv <file> <target directory/filename>
delete: rm <file>
Create a directory
mkdir <directory>
Create directories recursively
mkdir -p <directory1>/<directory2>
Delete a directory recursively
rm -r <directory>
Quick file search
locate
Search string in file
grep <string> <filename>
Search string recursively in
directory
grep -Iris <string> <directory>
Find files modified in the last n minutes
find <directory> -mmin -<n> -type f
eg. find . -mmin -5 -type f
Show only the nth column
col<n> “<separator>” <filename>
eg. col2 “,” foo.csv
Display file paginated
less <filename>
Display first n lines
head -n <n> <filename>
Display last n lines
tail -n <n> <filename>
Follow file content as it increases
tail -f <filename>
Pack a directory into an archive
zip: zip -r <target> <source dir>
tar.gz: tar cvzf <target>.tar.gz <source dir>
Unpack an archive
zip: unzip <zip file>
tar.gz: tar xf <tar.gz file>
Copy file to remote server
scp <filename> <user@server>:<destination>
eg. scp config.yaml admin@192.0.0.0:/config
Copy directory recursively
from remote server
scp -r <user@server>:<source> <destination>
eg. scp -r admin@192.0.0.0:/config /tmp
Security Show which users are logged in w Get password expiration date for <user> chage -l <user> Set password expiration date for <user> sudo chage <user> Lock a user account sudo passwd -l <user> Unlock a user account sudo passwd -u <user> List open ports and associated processes sudo netstat -tulpn
Automatically detect and ban abusive IP addresses sudo apt install fail2ban Show banned IP addresses sudo fail2ban-client status sudo fail2ban-client status <jail> Get the support status for installed packages ubuntu-support-status Enable kernel live patching sudo snap install canonical-livepatch sudo canonical-livepatch enable <token> Visit ubuntu.com/livepatch to get a free token for up to 3 machines.