Skip to content

Instantly share code, notes, and snippets.

@nobitagit
Last active September 6, 2017 20:36
Show Gist options
  • Save nobitagit/eef3aa8f4176568890d7 to your computer and use it in GitHub Desktop.
Save nobitagit/eef3aa8f4176568890d7 to your computer and use it in GitHub Desktop.
some unix commands i frequently use/sometimes forget
A basic `chmod` recap:
stuff like `chmod a+x fileName` ecc http://www.thegeekstuff.com/2010/06/chmod-command-examples
# to delete the whole line type
# CTRL + U
# to reverse search a past command (fuzzy searches in the history of all tabs)
# CTRL + r
#similar to ls, gives some info about each file/dir in the current dir
file *
# mark this file as executable (x) by all (a)
chmod a+x start_me.sh
# other opts are user|group|others
chomd [u|g|o]
# write read execute
chmod a+[w|r|x]
# save current directory path into a temporary bookmark
# see: http://cli.learncodethehardway.org/book/ex8.html
pushd ./
# do stuff like cd into whatever dir you need..
# [..after that...]
popd
# you'll be taken back to that dir you saved before
#show calendar of this month
cal
#show calendar of feb 2015
cal 2 2015
#count lines/words/letters in a file
wc file.txt
# outputs
# 3 6 24 txt.txt
# as 3 lines / 6 words / 24 letters
#
# wc flags are :
# -l - count lines
# -w - count words
# -c - count chars
# run last command
!!
# run last command as root
sudo !!
# run last command starting with a specific word
!<word>
# run command but don't save it in the history
<space>command
# create a dir and cd into it
# (The $_ command variable contains the most recent parameter. So if a user were to type the following at the command line: echo foo bar && echo $_ baz, then the output would be as follows:
# foo bar
# bar baz
mkdir myDir && cd $_
# list files that match these requirements
ls | grep "^a" # files beginning with a
find . -name "a*" # files beginning with a (looks in subdirectories as well)
# Suppress success being passed to stdout
# http://stackoverflow.com/questions/18062778/how-to-hide-command-output-in-bash
somecmd somefile.js > /dev/null # only success is suppressed. Error is still logged
# make dir newProject with this file structure:
# hn -|
# |- build -|
# | |- js
# |- css
# |- html
# |- img
# |- js
#
mkdir -p newProject/{build/js,css,html,img,js}
# create a file together with its parent dirs
mkdir onedir/newdir/newdir2/newdir3 && touch $_/filename.txt
# redirect to file (OVERWRITES the content in non-empty)
cat somefile > new_file.txt
# redirect to file (APPENDS the content in non-empty)
cat somefile >> new_file.txt
# on OSX hold CMD and click on link to open it in the browser
Listening at http://localhost:7770
# curl include headers
curl -i www.google.com
###### =>
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: http://www.google.co.uk/?gfe_rd=cr&ei=q1iYV7z6C-XR8gfDz4GgBw
Content-Length: 261
Date: Wed, 27 Jul 2016 06:46:03 GMT
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.uk/?gfe_rd=cr&amp;ei=q1iYV7z6C-XR8gfDz4GgBw">here</A>.
</BODY></HTML>
########
# see disk used for a certain directory
[sudo] du -chs * [| tail] # where -h is human readable
# list all running jobs along with ID
jobs -l
# kill a certain job by id
kill -9 {job_id}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment