Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am new to Linux and I am trying to create a cheat-sheet to help me remember common bash commands. If you know any of the commands for the tasks below, please post them. I appreciate it!

Commands for:

  1. the hostname of the system you are on?
  2. the type and version of the operating system the machine machine is running?
  3. the full path to your home directory?
  4. which other users are logged into the machine you are using?
  5. the last five commands executed by anyone from /usr/bin?
  6. how many words there are in the spell check dictionary (/usr/dict/words)?
  7. what groups you belong to?
  8. what files (excluding directories) are located in your home directory and all its subdirectories?
  9. what man pages have references to 'bash'?
share|improve this question

5 Answers 5

up vote 6 down vote accepted
1. hostname
2. lsb_release -a
3. echo ~
4. who
5. history | grep /usr/bin | tail -n 5
6. wc -w /usr/dict/words
7. groups [id -G -n for extra marks]
8. find ~ -name \* -type f -print
9. man -k bash

Make sure you give proper citations for your work ;)

share|improve this answer
1: hostname
2: uname -a
3:
4: users
5: cat ~/.bash_history (last commands in current user) to do exactly what you ask for you have to use grep over /etv/passwd to get the list of users and the use it to cat everyones .bash_history file
6: 
7: cat /etc/passwd ans some grep wizardy
8:
9:
share|improve this answer
    
3 : echo ~ or also echo $HOME 6 : there is one word per line so : wc -l /usr/dict/words 7 : the id command giv all needed information 9 : apropos bash –  slubman Sep 10 '09 at 7:15

Others have answered your specific query. If you're interested in learning the shell you can do worse than read LinuxCommand.org. If you find yourself wishing to go further the Advanced Bash Scripting Guide is a great resource.

share|improve this answer

what files (excluding directories) are located in your home directory and all its subdirectories?

$ cd $HOME
$ find -name \* -type f -print

btw. most of these commands are not bash builtins, rather standalone programs. So you can use them from any shell.

share|improve this answer
  1. $ hostname

  2. $ cat /etc/*release

    Note: this works on most distributions except plain Debian. On debian, 'cat /etc/debian_version'

  3. $ echo ~

  4. $ w

  5. $ history |grep /usr/bin

    Will only show the history for that user. Not sure about a system-wide history. Maybe I can learn something here.

  6. $ wc -l $(find /usr/share/dict -follow -type f -print) |grep total

    Assuming multiple word files and no duplicate words. Now follows symlinks!

  7. $ groups

  8. $ find ~ -type f

  9. $ grep -R bash /usr/share/man

I also feel like I just did some kid's homework. And the formatting on this site is a nightmare.

share|improve this answer
    
+1 for giving such convoluted homework answers! –  sybreon Sep 10 '09 at 7:37
    
Sorry, I was struggling with formatting. Should be more readable now. If you are referring to the find command in quotes, it should be faster for multiple files. –  Boohbah Sep 10 '09 at 7:41
    
I used find because I had multiple dictionary files on my system. I did not say it was useless to pipe wc. But I am now returning your downvote. –  Boohbah Sep 10 '09 at 8:45
    
I thought that you did it on purpose! :p –  sybreon Sep 10 '09 at 9:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.