LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-26-2005, 11:03 PM   #1
xuper
LQ Newbie
 
Registered: May 2005
Posts: 9

Rep: Reputation: 0
Turning off computer with a single command


One thing that has really started to annoy me every night is when I am falling half asleep in front of the pc and I click on shutdown and then have to wait for everything to close and for the computer to tell me that it is safe to turn it off. Is it possible to shutdown linux with a single command just as in windows? or be able to shut it down by hitting the reset button?

running mandrake 10.1
 
Old 05-26-2005, 11:11 PM   #2
JimBass
Senior Member
 
Registered: Oct 2003
Location: New York City
Distribution: Debian Sid 2.6.32
Posts: 2,100

Rep: Reputation: 49
As root, or with sudo, issue the command
Code:
/sbin/shutdown -h -t0 now
That should shut you off within 20 seconds. If your computer does not power off, you may need to add modules to your kernel for that to work, but generally it should kill it easily.

Peace,
JimBass
 
Old 05-26-2005, 11:22 PM   #3
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
I've got Ctrl-Alt-Del mapped to 'shutdown -h now', but that doesn't work in X, so it might not be a lot of use.

Dave
 
Old 05-26-2005, 11:29 PM   #4
gbhil
Member
 
Registered: Jan 2005
Location: /dev/input/chair0
Distribution: Slackware, Gentoo, Vector, Roll-your-own-with-GNU binutils
Posts: 174

Rep: Reputation: 30
in ~/.bashrc add this line with your current aliases

alias off="sudo /sbin/poweroff"

assuming sudo is setup for it, you can then issue the command "off" from a terminal to shut down.
 
Old 05-26-2005, 11:33 PM   #5
aes canis
Member
 
Registered: May 2005
Location: Finland
Distribution: Slackware 13.37, Ubuntu 10.10
Posts: 123

Rep: Reputation: 15
I found this on the net, but shamefully cannot remember where...
So, I'm not claiming originallity for it, and appologise to the original author!:
----------------------------------------
Making poweroff and reboot buttons
In Slackware when we want to power-off we need to give the command shutdown -h now as root in a terminal. (Because there is no entry for shutdown in the menu)
We can make a power-off button, but it needs some work, here is how to do that:
Edit the sudoers file, as root, with vi.
There is a special command to open the sudoers file in vi though - NOT vi sudoes, but:
Code:
# visudo
This will open the file in vi so press i to put vi in insert mode and paste the next line at the end of the file:
Code:
username ALL=(ALL) NOPASSWD: /sbin/shutdown -h now, /sbin/reboot
You need to do this for every user you will allow to reboot and halt.
Then save and close the file:
We now gave bruno sudo permission to give the commands sudo /sbin/reboot and sudo /sbin/halt and we can meke special buttons on the tastbar:
Rightclick on the taskbar and choose Add | Special Button | Non-KDE application. You will get a little GUI where you can put in the top box (Executable):
Code:
sudo /sbin/reboot
Click the icon button to change the icon to the one you like. Click OK and you are ready.
Do the same for:
Code:
sudo /sbin/halt
Every user you did add in the sudoers file will be able to press the buttons and reboot or halt the system.
------------------------------------------------
After that, I made a toolbar short cut to /sbin/shutdown -h now which works. So, when logged in as a regular user, I can shut the PC off properly without having to log out, login as root & then shutdown.

Last edited by aes canis; 05-26-2005 at 11:36 PM.
 
Old 05-26-2005, 11:54 PM   #6
fancypiper
LQ Guru
 
Registered: Feb 2003
Location: Sparta, NC USA
Distribution: Ubuntu 10.04
Posts: 5,141

Rep: Reputation: 58
Why shut it down? I have cron jobs that run and do stuff for me during my physical sleep. I like my computer to do work while I take it easy, so the only time I go down is when I decide to switch between my 4 operating systems.

alias is your friend, see my .bashrc file.
Code:
# Duron 950 uilleann .bashrc for root
# User specific aliases and functions

# Change bash prompt. See the article
export PS1='\d \@ \[\e[31;1m\]\u\[\e[34;1m\]@\[\e[36;1m\]\H \[\e[34;1m\]\w\[\e[31;1m\] # \[\e[0m\]'

# Turn off and reboot
alias off='shutdown -h now'
alias boot='shutdown -r now'

# Run Gentoo file manager as root
alias gentoo='gentoo --root-ok'

# Change permissions of /home/fancy and /pub
alias fancystuff='chown -R fancy.fancy /home/fancy && chown -R fancy.fancy /pub'
alias philstuff='chown -R phil.user /home/phil && chown -R phil.user /pub' 

# Keep 1000 lines in .bash_history (default is 500)
export HISTSIZE=1000
export HISTFILESIZE=1000

#Stop bash from caching duplicate lines.
HISTCONTROL=ignoredups

# Disk free
alias df='df -h'

# Alter the ls command
alias ls='ls -ac'
alias lls='ls -lac'

# xterm
# alias xterm='xterm -bg black -fg white'

# Launch links with my linux links page
alias links='links /home/fancy/bookmarks.html'

# For nano editor because I forget which one I use in which distro
alias pico='nano -w'
alias nano='nano -w'

# New name for top front end
alias gtop='gnome-system-monitor'

# Script needs to be on the bottom of the file or RH updates will fsck it up
# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi
Code:
# Duron 850 tinwhistle .bashrc for user fancy
# User specific aliases and functions

# Start X server
alias x='startx'

# Change bash prompt. See the article
# http://www-106.ibm.com/developerwork.../l-tip-prompt/
export PS1='\d \@ \[\e[32;1m\]\u\[\e[34;1m\]@\[\e[36;1m\]\H \[\e[34;1m\]\w\[\e[32;1m\] $ \[\e[0m\]'
# For the root account use this
# export PS1='\d \@ \[\e[31;1m\]\u\[\e[34;1m\]@\[\e[36;1m\]\H \[\e[34;1m\]\w\[\e[31;1m\] # \[\e[0m\]'

# Keep 1000 lines in .bash_history (default is 500)
export HISTSIZE=1000
export HISTFILESIZE=1000

#Stop bash from caching duplicate lines.
HISTCONTROL=ignoredups

# Disk free
alias df='df -h'

# Set paths
alias path='echo -e ${PATH//:/\\n}'

# Allow local users to use my X session
# xhost +local:

# I can't remember the new gnome command!
alias gtop='/usr/bin/gnome-system-monitor'

# Alter the ls command
alias ls='ls -ac'
alias lls='ls -lac'

# Become system administrator
alias god='su -'

# xterm
# alias xterm='xterm -bg black -fg white'

# Launch links with my linux links page
alias links='links /home/fancy/bookmarks.html'

# For nano editor because I forget which one I use in which distro
alias pico='nano -w'
alias nano='nano -w'

# Script needs to be on the bottom of the file or RH updates will fsck it up
# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

Last edited by fancypiper; 05-26-2005 at 11:59 PM.
 
Old 05-26-2005, 11:58 PM   #7
xuper
LQ Newbie
 
Registered: May 2005
Posts: 9

Original Poster
Rep: Reputation: 0
When I type

/sbin/shutdown -h -t0 now

the computer closes all programs running and then tells me its ok to shut it down, so it is the same as shutting it down through the gui. What I want to be able to do is to click on shutdown in the GUI and have the pc shutdown automatically, not have to wait for all the programs to close and then press the reset button. This may not be a critical problem but it is really annoying having to wait for all the programs to close in order for the pc to shutdown
 
Old 05-27-2005, 12:03 AM   #8
fancypiper
LQ Guru
 
Registered: Feb 2003
Location: Sparta, NC USA
Distribution: Ubuntu 10.04
Posts: 5,141

Rep: Reputation: 58
If you want your data written to disk correctly before shutting down, the programs need to close to sent the stuff to the disk properly. You risk data corruption if the processes aren't stopped.

I can open an x terminal, give these commands and everything turns off for me:

god
<give password>
off

sudo might be better, but I am stuck in my rut from my 1999 Linux install.

Last edited by fancypiper; 05-27-2005 at 12:07 AM.
 
Old 05-27-2005, 12:10 AM   #9
JimBass
Senior Member
 
Registered: Oct 2003
Location: New York City
Distribution: Debian Sid 2.6.32
Posts: 2,100

Rep: Reputation: 49
If your computer doesn't physically power off, it is missing kernel modules, or has a promblem with acpi or apm, whichever power management you're using. Do a search here on linux questions or google.com/linux, and you'll find ways to modify things so the power will shut off at the end of a shutdown.

Peace,
JimBass
 
Old 05-27-2005, 05:03 AM   #10
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 57
From my experience, it seems generally laptops use apm and desktops use acpi. You just need to load the modules so the kernel can access the physical hardware required to poweroff.
 
Old 05-27-2005, 05:22 AM   #11
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 51
I think cs-cam, got the right answer. You didn't explain the real problem at the beginning too

Last edited by mrcheeks; 05-27-2005 at 05:23 AM.
 
Old 05-27-2005, 12:41 PM   #12
pjbii
Member
 
Registered: Mar 2005
Distribution: FreeBSD, Slack, Fedora3
Posts: 35

Rep: Reputation: 15
# init 0
 
  


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
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 08:19 PM
turning off computer d1l2w3 Linux - General 14 01-08-2005 08:17 AM
Turning a single JPG into a 10 second avi? nmoog Linux - Software 2 04-28-2004 07:58 AM
How to begin Installing Linux on an Single Board Computer. Laeeq Linux - Hardware 0 02-27-2004 09:42 AM
Troubles with Computer Turning Off ShadowRunner Linux - Hardware 3 11-30-2003 09:46 PM


All times are GMT -5. The time now is 10:22 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration