LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-25-2013, 02:16 PM   #1
sayhello_to_the_world
Member
 
Registered: May 2013
Posts: 229

Rep: Reputation: Disabled
how to switch off a linux machine with shortcuts


hello dear linux-experts

i am new to the forums and also pretty new to linux too.

How to switch off a linux machine with shortcuts

in other words. i want to switch off the machine (opensuse) wiht the terminal - is this doable!?` With some commands?
 
Old 06-25-2013, 02:26 PM   #2
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Code:
# poweroff
# shutdown -h now
 
Old 06-25-2013, 02:27 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
shutdown -h now
 
Old 06-25-2013, 02:48 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,998

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
There are ways to do that also from power button. Many systems will do a proper shutdown if power button is pushed.

An alias or script could be used to simply issue the command "off" for example using the above references.

Last edited by jefro; 07-08-2013 at 11:02 AM.
 
Old 07-05-2013, 08:50 AM   #5
sayhello_to_the_world
Member
 
Registered: May 2013
Posts: 229

Original Poster
Rep: Reputation: Disabled
hello dear jefro

thx alot

Quote:
Originally Posted by jefro View Post
There are ways to do that also from power button. Many systems will do a proper shutdown if power button is pushed.

An alias or script could be used to simple issue the command "off" for example using the above references.

well i need some ways that do not do harm to the drive.

is this doable with some shortcuts !?
 
Old 07-05-2013, 09:08 AM   #6
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
is this doable with some shortcuts !?
Yes. Just write a one line shell script having
Quote:
shutdown -h now
which is made as an executable. Now create a shortcut to run this script.

OK
 
Old 07-05-2013, 09:27 AM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
I dont know which shortcuts you're looking for, but you can shutdown your macchine using above mentioned commands i.e. poweroff and shutdown. Additionally, you can create alias of these commands to make commands little short. For example, for reboot the machine (as root only) you can:
Code:
~# alias r='shutdown -r now'
To shutdown:
Code:
~# alias s='shutdown -h now'
In this way, when you will press r system will reboot, and s will shutdown the machine.
 
1 members found this post helpful.
Old 07-05-2013, 10:11 AM   #8
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
@sayhello_to_the_world

Just a thought...

If you are regularly working in terminal, how hard is it to type 'poweroff' to switch-off the machine.

And if you are mostly working on GUI, then what's the point in opening the terminal and typing 'poweroff' to switch-off, when you can easily just hit poweroff button.

But, if you are looking for emergency shutdown or reboot, then just read referred link. Be careful though while playing on that.

How to Reboot or halt Linux system in emergency
 
Old 07-05-2013, 10:21 AM   #9
sayhello_to_the_world
Member
 
Registered: May 2013
Posts: 229

Original Poster
Rep: Reputation: Disabled
hekki dear mddesai

many many thanks

i am looking for an emergency - power off -or shut down.

why: i run a q 210 notebook from samsung

this is well known for a backlight issue. - all runs well . but suddenly all gets dark - the display does not display any more.


for more than 6 months i had no issues here. All went well - but in the last few days i had some issues again.
suddenly the display was dark

Well - if i swith off the notebook and switch on all goes well.

BUT - i need to have a emergence-switch-off version!!!!!


so - the hint on the command-line- way is good - but you have to know that - if all is dark - i cannot see what i am doing and where the commmmand-line is!?


now i look at the next version - the emergency version of power off-.- ie your link!


above alll

many many thanks for all your hints and for all you do!!

i love this forum

greetings say
 
Old 07-05-2013, 01:31 PM   #10
justjustin
LQ Newbie
 
Registered: Jul 2013
Posts: 3

Rep: Reputation: Disabled
Here we use shutdown -g0 -h and it works great! We also run the sync command before emergency shutdowns to synchronize the data on the disk with the memory.
 
Old 07-06-2013, 05:16 PM   #11
selfprogrammed
Member
 
Registered: Jan 2010
Location: Minnesota, USA
Distribution: Slackware 13.37, 14.2, 15.0
Posts: 635

Rep: Reputation: 154Reputation: 154
I shutdown from console all the time. Terminal is the same.

>> who

To see how many consoles I have running so I can close any open editors.
If not closed they create save files.

When logged in as Root, then

>> halt

Halt will invoke shutdown now in most situations.

When logged in as a user then do not have privilege to run halt.
Could change privileges, but easier to use the three finger shutdown.

>> sync
Then (ctrl-alt-del)
CTRL-ALT-DEL will be intercepted and will invoke the halt program.
This key interception and the program it invokes is setup in someplace in /etc.
In the terminal console you can edit key definitions for the linux console keyboard and see (and change) the response for special combinations, like CTRL-ALT-DEL.
There is also keyboard driver special key setup that can intercept it earlier.
And X11 has its keyboard special key sequence intercepts too.

Any shorter key sequence might get invoked by accident.

This mouse repeater can also be setup to invoke halt for certain mouse button combinations.
This is explained in their docs.

If the button device interface is installed then detection of a power button press can invoke any program you want.
- a short press usually invokes "suspend"
- a long press usually invokes "shutdown"

This is setup in /etc again, but I cannot remember which files.
It was already setup in Slackware. Give them a try on your machine.

Last edited by selfprogrammed; 07-09-2013 at 06:52 PM.
 
Old 07-06-2013, 07:16 PM   #12
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
There is usually a setting you can change under Power Settings (or similar) to choose what happens when you press the power button. On my netbook I have it set to "choose" but it is just as easy to set it to "shutdown" so that the power button can be used to shut the machine down cleanly. I'm using XFCE but I am sure I have seen the same choices under Gnome and KDE.
 
Old 07-07-2013, 10:29 AM   #13
selfprogrammed
Member
 
Registered: Jan 2010
Location: Minnesota, USA
Distribution: Slackware 13.37, 14.2, 15.0
Posts: 635

Rep: Reputation: 154Reputation: 154
Most every you need to know (except for X11 and KDE) is in:
/etc/inittab
>> man inittab
>> man halt
>> man shutdown

Last edited by selfprogrammed; 07-07-2013 at 10:30 AM.
 
Old 07-07-2013, 05:38 PM   #14
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
I think what you are looking for is a keyboard shortcut, right?
You can assign custom commands (in your case the "shutdown -h now" command) to keyboard shortcuts, but how to do it depends on your desktop environment.
In in the larger desktop environments (like KDE, Gnome, XFCE etc...) you can assign them through graphical tools in the system settings. In the lighter ones (like openbox, fluxbox etc...) you have to edit text configuration files.
Since shutdown requires root privileges the script you are linking the shortcut to should actually say
Code:
sudo shutdown -h now
You will then have to allow yourself to call shutdown via sudo without requiring a password. This can be done by editig the sudoers file using the command
Code:
visudo
(as root) and adding the line

Code:
ALL ALL = NOPASSWD: /sbin/shutdown
Note that this line will allow all users on your machine to shut it down, but on a home computer this should not be a problem...
 
Old 07-08-2013, 11:04 AM   #15
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,998

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
It might be possible to assign a function key to a macro but I'd go with shivaa alias or make a script.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shortcuts to switch to open applications wogri Linux - Desktop 3 02-09-2010 06:49 AM
Can you switch on a linux machine using x10? bedazzled Linux - General 14 02-01-2010 07:07 AM
KDE custom shortcuts to switch between layots ?!! slashams Debian 1 02-24-2007 04:44 PM
networking my linux machine with my xp machine through a 3com switch chefkahuna Linux - Networking 1 07-06-2005 09:01 AM
How to switch workspaces in Fluxbox via keyboard shortcuts? oxblood Linux - Software 3 01-08-2004 11:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration