Archives For November 30, 1999

This simple tutorial will show you how to convert PNG to JPG in Ubuntu, so that it reduce the memory size and speed up loading image time.

1.) Install the required package by running below command in terminal:

sudo apt-get install imagemagick

2.) Then you can convert an .png image to .jpg format via below command. It takes “ubuntuhandbook.png” in the current directory and creates a JPEG image from it.

convert ubuntuhandbook.png ubuntuhandbook.jpg

You can also specify a compression level for JPEG images.

convert ubuntuhandbook.png -quality 90 ubuntuhandbook.jpg

3.) To convert all PNG files into JPEG files with that same filename but a different suffix. However be warned that if existing file with the same name will be over-written.

mogrify -format jpg *.png

Change Date and Time on Ubuntu 12.04 Server

Last updated: July 3, 2013

time

This simple tutorial is going to show Ubuntu beginners how to display and change date and time on Ubuntu Linux both Server and Desktop.

To display data and time, use date command:

date

Sample output:

Wed Jul 3 20:59:28 CST 2013

To display calendar, use cal command:

cal

Sample output:

July 2013
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

To change date and time:

sudo date -s "4 June 2020 18:00:00"

Want to change the MAC address of your network card? In this tutorial I’ll show you how to do this in Ubuntu as easy as a few commands in terminal.

My laptop has two cards on eth0 and wlan0, here I’m going to change the card on eth0.

Press Ctrl+Alt+T to open up a terminal, then get started with below steps:

1.) You may run command to check you network cards, and backup original MAC address for easy to revert back.

ifconfig

2.) Turn the network card down.

sudo ifconfig eth0 down

3.) Change MAC Address:

sudo ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE

4.) Start your network card:

sudo ifconfig eth0 up

That’s it!

Most Linux remembers the commands that you ran in terminal or command console. It’s useful for finding out what you’ve done to the system, especially for server.

For frequently used command with a long code, you don’t need to type all the code again and again. You can re-run then using history commands option, by just a few key presses.

List history commands

To find out what commands you’ve run in your Linux, simply run command:

history

In the output, you’ll see a large list of commands that you ran before. And, each command has number at its beginning.

If you have too much history commands, it may be hard to browse and find out a certain command. In the case, add grep option to filter. For example, run command below to find out history commands that include apt install.

history | grep "apt install"

For choice, you may also add -E option after grep to filter with regular expressions.

Re-Run a History Command

Once you got the history command, that’s too long or you don’t remember, you can simply re-run it by typing !number, where number is the number in front of that command in history output.

For example, run command below will re-run sudo apt install gimp, according to last screenshot. And, in terminal window it outputs what’s going to run immediately after you hitting Enter. If it’s a sudo command, it will also ask for password authentication.

!1057

To avoid careless mistakes, you may use the command below instead by adding :p in end to first preview that history command:

!1057:p

Then re-run !1057 if you confirm it is indeed the command you want.


For the last command, without finding out the history number, just use command below will re-run it:

!!

And, you can use it along with other commands. For example, re-run last command with sudo permission:

sudo !!

Or re-run last command, then poweroff:

!! && poweroff

There are also more choices, for example, re-run the last command start with given string:

!sudo

The command will re-run the last command start with sudo.

And, all the commands above can follow with :p to preview command before running.