Skip to content

Instantly share code, notes, and snippets.

@Tharwat96
Last active May 29, 2021 23:31
Show Gist options
  • Save Tharwat96/f052b6e3ec92214a1609d6d569289a1e to your computer and use it in GitHub Desktop.
Save Tharwat96/f052b6e3ec92214a1609d6d569289a1e to your computer and use it in GitHub Desktop.
Linux commands that I keep forgetting
sed:
to substitute something with something else:
sed "s/something/something_else/g" file.sh
the g in the right is for changing all occurrences in all lines, if it was not written, only the first occurrence of each line is replaced
sed example to substitute new lines with spaces:
sed ':a;N;$!ba;s/\n/ /g' file
awk:
# get only first column
command | awk {'print $1'}
These commands are made to backup a whole partition into one file "backup.tar.gz"
Backup:
sudo tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /
Backup (excluding timeshift):
sudo tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --exclude='/timeshift/*' --one-file-system /
Restore:
sudo tar -xvpzf /path/to/backup.tar.gz -C /restore/location --numeric-owner
----------------------
List hardware devices with their used driver
lspci -knn # for pci interfaces
lsusb -v # for usb interfaces
----------------------
List partitions with their mount points, UUID, filesystem, percentage of used and free space
lsblk -f
List blockdevices with their most details
blkid
blkid | grep -v loop <------------| removes loop devices (fake/virtual devices)
---------------------- |
Revert grep matches |
grep -v ex: -----------------------|
----------------------
Fix XFS:
xfs_repair /dev/sda1
if there is an issue with logs and can't mount the partition as well:
xfs_repair -L /dev/sda1 <--- destroys logs and might make the partition unusable (didn't encounter)
----------------------
To run a program using discrete GPU:
DRI_PRIME=1 <command>
# use less +F instead of tail -f
# shortcuts inside less:
## ctrl + c to get out of follow mode
## shift + f to follow
## q to exit
# ----------------------
# long line temp editing for multiline editor
## ctrl + x + e
#-----------------------
# better alternative to ping that shows the traceroute
## mtrs --curses 8.8.8.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment