Misc. Shell Commands

If you don’t have X11 (Wayland, Mir, or any other display server) or you prefer accessing this page on a Terminal, you can access it using Emacs.

 $ emacs -nw
 M-x → eww → https://wp.me/P7yg6l-1b
# install a package from backports on Debian
$ sudo aptitude -t jessie-backports install emacs24

# removing the residual config files
$ aptitude -F %p search '~c' | xargs sudo dpkg -P
Compression and Extraction:
# extract a compressed file (tar)
   $ tar --extract --gz -vf file.tar.gz
   $ tar --extract --bz -vf file.tar.bz2 --directory /tmp/
   # -v verbose
   # -f file

# compress into a file (tar)
   $ tar --create --lzma -vf new-file-name.tar.lzma directory1-to-compress/ file1-to-compress.c
   # -v verbose
   # -f file
Pastebin Service:
 $ cat /etc/apt/sources.list | nc paste.ubuntu.ir 1337
$ lualatex file.tex
# download all files
$ wget -m -p -E -k -K -np http://download.virtualbox.org/virtualbox

# download only tar.gz and deb files
$ wget -A tar.gz,deb -m -p -E -k -K -np http://download.virtualbox.org/virtualbox
# updating and dist-upgrading a Debian system every 10 minutes
$ sudo crontab -e
# Edit this file to introduce tasks to be run by cron.
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# For more information see the manual pages of crontab(5) and cron(8)
# m h  dom mon dow   command

*/10 * * * * /home/salman/.crontabofmine/auto-update-upgrade.sh >> /home/salman/.crontabofmine/auto-update-upgrade.log
$ cat ~/.crontabofmine/auto-update-upgrade.sh


echo ''
echo 'BEGIN-------------------------'
apt update
echo ' -------'
apt -y dist-upgrade
echo 'END---------------------------'
echo ''
# changing the default text editor at the system level.
$ sudo update-alternatives --config editor
Managing users:
$ sudo adduser salmanmoh
# granting sudo privilege
$ sudo adduser salmanmoh sudo
# remove the user from the group 'sudo'
$ sudo deluser salmanmoh sudo
chroot and debootstrap:
# install prerequisites 
$ sudo apt install binutils debootstrap

# build the chroot; using Switzerland (ch) mirror
$ sudo debootstrap --arch amd64 jessie /srv/chroot/jessie http://ftp.ch.debian.org/debian

# enter chroot
$ sudo chroot /srv/chroot/jessie

# prevent all daemons from being started in the chroot
$ sudo chroot /srv/chroot/jessie
$ cat > ./usr/sbin/policy-rc.d <<EOF
exit 101
$ chmod a+x ./usr/sbin/policy-rc.d
git identity config:
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
# finding where the distro mirrors are located.
$ host ftp.ch.debian.org

ftp.ch.debian.org is an alias for debian.ethz.ch.
debian.ethz.ch is an alias for plattenberg.ethz.ch.
plattenberg.ethz.ch has address
plattenberg.ethz.ch has IPv6 address 2001:67c:10ec:3dd1::42
# show hostname
$ hostname
# show ip address of the hostname
$ hostname -I
# find out the font aliased to monospace
$ fc-match monospace
# unarchive a variety of formats
$ unar sample.zip
$ unar sample.tar.xz
$ unar sample.tar.bz2
# put Tor Browser in the desktop menu
$ ./start-tor-browser.desktop --register-app
ssh key authentication
# on server
$ mkdir .ssh
$ chmod 700 .ssh
# copy your public key here
$ nano .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys
# change default Octave directory.
# by using it we can prevent `octave-workspace` to be created in HOME directory 
# and instead it will be created in /tmp directory.
$ echo "cd (\"/tmp\")" > ~/.octaverc
# fix "network 'default' is not active" error in libvirt
$ sudo virsh net-list --all
$ sudo virsh net-start default

# list all vms 
$ sudo virsh list --all

# start a vm
$ sudo virsh start ubuntu1804

# find IP address of the guest machine 
$ sudo virsh domifaddr ubuntu1804 --full

# list all running vms
$ sudo virsh list
# find anything that starts with 'my' in the current directory
$ find . -name 'my*'
# report file system disk space usage
# the whole hard disk
$ df -h
# estimate file space usage
# the current directory
$ du -sh
# extracting into an existing directory
$ unzip test.zip -d extract-dir
Creating GPG Keys
$ gpg --full-gen-key

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.