Skip to content

Instantly share code, notes, and snippets.

@islomar
Last active June 10, 2019 07:57
Show Gist options
  • Save islomar/7f0c0ccb7172c62526ab to your computer and use it in GitHub Desktop.
Save islomar/7f0c0ccb7172c62526ab to your computer and use it in GitHub Desktop.
Unix commands

Linux hints and tricks

  • Create shortcut in Ubuntu-Gnome Alacarte

Memory: number of slots and maximum RAM that could be installed

sudo dmidecode -t 16 dmidecode -t memory >> show memory slots

watch free -m >> shows free memory watch -n 2 <command_to_execute> >> execute the command every 2 seconds

If you create a directory under ~/bin, everything you copy there will be in the PATH directly.

Creation of system user

addUser --system --disabled-password --shell=/bin/false jenkins

Get the MaxPermSize used in a project

jinfo -flag MaxPermSize <process_id>

jar tf *.jar >> view JAR content

Install several versions of Maven

http://dev-maziarz.blogspot.com.es/2012/09/ubuntu-1204-installing-both-maven3-and.html

Create launcher in sidebar

sudo gnome-desktop-item-edit /usr/share/applications/ --create-new

#Graphic driver apt-get purge nvidia* bumblebee*

Process Id

echo $$ >> $$ is defined to return the process ID of the parent in a subshell;

Show process running on ports

sudo lsof -i sudo netstat -tulpn | grep :<portNumber> >> you get processId (pid) sudo ls -la /proc/<pid>/exe >> you get the exact process

Free space under /boot

http://askubuntu.com/questions/89710/how-do-i-free-up-more-space-in-boot

#Grails bash completion https://grails.org/Grails%20Bash%20Completion http://pastebin.com/f52475980

ps -A

Manage services

/etc/init.d/ [start | stop | status] service [start | stop | status]

Enhance the system prompt

http://www.ibm.com/developerworks/linux/library/l-tip-prompt/

Environment variables

  • Under /etc/profile.d/, you can create an .sh file putting together some system-wide env variables.
    • E.g. under jdk.sh you can find env variables for JVM.
  • Under /etc/environment

Network

Shells

zshell

Install oh-my-zsh:
https://manuteoriginal.wordpress.com/2013/04/24/zsh-y-oh-my-zsh-en-mac-os-x/

bash

Update bashrc: . ~/.bashrc source ~/.bashrc

Copy into .bashrc:

export GIT_PS1_SHOWDIRTYSTATE=1
export PS1='\w\e[0;32m$(__git_ps1 " (%s)")\$ '

fish

  • https://fishshell.com/docs/current/tutorial.html
  • https://blog.devopscomplete.com/fishing-with-bob-the-fish-2decd3a2f87
  • A universal variable is a variable whose value is shared across all instances of fish, now and in the future – even after a reboot. You can make a variable universal with set -U
  • Modify $PATH variable: set -U fish_user_paths <path_to_be_appended> $fish_user_paths
  • Unlike other shells, fish does not have an export command. Instead, a variable is exported via an option to set, either --export or just -x.
  • You can erase a variable with -e or --erase
  • Unlike other shells, fish stores the exit status of the last command in $status instead of $?
  • Unlike other shells, fish does not use backticks ` for command substitutions. Instead, it uses parentheses
  • Unlike other shells, fish does not have aliases or special prompt syntax. Functions take their place.
    • You can see them typing functions
    • You can see the source for any function by passing its name to functions, e.g. functions ls
  • Unlike other shells, there is no prompt variable like PS1. To display your prompt, fish executes a function with the name fish_prompt, and its output is used as the prompt.
  • The equivalent to bashrc is ~/.config/fish/config.fish
  • When fish encounters a command, it attempts to autoload a function for that command, by looking for a file with the name of that command in ~/.config/fish/functions/
    • For example, if you wanted to have a function ll, you would add a text file ll.fish to ~/.config/fish/functions
  • To define aliases: $HOME/.config/fish/aliases.fish
  • Show prompt in new line: set -g theme_newline_cursor yes
  • To execute a bash script, several options:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment