LinuxQuestions.org
Register a domain and help support LQ
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, 03:16 PM   #1
sayhello_to_the_world
Member
 
Registered: May 2013
Posts: 220

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, 03:26 PM   #2
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 516

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

Rep: Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001
shutdown -h now
 
Old 06-25-2013, 03:48 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 15,684

Rep: Reputation: 2260Reputation: 2260Reputation: 2260Reputation: 2260Reputation: 2260Reputation: 2260Reputation: 2260Reputation: 2260Reputation: 2260Reputation: 2260Reputation: 2260
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 12:02 PM.
 
Old 07-05-2013, 09:50 AM   #5
sayhello_to_the_world
Member
 
Registered: May 2013
Posts: 220

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, 10:08 AM   #6
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 813

Rep: Reputation: 195Reputation: 195
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, 10: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, 11:11 AM   #8
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 516

Rep: Reputation: 139Reputation: 139
@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, 11:21 AM   #9
sayhello_to_the_world
Member
 
Registered: May 2013
Posts: 220

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, 02: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, 06:16 PM   #11
selfprogrammed
Member
 
Registered: Jan 2010
Location: Minnesota, USA
Distribution: Slackware 13.37
Posts: 291

Rep: Reputation: 55
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 07:52 PM.
 
Old 07-06-2013, 08:16 PM   #12
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 6,313

Rep: Reputation: 1724Reputation: 1724Reputation: 1724Reputation: 1724Reputation: 1724Reputation: 1724Reputation: 1724Reputation: 1724Reputation: 1724Reputation: 1724Reputation: 1724
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, 11:29 AM   #13
selfprogrammed
Member
 
Registered: Jan 2010
Location: Minnesota, USA
Distribution: Slackware 13.37
Posts: 291

Rep: Reputation: 55
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 11:30 AM.
 
Old 07-07-2013, 06:38 PM   #14
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 812

Rep: Reputation: 216Reputation: 216Reputation: 216
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, 12:04 PM   #15
jefro
Moderator
 
Registered: Mar 2008
Posts: 15,684

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:49 AM
Can you switch on a linux machine using x10? bedazzled Linux - General 14 02-01-2010 08:07 AM
KDE custom shortcuts to switch between layots ?!! slashams Debian 1 02-24-2007 05:44 PM
networking my linux machine with my xp machine through a 3com switch chefkahuna Linux - Networking 1 07-06-2005 10:01 AM
How to switch workspaces in Fluxbox via keyboard shortcuts? oxblood Linux - Software 3 01-08-2004 12:21 PM


All times are GMT -5. The time now is 11:03 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration