Skip to content

Instantly share code, notes, and snippets.

@cosmomathieu
Last active September 2, 2021 13:42
Show Gist options
  • Save cosmomathieu/01f6ff8537633368654f69d3541d441a to your computer and use it in GitHub Desktop.
Save cosmomathieu/01f6ff8537633368654f69d3541d441a to your computer and use it in GitHub Desktop.
A collection of helpful bash commands

Bash Scripts and Commands

A collection of helpful bash scripts.

List

File Name Description
mkdirandmove.sh Creates a new folder in the current directory and then moves everything into that folder
rename-part-of-file-script.sh Rename part of a file in a directory matching a given extension

Commands

restore ll command

sudo echo -e "#! /bin/bash\nls -alF" > /bin/ll ; sudo chmod +x /bin/ll

Delete all files within a directory except for one

The following deletes all files contained within a directory except the file you pass it as a parameter.

First cd into the directory you want to delete the files. Then run the following command:

ls | grep -v "${file-to-keep}" | xargs rm

${file-to-keep} is the name of the file you want keep. E.g. ls | grep -v "backup.tar.gz" | xargs rm

#!/bin/bash
# Creates a new folder in the current directory and then moves everything into that folder
#
# Usage: sudo bin/magento module:status | grep "TemplateMonster_" | while read line; do sudo bin/magento module:enable "$line"; done;
mkdir newfolder && ls -a | grep -v "newfolder" | grep -v "^\.$\|^\.\.$" | while read line; do mv "$line" newfolder/; done;
# Rename part of a file in a directory matching a given extension
# rename s/${search}/${replace}/ ./*.${ext}
rename s/RerunReason/AdjustmentReason/ ./*.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment