To run a mysql query directly from command line, without entering the interactive mode, use -e flag, like below
$ mysql -u user -p -e 'show tables;' mydbname
Linux is for everybody. Lets enjoy it.
To run a mysql query directly from command line, without entering the interactive mode, use -e flag, like below
$ mysql -u user -p -e 'show tables;' mydbname
To download torrents using a command line, the easiest tool to use is transmission-cli. This tool is available in debian based distro and redhat based distro alike.
To use this tool, you have to install it first.
In debian based distro:
$ sudo apt install transmission-cli -y
In redhat based distro:
$ sudo yum install transmission-cli -y
To use it with torrent file, first download the torrent file, and then run transmission-cli against the file
$ wget https://releases.ubuntu.com/20.04/ubuntu-20.04.2-live-server-amd64.iso.torrent
$ transmission-cli ubuntu-20.04.2-live-server-amd64.iso.torrent
To use it with magnet link, just run transmission-cli against the magnet link
$ transmission-cli magnet:?xt=urn:btih:eb6354d8d9b9427458af8bee90457101a4c1e8e3&dn=archlinux-2021.05.01-x86_64.iso
Sometimes, when you are setting up a linux machine, there is a need to know what IP our machine is being connected to the public internet. There are many websites that provide this kind of service, but below are some of my favorites that work well with commands.
To be able to use this, we need a text based web browser. We will use curl in this case. Install curl if your machine does not have one.
# yum install curl -y
To get our ip address, run curl like below. Choose whichever you like :).
$ curl ipecho.net/plain
210.210.210.210
$ curl icanhazip.com
210.210.210.210
{
"ip": "210.210.210.210",
"city": "Kuala Lumpur",
"region": "Kuala Lumpur",
"country": "MY",
"loc": "3.1390,101.6869",
"org": "AS4818 Digi Telecommunications Sdn. Bhd.",
"postal": "50505",
"timezone": "Asia/Kuala_Lumpur",
"readme": "https://ipinfo.io/missingauth"
}
$ curl ipinfo.io/ip
210.210.210.210
$ curl ipinfo.io/city
Kuala_Lumpur
Sometimes we want to spawn off a few new instances, with the same spec and operating systems, but we do not want to go through the hassle of setting up each OS manually, and then update it one by one. In order to do that efficiently, openstack provides a very good way, which is to create an image from a running instance, and this image can be used to spawn off new instances afterwards.
Before we turn any instance to an image, we need to know its instance ID
$ openstack server list
$ openstack server image create --name centos7-updated-20180525 21e78f23-8b67-423a-9622-d46c8487f829
$ openstack image list
In order to create new instance (it is called server in openstack command), you need to know beforehand a few information to feed to the create instance command. Refer below for those information:
check available flavor
$ openstack flavor list
$ openstack image list
$ openstack network list
$ openstack security group list
$ openstack keypair list
$ openstack server create \
--image centos-7-20180520 \
--key-name my-keypair \
--flavor m1.medium \
--security-group defaults \
--network private-140 \
thenewinstancename
$ openstack server list
# ls -l
total 52
drwxrwxrwx 2 root root 41 Jan 14 2013 archive
drwxr-xr-x 2 root root 3072 Aug 3 2013 bin
-rw-r--r-- 1 root root 578 Jan 14 2013 README-archive.txt
lrwxrwxrwx 1 root root 3 Feb 17 2013 run -> tmp
The easy way to check if a site is available, is by using curl. For example, if you want to check whether www.google.com is available or not, jut run:
$ curl -I www.google.com HTTP/1.1 200 OK Date: Thu, 25 Apr 2013 06:03:06 GMT Expires: -1 Cache-Control: private, max-age=0 Content-Type: text/html; charset=ISO-8859-1 Set-Cookie: PREF=ID=f4eacf44ddfe9913:FF=0:TM=1366869786:LM=1366869786:S=pD4jQT9xbgTOjuKG; expires=Sat, 25-Apr-2015 06:03:06 GMT; path=/; domain=.google.com Set-Cookie: NID=67=KULBN37y3Mw7TIYNurxqV3L9OAm0gaj4VhRxz0_OsayoTS8C7nPN9QLCMovAzkVxhKfoop1EcHjWiBWjv7Vxl2C5iQ-Z8J0zcVtv4YfrJXs2ypRegbp2Y8MPcJjTyX1p; expires=Fri, 25-Oct-2013 06:03:06 GMT; path=/; domain=.google.com; HttpOnly P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info." Server: gws X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN Transfer-Encoding: chunked
with -I for fetching the HTTP-header only. In this case the return code is 200, and it means the site is available.
I found a weird error message when I tried to delete some files in my linux box today. The command I used was
sudo rm -rf *.jsto delete some .js files, and I got an error message:
sudo: unable to execute /bin/rm: SuccessAfter googling around, I found this wonderful site, and the solution is to use find coupled with -exec flag rather than rm:sudo find . -iname '*.js' -exec rm {} \;
The problem is, according to the site, was caused by buffer overflow when expanding the *.The single quote that we used in the find command will prevent it from expanding and causing overflow. So, that's all folks.