Skip to content

Instantly share code, notes, and snippets.

@stefanbirkner
Last active August 12, 2025 11:17
Show Gist options
  • Select an option

  • Save stefanbirkner/b64bbbbb4fe99f7ffea7 to your computer and use it in GitHub Desktop.

Select an option

Save stefanbirkner/b64bbbbb4fe99f7ffea7 to your computer and use it in GitHub Desktop.
My Bash Cheat Sheet

Show the exit code of the last command:

echo $?

Reuse the last part of the previous command:

new_command !!:$

Remove new line from end of file

perl -pi -e 'chomp if eof' <filename>

Rename files from upper case filename to lower case

for i in *; do mv $i `echo $i | tr [:upper:] [:lower:]`; done

Show the 10 most used commands:

history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head

Change file suffix

rename 's/\.old$/\.new/' *.old
find . -name "*.old" -exec rename 's/\.old$/.new/' '{}' \;

Recursive search and replace

find . -type f -exec sed -ie 's/old/new/g' {} \;

Reorder the columns of a CSV file (using , as separator)

awk -F, '{print $2,$1,$3}' OFS=, file

Start a web server that serves the current directory

python -m SimpleHTTPServer <port>

Make a program continue to run after logout from SSH

$ myprogram

Press <Ctrl>+Z

[1]+  Stopped                 myprogram
$ disown -h %1
$ bg 1
[1]+ myprogram &
$ logout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment