Giter Club home page Giter Club logo

bash_hints's Introduction

bash_hints

collection of bash commands which may be useful



Assign date to variable, useful for scripts

DATE_OF_RUN=$(date +%F_%H_%M)

Date X days ago

date +%Y-%m-%d -d '1 day ago'

Find files using newer modification time than X days ago.

find /directory -newermt $(date +%Y-%m-%d -d 'X day ago') -type f

Sort a file (which has content per line) and then output as single line

sort file | tr '\n' ' '

Words seperated by spaces in a file - convert to per line and sorted

cat /tmp/ubuntu_pkgs | tr " " "\n" | sort

Copy ACL

getfacl source-folder | setfacl --set-file=- target-folder

Replace with sed recursively (from current directory)

find . -type f -exec sed -i 's/old/new/g' {} +

Find and count files in directories... using a CWD, which ONLY contains directories (note the ls -1 used to feed from CWD).

ls -1 | while read -r dir; do printf "%s:\t" "$dir"; find "$dir" -type f | wc -l; done

Add first column of numbers in file without using bc, but awk

awk '{s+=$1} END {print s}' some_filename

...an alternative to the last command, numbers printed for each line and final total.

awk '{ sum+=$1;print $1} END {print "Sum";print sum}' some_filename

Remove newlines from file1 to file2

tr -d '\n' < file.txt > file2.txt

ps - Show top10 CPU utilisation, all processes, apply formatting

ps -Ao user:50,uid,comm,pid,pcpu,tty --sort=-pcpu | head

iostat

iostat -kxh

clear page cache (sudo/root)

sync; echo 1 > /proc/sys/vm/drop_caches

sed

replace comment at the start of line (remove) identified by word baseurl

sed -e '/baseurl/ s/^#*//' file

replace content identified by word baseurl

sed -e '/baseurl/ s/old_words/new_words/' file

comment start of line

sed -e '/^.*word_to_match*/ s/^/#/' file

bash_hints's People

Contributors

ds-04 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.