Skip to content

Instantly share code, notes, and snippets.

@daniel-finnan
Last active May 16, 2024 11:56
Show Gist options
  • Save daniel-finnan/73d7df340f25d59f462751622b7f6dbd to your computer and use it in GitHub Desktop.
Save daniel-finnan/73d7df340f25d59f462751622b7f6dbd to your computer and use it in GitHub Desktop.
Useful Linux commands

Useful Linux commands

Using bash

File compression

Extract from a tarball

tar -xf archive.tar -C /path/to/directory

where:

-x - extract -f - file option input specifying location -C - file option output specifying location

Package management

Search for packages within APT

apt search package_name

Comparing the contents of two directories

diff -r <directory1> <directory2>

Finding all files containing specific string

grep -Rnw '/path/to/somewhere/' -e 'pattern'

Adding -l option provides file name containing result. See this StackOverflow post

Hard disk

To display connected hard disks, mount points, etc

lsblk

Mounting a disk

Create a folder to mount:

sudo mkdir /media/disk

Then use mount:

sudo mount /dev/sda1 /media/disk

Repairing NTFS partition

Use ntfsfix, which is part of ntfs-3g.

Make sure disk is not mounted:

umount /dev/sda1

Then run nftsfix on disk:

sudo ntfsfix /dev/sda1

Be cautious, MS Windows utilities should be preferred.

Tasks / Processes

ps shows a list of running processes.

Article here details some of the switches, etc.

top provides a real-time list of running processes in order of CPU usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment