Skip to content

Instantly share code, notes, and snippets.

@stevewhitmore
Last active May 15, 2020 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevewhitmore/48ef38eb5b341f76d9f06e2c0f3a1bb4 to your computer and use it in GitHub Desktop.
Save stevewhitmore/48ef38eb5b341f76d9f06e2c0f3a1bb4 to your computer and use it in GitHub Desktop.
Random useful bash things

Find

find <directory> -iname <filename>                # find files
find <directory> -type d -iname <directory-name>  # find directory
find . -name "filename" -delete                   # delete all files with given name

Grep

-i # ignore case
-r # recursive search
-l # only list files (instead of showing exactly in the file where match is found)
--include\*.fileextension # only show matches for files of specified extension

To find all java files with "some-pattern", use

grep -irl "some-pattern" --include=\*.java .

"grep: for every file ending in '.java' in this directory list those that include 'some-pattern', but only show the name and path of the file it's in and ignore case."

MySQL/Apache operations

sudo /etc/init.d/mysql start
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql restart
sudo /etc/init.d/mysql status

Replace "mysql" with whatever service name for the same operations on that service (e.g. apache2, bluetooth, etc)

Package updates

sudo apt update        # Fetches the list of available updates
sudo apt upgrade       # Installs some updates; does not remove packages
sudo apt full-upgrade  # Installs updates; may also remove some packages, if needed
sudo apt autoremove    # Removes any old packages that are no longer needed

OS Info

Any of the following will display info about the current OS

cat /etc/os-release
# or
lsb_release -a
# or
hostnamectl

To see kernel version

uname -r

xfce specific

xfce4-taskmanager    # Open up task manager
xfce4-panel -r       # Reset xfce panel (for after styling/layout change)

Trash:

To trash some_file (or folder) use

gio trash some_file

To go dumpster diving use

gio list trash://

To empty trash

gio trash --empty

tar

-z # filter the archive through gzip
-v # verbose: what's in the archive
-t # list files in archive
-x # extract contents of archive
-c # tells tar to create archive file
-f # tells tar the name of the file that's being operated on

So to compress a file, use

tar -czvf projects.tar.gz ./project*

"tar: create an archive, run it through gzip, tell me what you're compressing, and the file's name is projects.tar.gz. Do this operation on files in this folder with names starting with 'projects' ".

To extract the contents of a file, use

tar -xzvf projects.tar.gz

"tar: extract, uncompress, and tell me what you're pulling out of projects.tar.gz"

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