Skip to content

Instantly share code, notes, and snippets.

@mort3za
Last active December 1, 2020 10:51
Show Gist options
  • Save mort3za/2ee614c79f10139674d603f06a0b68ba to your computer and use it in GitHub Desktop.
Save mort3za/2ee614c79f10139674d603f06a0b68ba to your computer and use it in GitHub Desktop.
Linux Commands... http://bit.ly/m3linux
# Set permission of all files and folders. 755 and 644.
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
find ./app/cache -type d -exec chmod 777 {} \;
find ./app/logs -type d -exec chmod 777 {} \;
find ./web/upload -type d -exec chmod 777 {} \;
#find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
#find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
# Show permissions in number format in ubuntu. #linux
# http://askubuntu.com/a/430685/205156
alias perms="stat -c '%a - %n'"
@mort3za
Copy link
Author

mort3za commented Feb 19, 2017

Remove x (execute) permission for all files inside a directory:

chmod -R a-x+X directory/

@mort3za
Copy link
Author

mort3za commented Mar 26, 2017

Edit mp3 tags:
Search for id3 in Software manager and install eyeD3
remove all tags: eyeD3 --remove-all *

Set tags: eyeD3 -a artistName -A "album name" -t "title of music" -n 4 song.mp3

@mort3za
Copy link
Author

mort3za commented Mar 27, 2017

Install color emoji's #ubuntu:
source article: http://www.omgubuntu.co.uk/2016/05/emoji-one-font-linux-ppa-easy-install

sudo apt remove fonts-emojione-svginot
sudo apt install fonts-twemoji-svginot

test page: http://eosrei.github.io/emojione-color-font/full-demo.html

@mort3za
Copy link
Author

mort3za commented Jun 4, 2017

Unzip tar.gz file:
tar -xvzf filename.tar.gz

@mort3za
Copy link
Author

mort3za commented Dec 14, 2017

Change ownership of directories and files:

find . -type d -exec chown nobody:nobody {} \;
find . -type f -exec chown nobody:nobody {} \;

@mort3za
Copy link
Author

mort3za commented Dec 28, 2017

Make relative symbolic links.

(by copy folder to another place, symlinks are relative to copied folder)

cd target_location
ln -s -r ../../path/to/target/folder/or/file/ NAME_OF_SYMLINK

OR run this bash-file in target location. use * to create symlink for all files

mkdir target-folder
ln -r -s ./source-folder/*.ext ./target-folder/

@mort3za
Copy link
Author

mort3za commented Nov 4, 2018

Turn off external hard disk

udisksctl power-off -b /dev/sdX
replace sdX with your hdd name (e.g. sdb or sdc)

@mort3za
Copy link
Author

mort3za commented Nov 10, 2018

Copy files/folders between computers (by ssh)

-r (copy folders), -P 2020 (change port to 2020), -l 1024 (limit to 1Mbps)
scp source_file_name username@destination_host:destination_folder

you can change source and destination to change the direction of copy

@mort3za
Copy link
Author

mort3za commented Dec 25, 2018

zip all files in all subdirectories separately

gzip --keep --force -r dist
--keep to prevent delete original files

@mort3za
Copy link
Author

mort3za commented Mar 23, 2019

Show hardware informations

For important devices:
inxi -Fxz

Full details of CPU:
cat /proc/cpuinfo and lscpu

@mort3za
Copy link
Author

mort3za commented Apr 1, 2019

Transfer files between two linux devices by scp

on host device:
sudo apt-get install openssh-server && sudo systemctl start ssh
on client device:
scp /path/to/file-or-folder/you-want-to-transfer.ext host_username@host_ip:/path/to/destination`
Then enter host device password. Transfer will start.

Tip: You can use ssh-key instead password.

@mort3za
Copy link
Author

mort3za commented Apr 29, 2019

Pipe text to clipboard in terminal (by xclip)

(copy to terminal clipboard): echo "something" | xclip

copy to clipboard and use in other apps:
echo "something" | xclip -selection clipboard

@mort3za
Copy link
Author

mort3za commented Jun 21, 2019

Install from source

cd software_folder
./configure
make
make install # or sudo make install

more in https://www.linux.com/news/how-install-packages-source-linux/

@mort3za
Copy link
Author

mort3za commented Aug 24, 2019

screen command (toggle between multiple terminals)

sudo apt install screen
screen # then press space to continue
# run something on terminal, e.g. wget a 1TB file
# press Ctrl A + D to return to previous terminal
screen -r # to return to that terminal
# press Ctrl A + K to kill that terminal
screen -list # to see list of detached terminals
screen -r NUMBER # to attach to a terminal by it's id

@mort3za
Copy link
Author

mort3za commented Sep 6, 2019

See the temperature of CPU

cat /sys/class/thermal/thermal_zone*/temp

@mort3za
Copy link
Author

mort3za commented Sep 8, 2019

Create bootable USB

to find usb drive path: cat /dev/sd* (if it is sdb1, use sdb instead)
sudo dd if=ubuntu-18.04-desktop-amd64.iso of=/dev/sdb

https://unix.stackexchange.com/a/14047/165620

@mort3za
Copy link
Author

mort3za commented Dec 5, 2019

Switch keyboard keys

xev and press any key to find the key codes, the output is something like this:

    state 0x10, keycode 78 (keysym 0xff14, Scroll_Lock), same_screen YES,
    state 0x10, keycode 62 (keysym 0xffe2, Shift_R), same_screen YES,
    state 0x11, keycode 11 (keysym 0x40, at), same_screen YES,

Switch keys by:
xmodmap -e "keycode 78 = at"

Save to prevent reset after booting:
xmodmap -pke|egrep -e '78'
That will print a line like:
keycode 78 = at NoSymbol at
Create file ~/.Xmodmap and copy to it.

https://askubuntu.com/a/296437/205156

@mort3za
Copy link
Author

mort3za commented Dec 23, 2019

Show local IP address

hostname -I

@mort3za
Copy link
Author

mort3za commented Dec 23, 2019

Connect to ssh and use server connection

ssh -fN -D 1080 user@remote

Open an application by defined proxy

proxychains4 -f /etc/proxychains4.conf [firefox, bash or something]
https://github.com/rofl0r/proxychains-ng

@mort3za
Copy link
Author

mort3za commented Apr 10, 2020

@mort3za
Copy link
Author

mort3za commented Apr 10, 2020

Restart cinnamon when GUI is laggy

press alt + f2 anywhere, a dialog box will open, type r and press Enter.

https://www.unixmen.com/quick-tip-restart-cinnamon-crash/

@mort3za
Copy link
Author

mort3za commented Apr 20, 2020

See hardware details

sudo apt install inxi
inxi -Fxz

@mort3za
Copy link
Author

mort3za commented May 6, 2020

Fix hibernate on ubuntu 20

apt remove --purge hibernate uswsusp

# /etc/default/grub

# add resume=UUID=###
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=7ef2fd85-9a9e-4fa9-a9c9-6c541d7944c9"

and edit (or create file)

# /etc/initramfs-tools/conf.d/resume

RESUME=UUID=###

* ### is the UUID of swap partition.

sudo apt install pm-utils
sudo pm-hibernate

https://www.linuxuprising.com/2018/08/how-to-use-swap-file-instead-of-swap.html
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1819915/comments/49

@mort3za
Copy link
Author

mort3za commented May 21, 2020

Install Nvidia optimus-manager in Manjaro distro (to switch between Intel and Nvidia GPUs easily)

https://forum.manjaro.org/t/guide-install-and-configure-optimus-manager-for-hybrid-gpu-setups-intel-nvidia/92196

@mort3za
Copy link
Author

mort3za commented May 23, 2020

Get ip of websites through Tor

tor-resolve WEBSITE_DOMAIN

@mort3za
Copy link
Author

mort3za commented May 29, 2020

Fix dns leak in OpenVPN (necessary to unblock filtering)

cd /tmp & git clone git@github.com:alfredopalhares/openvpn-update-resolv-conf.git
cd openvpn-update-resolv-conf
sudo cp update-resolv-conf.sh /etc/openvpn/

Then open your ovpn config file and add:

script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf

Finally, connect to your server by:
sudo openvpn --config myconfig.ovpn

Resources:
https://wiki.archlinux.org/index.php/OpenVPN#The_update-resolv-conf_custom_script
https://github.com/alfredopalhares/openvpn-update-resolv-conf

@mort3za
Copy link
Author

mort3za commented Jul 1, 2020

Copy text between two VIMs.

Install GVim instead of vim which contains vim too, it has clipboard feature (check with vim --version | grep clipboard).
Select text and use "+y to copy text to global clipboard register. then paste as normal text.

https://stackoverflow.com/questions/4620672/copy-and-paste-content-from-one-file-to-another-file-in-vi

@mort3za
Copy link
Author

mort3za commented Jul 1, 2020

Clear DNS cache in manjaro

update /etc/hosts then sudo nscd -i hosts

@mort3za
Copy link
Author

mort3za commented Oct 25, 2020

Shred a partition (without ability to recover files)

sudo shred -v -n1 -z /dev/sdX

@mort3za
Copy link
Author

mort3za commented Dec 1, 2020

OpenVPN - exempt a website on VPN

Add this line for every website to .ovpn file:
route WEBSITE_IP 255.255.255.255 DEFAULT_GATEWAY

example for https://www.whatsmyip.org/
route 208.79.209.138 255.255.255.255 192.168.1.1
208.79.209.138 is the IP of the website.
Get the website IP by ping whatsmyip.org

Restart VPN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment