101 Linux Hacks


Trip

Sorry, but I suck at explaining stuff :P
Joined
Dec 22, 2005
Messages
2,670
Age
47
Location
The cesspit of the world, Bradford U.K
Website
ubuntufs.wordpress.com
Came across this today and thought it might be quite useful for those Pandora users that are only just starting out with Linux.
It's all command line and not tied to any specific distro + there seems to be quite a few answers for the most commonly asked questions by new Linux users..

QUOTE
http://www.thegeekstuff.com/2009/02/linux-...oad-free-ebook/


Table of Contents -

Chapter 1: Powerful CD Command Hacks

* Hack 1. Use CDPATH to define the base directory for cd command
* Hack 2. Use cd alias to navigate up the directory effectively
* Hack 3. Perform mkdir and cd using a single command
* Hack 4. Use “cd -” to toggle between the last two directories
* Hack 5. Use dirs, pushd and popd to manipulate directory stack
* Hack 6. Use “shopt -s cdspell” to automatically correct mistyped directory names on cd

Chapter 2: Date Manipulation

* Hack 7. Set System Date and Time
* Hack 8. Set Hardware Date and Time
* Hack 9. Display Current Date and Time in a Specific Format
* Hack 10. Display Past Date and Time
* Hack 11. Display Future Date and Time

Chapter 3: SSH Client Commands

* Hack 12. Identify SSH Client Version
* Hack 13. Login to Remote Host using SSH
* Hack 14. Debug SSH Client Session
* Hack 15. Toggle SSH Session using SSH Escape Character
* Hack 16. SSH Session Statistics using SSH Escape Character

Chapter 4: Essential Linux Commands

* Hack 17. Grep Command
* Hack 18. Find Command
* Hack 19. Suppress Standard Output and Error Message
* Hack 20. Join Command
* Hack 21. Change the Case
* Hack 22. Xargs Command
* Hack 23. Sort Command
* Hack 24. Uniq Command
* Hack 25. Cut Command
* Hack 26. Stat Command
* Hack 27. Diff Command
* Hack 28. Display total connect time of users

Chapter 5: PS1, PS2, PS3, PS4 and PROMPT_COMMAND

* Hack 29. PS1 - Default Interaction Prompt
* Hack 30. PS2 - Continuation Interactive Prompt
* Hack 31. PS3 - Prompt used by “select” inside shell script
* Hack 32. PS4 - Used by “set -x” to prefix tracing output
* Hack 33. PROMPT_COMMAND

Chapter 6: Colorful and Functional Shell Prompt Using PS1

* Hack 34. Display username, hostname and current working directory in the prompt
* Hack 35. Display current time in the prompt
* Hack 36. Display output of any command in the prompt
* Hack 37. Change foreground color of the prompt
* Hack 38. Change background color of the prompt
* Hack 39. Display multiple colors in the prompt
* Hack 40. Change the prompt color using tput
* Hack 41. Create your own prompt using the available codes for PS1 variable
* Hack 42. Use bash shell function inside PS1 variable
* Hack 43. Use shell script inside PS1 variable

Chapter 7: Archive and Compression

* Hack 44. Zip command basics
* Hack 45. Advanced compression using zip command
* Hack 46. Password Protection of Zip files
* Hack 47. Validate a zip archive
* Hack 48. Tar Command Basics
* Hack 49. Combine gzip, bzip2 with tar

Chapter 8: Command Line History

* Hack 50. Display TIMESTAMP in history using HISTTIMEFORMAT
* Hack 51. Search the history using Control+R
* Hack 52. Repeat previous command quickly using 4 different methods
* Hack 53. Execute a specific command from history
* Hack 54. Execute previous command that starts with a specific word
* Hack 55. Control the total number of lines in the history using HISTSIZE
* Hack 56. Change the history file name using HISTFILE
* Hack 57. Eliminate the continuous repeated entry from history using HISTCONTROL
* Hack 58. Erase duplicates across the whole history using HISTCONTROL
* Hack 59. Force history not to remember a particular command using HISTCONTROL
* Hack 60. Clear all the previous history using option -c
* Hack 61. Substitute words from history commands
* Hack 62. Substitute a specific argument for a specific command
* Hack 63. Disable the usage of history using HISTSIZE
* Hack 64. Ignore specific commands from the history using HISTIGNORE

Chapter 9: System Administration Tasks

* Hack 65. Partition using fdisk
* Hack 66. Format a partition using mke2fsk
* Hack 67. Mount the partition
* Hack 68. Fine tune the partition using tune2fs
* Hack 69. Create a swap file system.
* Hack 70. Create a new user
* Hack 71. Create a new group and assign to an user
* Hack 72. Setup SSH passwordless login in OpenSSH
* Hack 73. Use ssh-copy-id along with ssh-agent
* Hack 74. Crontab
* Hack 75. Safe Reboot Of Linux Using Magic SysRq Key

Chapter 10: Apachectl and Httpd Examples

* Hack 76. Pass different httpd.conf filename to apachectl
* Hack 77. Use a temporary DocumentRoot without modifying httpd.conf
* Hack 78. Increase the Log Level temporarily
* Hack 79. Display the modules inside Apache
* Hack 80. Show all accepted directives inside httpd.conf
* Hack 81. Validate the httpd.conf after making changes
* Hack 82. Display the httpd build parameters
* Hack 83. Load a specific module only on demand

Chapter 11: Bash Scripting

* Hack 84. Execution Sequence of .bash_* files
* Hack 85. How to generate random number in bash shell
* Hack 86. Debug a shell script
* Hack 87. Quoting
* Hack 88. Read data file fields inside a shell script

Chapter 12: System Monitoring and Performance

* Hack 89. Free command
* Hack 90. Top Command
* Hack 91. Ps Command
* Hack 92. Df Command
* Hack 93. Kill Command
* Hack 94. Du Command
* Hack 95. lsof commands.
* Hack 96. Sar Command
* Hack 97. vmstat Command
* Hack 98. Netstat Command
* Hack 99. Sysctl Command
* Hack 100. Nice Command
* Hack 101. Renice Command


Hope it helps :)
 
Last edited by a moderator:
OMG, how could I use Linux for over ten years without knowing about "cd -"? I feel so noobish...
 
So less of a "hack" and more of an intro to Linux?

It would be nice if they just called it Linux tips, instead of grossly mis-using the word "hack".

Maybe "Documented Linux Features"?
 
I've been using Linux for... five years now and I didn't know a lot of these.
 
Last edited by a moderator:
'cb88' said:
Looks cool ... password is linuxrocks if you didn't notice at the page in the link
Soz, forgot to add that :unsure:

'Klaus' said:
OMG, how could I use Linux for over ten years without knowing about "cd -"? I feel so noobish...
'nickspoon' said:
I've been using Linux for.. five years now and I didn't know a lot of these.
You think them are bad.. I've been using Windows since version 3.1 + Linux for about 6 years and have only just found out that Ctrl+A selects all :eek:

EDIT: If you want some more commands, check out commandlinefu.com. Not seen that site before today either. It's a good day :)
QUOTE
http://www.commandlinefu.com/commands/browse
 
Last edited by a moderator:
I've been using various *nixes for over 20 years and I still keep finding new commands and options.
 
Last edited by a moderator:
It's not too bad. I knew most of the (non-Apache) stuff anyway. I always know that "cd -" exists but I've never actually managed to use it because normally I've only needed it when I've accidentally cd'd my way out of a long path that I didn't mean to. By the time I remember that it's "cd -" that would take me back, I always manage to type the long path (with the help of bash's tab-completion).

Some of the others are just stupid or dangerous. I don't see any point in executing a command from the history like that book shows... you've only got to be one number out and you get the "rm -f" that you were using in some other directory. It's normally easier to just use the arrow keys anyway or, for anything particularly tricky, just echoing it to a script before you run it so that you know you can edit it and get it back. I don't think I've ever used history at all.

I don't see any use for CDPATH at all, either. Again, it just seems to make it easier to make mistakes. This is coming from a person who, whenever they use an rm command that needs a wildcard, puts a "#" in first so that I don't accidentally run a half-typed wildcard expansion. Or I use echo in the place of rm until I'm sure the list contains only the items I want to remove. I notice those "hacks" aren't in there.

"Perform mkdir and cd in a single command"... don't see much use for this.
Directory auto-spell-check-and-correct? EEeek. That's asking for trouble.
"Display future (and past) date and time"... now that's useful. I don't think I'd ever be able to remember the syntax quick enough to make it worthwhile, but I can see a use to it.

grep, find, sed, xargs, sort, uniq, - I use them so much the syntax is embedded in my brain and I can write scripts that do just about anything to a file or file listing.

Everything else seemed to be "how to do something quite obviously within the scope of a certain utility, in a way specified in the man pages". I'm not sure who it's supposed to target - newbies would just wreak havoc or not understand (or both!) and experienced people probably know most of it already. The middle ground aren't going to be doing enough file operations in the command-line to make most of it worthwhile.

Still... it's free, I suppose. :p

Oh, and I already have the Sed/Awk book that they recommend towards the end of the book. It's an absolute nightmare to read. I did better just reading the man pages for sed and a bog-standard regexp cheat sheet. I bought it at a boot sale for 50p and when I got home, I saw why.

Unix-based systems... the only computers to need AN ENTIRE BOOK for one command-line utility with a simple, stated purpose.
 
Last edited by a moderator:
Back
Top