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.) If you want to convert a batch of photo images, for example all .png files in “Pictures” folder, use try this command instead:

cd ~/Pictures && for file in *.png; do convert $file ${file%.png}.jpg; done

4.) 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 24.04 Server

Last updated: April 22, 2024

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.

UPDATE: The commands in this tutorial are tested and also works in Ubuntu 24.04.

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

If the command not found, run sudo apt install ncal to install it.

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, use command:

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

NOTE: your Ubuntu server may enabled network time synchronization. The command above will NOT work until you disable it by using command:

sudo timedatectl set-ntp no

To re-enable network time synchronization, run command:

sudo timedatectl set-ntp yes

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.