LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 04-20-2010, 11:05 PM   #1
gaikokujinkyofusho
LQ Newbie
 
Registered: Apr 2009
Location: different day, different place
Distribution: SuSE, considering Mint
Posts: 14

Rep: Reputation: 0
Possible to set "-h" for all programs?


Hi, i was busy setting up aliases for all the different commands that i use that have the -h (human readable format, or something like that) and it occurred to me that maybe, possibly (though i don't know how) it might be possible to set that parameter "universally" or at least for the applications where it can be used. So my question is, is that possible and if so how can it be done? Any help/ideas would be greatly appreciated!

Cheers,

-Gaikio
 
Old 04-20-2010, 11:48 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
I could be wrong but to the best of my knowledge your current option of creating aliases is the way to go.
However, I presume you are simply writing an alias for each command?
You may be better suited, as i am imagining there are a few you would like to set, to use a loop
based on an array of your commands, see below link on reference for how to use arrays in bash.
The general idea would be:

Code:
comm_array=(ls df) # add as many as required here

for command in ${comm_array[@]}
do
    alias $command="$command -h"
done

Reference: http://tldp.org/LDP/abs/html/arrays.html
 
1 members found this post helpful.
Old 04-21-2010, 02:14 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
I'm afraid that grail's approach is your best bet. The programs are all written by different people (see the bottom of each man page) and there's no enforced std for options...
 
Old 04-21-2010, 12:44 PM   #4
gaikokujinkyofusho
LQ Newbie
 
Registered: Apr 2009
Location: different day, different place
Distribution: SuSE, considering Mint
Posts: 14

Original Poster
Rep: Reputation: 0
Hi Grail, sorry for the belated reply. I tried your idea and it worked like a charm! Thanks!
 
Old 04-21-2010, 01:40 PM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,541
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

Just a few useful links;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Bash Reference Manual <<< Look here
Advanced Bash-Scripting Guide <<< and here
Linux Newbie Admin Guide
LinuxSelfHelp
Getting Started with Linux

The above links and others can be found at 'Slackware-Links' . More than just SlackwareŽ links!
 
Old 04-21-2010, 11:43 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Cool. Please mark as SOLVED
 
Old 04-22-2010, 07:25 PM   #7
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,052

Rep: Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881
one (or two) possible disadvantages with the Grail solution is
  • if you type 'du -h', you will actually pass 'du -h -h' to the command. I tried a couple of cases, and it looks as if the '-h -h' output is always the same as the '-h' output. I can't believe that this behaviour is one that is tested for, so you might want to check with every util for which you will use it, if this is of concern to you (maybe you are absolutely sure that this will never happen)
  • if you should decide that you don't in some particular case want the 'human readable output format' (maybe you are feeling particularly machine-like that day) there isn't a particularly easy way of turning it off (ok, there is a pretty easy way, once you've thought about it)
Provided that you are happy living with the limitations, it seems like a good solution.
 
Old 04-22-2010, 07:27 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
If I need an an alias, I always (usually?) provide new name so it won't interfere with normal operations.
 
Old 04-22-2010, 07:42 PM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,832

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
I go the other way - if I don't want the (same named) alias I use "\<command> ..."
 
Old 04-22-2010, 08:58 PM   #10
Bratmon
Member
 
Registered: Jul 2009
Location: 75.126.162.205:80
Distribution: Arch / Mint 17
Posts: 297
Blog Entries: 3

Rep: Reputation: 50
Add -h to everything? Even something like shutdown?
 
Old 04-22-2010, 10:44 PM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
@Bratmon - no not everything, just those in the array. So unless he puts shutdown in there halt won't be the default
 
  


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
Error: "cannot set groups" by using "su -", pls help nelsonyuen Linux - General 14 07-31-2010 01:24 PM
error: Error for wireless request "Set Mode" (8B06) : invalid argument "roaming" penguin chick Linux - Wireless Networking 5 08-22-2008 02:16 PM
cpufreqd can't start (Couldn't set profile "Performance High" set for cpu0) simopal6 Linux - Laptop and Netbook 2 05-10-2007 09:31 AM
how do you install programs extracted from "tar.gz", "bz2", etc? shoelessworm Ubuntu 13 04-12-2006 03:24 PM
How to set the size of icons for "Starterbar" in "Gdekslets" Blue Jacket Linux - Software 4 11-23-2005 03:42 AM


All times are GMT -5. The time now is 09:51 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