Miscellaneous Linux commands. Some useful tips for the Linux BASH prompt.

The ldd command will print out a list of all libraries that an executable is linked against. This is the output for a simple “Hello World” command.

20:15:31 tux@linux-v415 ($ ldd ./a.out 
        linux-vdso.so.1 =>  (0x00007fff171ff000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fe56ef58000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fe56f2e8000)
20:15:49 tux@linux-v415 ($

If you wish to view a graphical representation of your system load in an Xterm or on the text console, use the tload command. This prints the graph using text characters.

To send a broadcast message from your tty or terminal emulator window use the wall command. I tried this on my KDE desktop in the konsole window and the notification popped up from the system tray showing my message. Just type the intended message and then press Ctrl-D to send it.

10:01:58 tux@linux-v415 ($ wall
Hello
                                                                               
Broadcast Message from tux@linux-v4                                            
        (/dev/pts/1) at 10:02 ...                                              
                                                                               
Hello                                                                          
                                                                               
10:02:10 tux@linux-v415 ($

The lsblk command will list all of the block devices or hard disks that are mounted on your machine. This is a useful command.

10:25:09 tux@linux-v415 ($ lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk 
├─sda1   8:1    0 214.9G  0 part /media/_Fedora-17-x86_6
├─sda2   8:2    0  32.2G  0 part /media/3fabc97d-c76a-4922-8705-5536e89cfd21
├─sda3   8:3    0     1K  0 part 
└─sda5   8:5    0 218.6G  0 part 
sdb      8:16   0 465.8G  0 disk 
├─sdb1   8:17   0   430M  0 part /media/e01436e0-4aa5-420b-94aa-0b35bd00020e
├─sdb2   8:18   0 341.8G  0 part /media/c84b3630-79a5-4ab3-85a5-f50bc23a3da9
├─sdb3   8:19   0 121.1G  0 part /media/a6f66737-afea-48c3-9694-f6da22904d37
├─sdb4   8:20   0     1K  0 part 
└─sdb5   8:21   0   2.5G  0 part [SWAP]
sdc      8:32   0   1.8T  0 disk 
└─sdc1   8:33   0   1.8T  0 part /media/Elements
sdd      8:48   0  37.3G  0 disk 
└─sdd1   8:49   0  37.3G  0 part /media/4282F11082F10965
sr0     11:0    1   834M  0 rom  /livecd
loop0    7:0    0     7G  0 loop /
10:25:18 tux@linux-v415 ($

Here is an interesting command that will reverse any text fed into it. The rev command could be useful when piping text into it to reverse a text file.

10:32:21 tux@linux-v415 ($ rev 
Hello
olleH
Hello
olleH

The ddate command will convert Gregorian dates into Discordian date formats. An example is shown below.

11:01:10 tux@linux-v415 ($ ddate 
Today is Boomtime, the 53rd day of Bureaucracy in the YOLD 3178

To see how much free RAM you have on your Linux system use the free command. This is useful to keep track of memory usage. Another way is to use the cat /proc/meminfo | grep MemFree: command.

11:01:18 tux@linux-v415 ($ free 
             total       used       free     shared    buffers     cached
Mem:       6053668    5902464     151204          0     549500    3353780
-/+ buffers/cache:    1999184    4054484
Swap:      2559996       2240    2557756

Do you sometimes want to find where a program is installed to? The whereis command will help you with this.

11:19:15 tux@linux-v415 ($ whereis emacs
emacs: /usr/bin/emacs /usr/lib/emacs /usr/bin/X11/emacs /usr/share/emacs /usr/share/man/man1/emacs.1.gz

I am not sure if I have posted this before; but the host command will print information about a certain network host. It prints all of the IP addresses and other pertinent information about the target host.

11:21:54 tux@linux-v415 ($ host localhost
localhost has address 127.0.0.1
localhost has IPv6 address ::1
11:22:02 tux@linux-v415 ($ host google.com
google.com has address 74.125.237.105
google.com has address 74.125.237.110
google.com has address 74.125.237.96
google.com has address 74.125.237.97
google.com has address 74.125.237.98
google.com has address 74.125.237.99
google.com has address 74.125.237.100
google.com has address 74.125.237.101
google.com has address 74.125.237.102
google.com has address 74.125.237.103
google.com has address 74.125.237.104
google.com has IPv6 address 2404:6800:4006:803::1002
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.

To get help on the BASH shell builtin commands the help command is your friend. Type help kill to get help on the kill command for example.

11:25:33 tux@linux-v415 ($ help
GNU bash, version 4.2.10(1)-release (x86_64-suse-linux-gnu)
These shell commands are defined internally.  Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.

A star (*) next to a name means that the command is disabled.

 job_spec [&]                                                                                                          history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
 (( expression ))                                                                                                      if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
 . filename [arguments]                                                                                                jobs [-lnprs] [jobspec ...] or jobs -x command [args]
 :                                                                                                                     kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
 [ arg... ]                                                                                                            let arg [arg ...]
 [[ expression ]]                                                                                                      local [option] name[=value] ...
 alias [-p] [name[=value] ... ]                                                                                        logout [n]
 bg [job_spec ...]                                                                                                     mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
 bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readlin>  popd [-n] [+N | -N]
 break [n]                                                                                                             printf [-v var] format [arguments]
 builtin [shell-builtin [arg ...]]                                                                                     pushd [-n] [+N | -N | dir]
 caller [expr]                                                                                                         pwd [-LP]
 case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac                                                            read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
 cd [-L|[-P [-e]]] [dir]                                                                                               readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
 command [-pVv] command [arg ...]                                                                                      readonly [-aAf] [name[=value] ...] or readonly -p
 compgen [-abcdefgjksuv] [-o option]  [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterp>  return [n]
 complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command]>  select NAME [in WORDS ... ;] do COMMANDS; done
 compopt [-o|+o option] [-DE] [name ...]                                                                               set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
 continue [n]                                                                                                          shift [n]
 coproc [NAME] command [redirections]                                                                                  shopt [-pqsu] [-o] [optname ...]
 declare [-aAfFgilrtux] [-p] [name[=value] ...]                                                                        source filename [arguments]
 dirs [-clpv] [+N] [-N]                                                                                                suspend [-f]
 disown [-h] [-ar] [jobspec ...]                                                                                       test [expr]
 echo [-neE] [arg ...]                                                                                                 time [-p] pipeline
 enable [-a] [-dnps] [-f filename] [name ...]                                                                          times
 eval [arg ...]                                                                                                        trap [-lp] [[arg] signal_spec ...]
 exec [-cl] [-a name] [command [arguments ...]] [redirection ...]                                                      true
 exit [n]                                                                                                              type [-afptP] name [name ...]
 export [-fn] [name[=value] ...] or export -p                                                                          typeset [-aAfFgilrtux] [-p] name[=value] ...
 false                                                                                                                 ulimit [-SHacdefilmnpqrstuvx] [limit]
 fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]                                                      umask [-p] [-S] [mode]
 fg [job_spec]                                                                                                         unalias [-a] name [name ...]
 for NAME [in WORDS ... ] ; do COMMANDS; done                                                                          unset [-f] [-v] [name ...]
 for (( exp1; exp2; exp3 )); do COMMANDS; done                                                                         until COMMANDS; do COMMANDS; done
 function name { COMMANDS ; } or name () { COMMANDS ; }                                                                variables - Names and meanings of some shell variables
 getopts optstring name [arg]                                                                                          wait [id]
 hash [-lr] [-p pathname] [-dt] [name ...]                                                                             while COMMANDS; do COMMANDS; done
 help [-dms] [pattern ...]                                                                                             { COMMANDS ; }

If you are very new to the Linux command line, the man intro command will print a helpful tutorial that will help you learn the basics.

If you want to have some fun as I did; make a copy of a text file and then use the join command to join them together…

11:30:50 tux@linux-v415 ($ join my.c my2.c 
#include  
#include  
#include  
#include  

clock_t times(struct tms *buf); times(struct tms *buf);

int main(void) main(void)
{
write(1, "Hello World.\n", 15); "Hello World.\n", 15);

return 0; 0;
}

Post a Comment

Your email is kept private. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current ye@r *