Bits of handy code
Some handy code which is useful when its really needed.
- pretify json via commandline
cat myfile.json | python -m json.tool
- Start Unetbootin in debian. change sudo to su accordingly.
sudo export QTX11NO_MITSHM=1 unetbootin
archlinux forum - Reset git HEAD
git reset HEAD~1
- Include full path in the output of find command for current directory
find -name "filename" -exec readlink -f {} \;
- Execute a command on the files found with find command.
find -iname "*.pdf" -exec cp "{}" /destination/directory \;
- Check progress of dd command while writing to a drive. Very useful while creating bootable pen drives Create bootable drive
dd if=[iso path] of=[device] bs=4
While the above command is running open another terminal and give this command and check output in previous terminalwatch -n5 'sudo kill -USR1 $(pgrep ^dd)'
- To encrypt file or folder from cli. make sure you have gpg and tar
tar zcvf - [file1|folder1] [file2|folder2] | gpg -c > myfiles-backup.tar.gz.gpg
this will ask for passphrase
and to decrypt
gpg myfiles-backup.tar.gz.gpg
For more details - How to come out of ssh connections that got closed or froze.
Enter, ~, .
type these on the terminal whose connection is lost - Play music from a folder and sub folders
mplayer -playlist <(find "$PWD" -name "*.mp3" -type f)
- One command to backup whole system
rsync -aAXv --exclude={"/dev/","/proc/","/sys/","/tmp/","/run/","/mnt/","/media/*","/lost+found"} / /path/to/backup/folder
for more details check this link
Arch Linux Page - Running x11 applications in wayland especially chromium
GDK_BACKEND=x11 chromium
- Get ip address from /proc without the use of any net command.
cat /proc/net/fib_trie | grep "|--" | egrep -v "0.0.0.0"| 127."
Postgresql Quick commands to create Database, Users and other tasks
Create User
CREATE USER <username> WITH PASSWORD '<password>';
Create a Database
CREATE DATABASE <database name>;
Grant Privileges to user on the Database
GRANT ALL PRIVILEGES ON DATABASE <database name> TO <user>;
Change ownership of the Database
ALTER DATABASE <db name> OWNER TO <user>;
Update user password
ALTER USER <user> WITH PASSWORD '<new password>';
Drop Database or user or table
DROP DATABASE <db name>;
DROP USER <user>;
DROP TABLE <table>;
Clear records and keep the structure of the table
TRUNCATE <table>;
Grant privileges to a table for a user
GRANT ALL PRIVILEGES ON TABLE <table> TO <user>;
Grant privileges to user for importing files (improt csv to Database)
GRANT pg_read_server_files TO <user>;