96
rated 0 times
[
96]
[
0]
/ answers: 1 / hits: 160700
/ 1 Year ago, fri, february 3, 2023, 7:39:20
I am using Ubuntu 12.04. Is there any way to lock the screen or session from a terminal command or script?
More From » command-line
I am using Ubuntu 12.04. Is there any way to lock the screen or session from a terminal command or script?
Simple:
gnome-screensaver-command -l
The following can also work, if the screensaver is set to lock when activate (see screensaver settings), since the command activates the screensaver:
gnome-screensaver-command -a
You can add an alias to the command by editing the file .bashrc
(or .bash_aliases
) in your home directory:
gedit $HOME/.bashrc
and adding the following line:
alias lock='gnome-screensaver-command -l'
Then from terminal:
source .profile
This will activate the alias.
From now on, the alias lock
in a terminal will have the effect of locking the screen.