Skip to content

Instantly share code, notes, and snippets.

@ralphcrisostomo
Last active November 11, 2021 03:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralphcrisostomo/6eb07669f1b99ff58aae to your computer and use it in GitHub Desktop.
Save ralphcrisostomo/6eb07669f1b99ff58aae to your computer and use it in GitHub Desktop.
Bash Commands

Bash Commands

Initial Setup

sudo apt-update
sudo apt-upgrade

Source List

# Update your source.list if having an error
# vi sudo vim /etc/apt/sources.list

deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi

Raspberry Pi

Transmission

Share HDD on network

#
# `sudo apt-get install samba samba-common-bin`
# `vi /etc/samba/smb.conf` 
#
# Insert at the end of the file :
#

[Torrentbox]
comment = Public Shares
path = /media/Torrent
writeable = Yes
only guest = Yes
create mask = 0777
directory mask = 0777
browseable = Yes
public = Yes

Install

Screen

sudo apt-get update
sudo apt-get install tmux
sudo apt-get install vim-nox

NTFS

sudo apt-get install ntfs-3g

Create Bootable USB

OSX

sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/OSX\ Yosemite\ 10.10 --applicationpath /Applications/Install\ OS\ X\ Yosemite.app --nointeraction

Windows Format

  • 399438MB = 390GB

Files

Copy files from a text file

sudo rsync -avr -P --files-from=move.txt . /media/Anime01/Anime

Find files with name and extention

find /source/ | grep name | grep .extention | while read -r line; do echo "$line"; done

Copy files

for file in /source/*; do rsync -av -P "$file" /destination; done

Copy files with regex

for file in /source/*; do if [[ "$file" =~ * ]]; then rsync -av -P "$file" /destination; fi; done

Loop command until it succeed

until git push; do echo "Retrying..."; done

Remove empty directories

du -h . | grep ^0 | cut -f2 | while read -r line; do rm -rfv "$line"; done

Backup files workflow

sudo find /source > move-files.txt
sudo rsync --ignore-existing -raz --progress --files-from=move-files.txt /source /destination

Count Files

ls | wc -l

Count Files Recursive

find . -type f | wc -l

Hard Disk

Auto Mount

http://posts.danharper.me/raspberry-pi-2-auto-mount-usb/

sudo vi /etc/fstab

Utilities

$ df -h -
$ du -h -
$ blkid -
$ lsblk

Show external hd uuids

$ ls -al /dev/disk/by-uuid

Display the mounted filesystems table

df -h

Unmount the device as necessary

sudo umount /path/to/device

Create an NTFS filesystem

sudo mkntfs /dev/sda1
sudo ntfslabel /dev/sda1 MyDrive

Create an Ext4 filesystem

sudo mkfs.ext4 /dev/sda1
sudo e2label /dev/sda1 MyDrive

Format HD

fdisk /dev/sda

Check Boot Sector

sudo apt-get install ntfsprogs
sudo ln -s /bin/ntfsfix /sbin/fsck.ntfs
sudo ln -s /bin/ntfsfix /sbin/fsck.ntfs-3g
fsck /dev/sda1
shutdown -rF now

Check Boot Sector on Windows

chkdsk /f

OSX Copy ISO files to thumbdrive

sudo dd if=/path/to/image.iso of=/dev/diskN bs=1m

OSX Create ISO from a directory

hdiutil makehybrid -iso -joliet -o Image.iso ImageDirectory

Network

Get Public IP

curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//' 

Git

Create git local branches from origin

git branch -a | grep remotes | while read -r line ; do git checkout ${line//remotes\/origin\//} ; done

WIFI for newly installed Debian

/etc/network/interface

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet manual

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

/etc/wpa_supplicant/wpa_supplicant.conf

network={
ssid="PLDTMyDSL"
psk="******"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment