Archive for the ‘Bash’ Category

How to Change Lid Close Action in Ubuntu 18.04 LTS

September 5th, 2019 No comments

Open terminal by pressing Ctrl+Alt+T or searching for “Terminal” from start menu. When it opens, run command:

sudo gedit /etc/systemd/logind.conf

When the files opens, uncomment the line #HandleLidSwitch=suspend by removing # in the beginning, and change the value to:

  • HandleLidSwitch=poweroff, shutdown / power off when lid is closed.
  • HandleLidSwitch=hibernate, hibernate when lid is closed (need to test if hibernate works).
  • HandleLidSwitch=ignore, do nothing.
  • HandleLidSwitch=suspend, suspend laptop when lid is closed.

Save the file and finally restart the Systemd service to apply changes via command:

systemctl restart systemd-logind.service
Categories: Bash, Linux, Ubuntu Tags:

Reboot linux at specific time

August 13th, 2019 No comments

Sometimes you want to reboot a server in the middle of the night. With linux it’s as simple as this command:

shutdown -r 04:00

Which will reboot the machine at 4 am in the morning. If you need to abort the reboot, use the following to abort the reboot:

shutdown -c
Categories: Bash, Linux, Red Hat / CentOS, Ubuntu Tags:

Mount exFAT in Ubuntu 18.04

August 8th, 2019 No comments

The exFAT file system is created by Microsoft to overcome the 4GB file size limit in FAT. To mount such an partition you need to enable exFAT. Otherwise you’ll get an error saying can’t mount unknown filesystem type “exfat”. In Ubuntu 18.04 it’s simple, just open a terminal and type:

sudo apt install exfat-fuse exfat-utils

If this doesn’t work you might need to add the “universe” repository first. Here’s an example followed by a mount of the device at /dev/sdb1. Replace this device with your own device:

sudo add-apt-repository universe
sudo apt update
sudo apt install exfat-fuse exfat-utils
sudo mkdir /mnt/myEXFAT
sudo mount /dev/sdb1 /mnt/myEXFAT

To list devices and their partitions, use the command:

sudo parted -l

Beware that exFAT can’t handle certain characters in the file names, like “:”. If you need to rename multiple file names you can modify the below example that replaces all “:”-characters with an underscore “_” in the current directory:

find . -depth -maxdepth 1 -name '*:*' -execdir bash -c 'mv -- "$1" "${1//:/_}"' bash {} \;

Categories: Bash, Linux, Ubuntu Tags:

Upgrade Ubuntu Linux using command line

August 6th, 2019 No comments

To upgrade Ubuntu Linux open up a terminal and type:


The old way using apt isn’t needed in Ubuntu to upgrade the system. dist-upgrade has been superseded in Ubuntu by full-upgrade.

The do-release-upgrade command can be run as an user with admin rights without sudo. The user password will be asked when starting the command. The system will then make different checks before the upgrade starts. If using SSH an additional port will be opened on port 1022 that can be used if the ordinary SSH-tunnel are broken during the update.

Categories: Bash, Linux, Ubuntu Tags:

Formattera en USB-pinne i Ubuntu

August 11th, 2012 No comments

Kolla först vilken enhetsnamn pinnen har. Starta ett terminalfönster och skriv:

sudo fdisk -l



Sedan när du kollat namnet måste du avmontera pinnen. I mitt fall hette enheten för USB-pinnen /dev/sdb

umount /dev/sdb

Formattera nu pinnen. Jag väljer att formattera den med VFAT så den går att använda i Windows m.fl. operativsystem.

sudo mkfs.vfat /dev/sdb1

Om du vill döpa om namnet på pinnen i kommandoradsläge kan du installera mtools

sudo apt-get install mtools

Sedan kan det vara bra idé att hoppa över mtoolskontrollen av pinnen då man ibland får ett felmeddelande not a multiple of sectors per track (62)

echo mtools_skip_check=1 >> ~/.mtoolsrc

Döp sedan om USB-pinnen med följande kommando

sudo mlabel -i /dev/sdb1 ::namn



Categories: Bash, Linux Tags:

Prepare Linux for source compile

August 11th, 2012 No comments

1. Install packages to build the kernel modules

sudo apt-get install autoconf automake binutils make cpp gcc linux-headers-$(uname -r)

2. Find out where the kernel headers are (you may need this later)

ls -d /usr/src/linux-headers-$(uname -r)*/include

i.e. /usr/src/linux-headers-2.6.31-14-generic-pae/include

i.e. /lib/modules/2.6.31-14-generic-pae/build/include

3. Get the kernel source

sudo apt-get build-dep linux-image-$(uname -r)

sudo apt-get source linux-image-$(uname -r)

Categories: Bash, Linux, Programmering, Ubuntu Tags:


August 11th, 2012 No comments

För att lägga till SSH stöd i DNS-323:

För att lägga in ett RSYNC jobb via CRON:

DNS323 + Duplicity = Encrypted Offsite Backup BLISS!:

Modding Cron on the D-Link DNS-323 using funplug-0.3:

Modding ‘crontab’ on Fujitsu Q700:

vi /etc/config/crontab

crontab /etc/config/crontab

Categories: Bash, Linux Tags:

Move your Ubuntu/Debian installation to another computer

August 11th, 2012 No comments

To move your Ubuntu/Debian installation to another computer:

1. Start a terminal window on your old computer

2. ‘dpkg –get-selections > ~/instsoft.log’

3. Copy all files from your home folder to an external USB-drive

. (if you use Nautilus instead, remember to press CTRL+H to get all hidden files)

On the new computer:

1. Install the new computer with the same Linux version as the old one

2. Enter the folder containing your home folder copy (from step 3 above)

3. Start a terminal window

4. ‘sudo apt-get install dselect’

5. ‘sudo dpkg –set-selections < instsoft.log’

6. ‘sudo dselect’

7. Select ‘i’ and press Enter to start the software installation

. (internet access required)


To copy the entire disk to another disk (with partitions already prepared):

1. Mount the destination disk: sudo mkdir /mnt/extusb && mount -t ntfs-3g /dev/sda2/mnt/extusb

2. Copy all files: sudo cp -rpx / /mnt/extusb

3. Install Grub2 on the new disk

sudo mount /dev/sda2 /mnt

sudo mount –bind /dev /mnt/dev

sudo chroot /mnt

grub-install –recheck /dev/sda

dpkg-reconfigure linux-image-`uname -r`

Categories: Bash, Linux Tags:

Check which Linux version

August 11th, 2012 No comments

uname -a

cat /etc/lsb-release (shows Ubuntu version)

cat /proc/version

cat /proc/cpuinfo

cat /etc/issue

Categories: Bash, Linux Tags:

How to figure out which process is listening on a specific port

August 11th, 2012 No comments

This website explained it:

Let’s say we want to find our what process is tied to port 53.

First, use the following command to find if the port is is use or not

netstat -an | grep 53

#Then, use the following command to find which process is using the port

fuser -n tcp 53

This will return something like ’53/tcp: 5006′.

it shows pid.

After that, we can find the full process information.

ps -ef | grep 9113

If you know shell you can use the below in a shell script to put all these step together

status=`netstat -an |grep $1`
if [ "$status" == "" ]; then
echo “port $1 is free”
ps -ef |grep `fuser -n tcp $1`

Or if you’re running linux download lsof

lsof -i :53


lsof -i :1226

Or you and use grep

lsof | grep [process name]
Categories: Bash, Linux Tags: