Skip to content

Latest commit

 

History

History
114 lines (66 loc) · 2.26 KB

bash.rst

File metadata and controls

114 lines (66 loc) · 2.26 KB

Bash and command line utilities

Remove all .pyc files from a project:

find . -name "*.pyc" -exec rm -rf {} \;

curl usage:

curl -v -X POST -H 'X-Auth-Token: 123qwe' -H 'Content-Type: application/json' -d @POST_email_confirmation_codes.json http://localhost:5000/v3/email_confirmation_codes
curl -v -X POST -H 'X-Auth-Token: 123qwe' -H 'Content-Type: application/json' -d '{"email": "test@example.com"}' http://localhost:5000/v3/email_confirmation_codes

Find and replace:

find . -type f -print0 | xargs -0 sed -i 's/json.loads(resp.body)/resp.json_body/g'

Cut PID from processes list output:

ps ax | grep '[k]eystone-all' | cut -f1 -d ' '

Use -B number to set how many lines before the match and -A number for the number of lines after the match:

grep -B 4 -A 2 pattern file.txt

If you want the same amount of lines before and after you can use -C number:

grep -C 3 pattern file.txt

Create tar.gz archive:

tar -czvf tarballname.tar.gz item_to_compress

Unpack tar.gz archive:

tar -xzvf tarballname.tar.gz

Download and run bash script:

bash <(curl -s https://raw.githubusercontent.com/ivankliuk/scripts/master/postinstall.sh)

or:

source <(curl -s https://raw.githubusercontent.com/ivankliuk/scripts/master/postinstall.sh)

Command line directory stack:

stack@stack:/$ dirs
/
stack@stack:/$ pushd /var/
/var /
stack@stack:/var$ pushd /var/log/
/var/log /var /
stack@stack:/var/log$ dirs
/var/log /var /
stack@stack:/var/log$ popd
/var /
stack@stack:/var$ popd
/
stack@stack:/$ popd
-bash: popd: directory stack empty
stack@stack:/$

Quickly change date:

sudo date +%Y%m%d -s "20141219"

Download and execute a script:

wget -O - https://raw.githubusercontent.com/ivankliuk/scripts/master/postinstall.sh | bash

Check exit code of the last executed command:

echo $?

Pretty-print of JSON output:

cat my_json.json | python -m json.tool

Add a user to 'wheel' group:

sudo usermod -aG wheel user123