Linux commands Cheat-Sheet

A collection of commands that are frequently used when running Linux, setting up a new machine… etc.

 

Kill all processes and sessions owned by a user.

ps -fp $(pgrep -d, -u username ) 

pkill -9 -u username
ln -s absolute-path-origin abs-destinyforldername

 

 

 

sudo apt-get update sudo apt-get upgrade 
#see if the package is held back 
sudo apt-get purge gnome-session 
sudo apt-get install gnome-session startx

 

 

 

Install sublime text

http://linuxg.net/how-to-install-sublime-text-3-build-3065-on-the-most-popular-linux-systems/

$ wget http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_3065_x64.tar.bz2 
$ tar -xjvf sublime_text_3_build_3065_x64.tar.bz2 
$ sudo mv ~/sublime_text_3/ /opt/ 
$ sudo ln -s /opt/sublime_text_3/sublime_text /bin/subl Create a desktop entry: 
$ cat << EOF > ~/.local/share/applications/sublime.desktop [Desktop Entry] Name=Sublime Text Exec=subl %F MimeType=text/plain; Terminal=false Type=Application Icon=/opt/sublime_text_3/Icon/128x128/sublime-text.png Categories=Utility;TextEditor;Development; EOF Optional, to remove Sublime Text 3 (Build 3065), do: 
$ sudo rm /opt/sublime_text_3/sublime_text /bin/subl ~/.local/share/applications/sublime.desktop

 

 

 

Install python

install openssl

# wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
# tar xJf Python-3.6.0.tar.xz
# cd Python-3.6.0
# ./configure
# make
# make install

# which python3
# python3 -V

 

 

 

Add dir to PATH

Put the export declaration in ~/.bashrc. 
Example .bashrc contains: 
export PATH=/var/lib/gems/1.8/bin:/home/fraxtil/.bin:$PATH

Change GRUB boot order

edit '/etc/default/grub'

Make command line bash linux autocomplete like Matlab

Put the following lines in your ~/.inputrc:

## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forward

 

 

 

Add user to sudoers

adduser youruser sudo

apt-get install sudo

nano /etc/sudoers

Once open, look for the line that contains %sudo ALL=(ALL:ALL) ALL 
Under that line, add:
youruser ALL=(ALL:ALL) ALL

 

 

 

Ignore case when using tab completion in the terminal

gksu gedit ~/.inputrc
If you want to change the global .inputrc file, type the following command instead.

gksu gedit /etc/.inputrc

set completion-ignore-case on

Generate SSH keys

ssh-keygen -t rsa -b 4096
And copy the public key to the device from where you want to authenticate.
To allow login using that public key, cd into /home/user/.ssh/ and
cat keyname.pub >>./authorized_keys
Make sure you use >> which appends contents to the end of the file, otherwise, with > contents will be replaced.

Mount an USB flash drive

  1. List all the devices
    lsblk
  2. Find the ID
    sudo blkid
  3. Create the destination mount point
    sudo  mkdir /media/usb
  4. Mount it!
    sudo mount /dev/sdb1 /media/usb

To unmount it, just

sudo umount /media/usb

 

 

 

Use GitHub

  1. Generate SSH keys
  2. Add it to your account

 

Find a file

find . -type f -name "abc*" 
Many more, in particular for KALI Linux at TheHackToday.