Linux commands with examples

When you are using Linux command line frequently, using the history effectively can be a major productivity boost. In fact, once you have mastered the 15 examples that I’ve provided here, you’ll find using command line more enjoyable and fun.
1. Display timestamp using HISTTIMEFORMAT

Typically when you type history from command line, it displays the command# and the command. For auditing purpose, it may be beneficial to display the timepstamp along with the command as shown below.

# export HISTTIMEFORMAT='%F %T '
# history | more
1  2008-08-05 19:02:39 service network restart
2  2008-08-05 19:02:39 exit
3  2008-08-05 19:02:39 id
4  2008-08-05 19:02:39 cat /etc/redhat-release

Linux at Command

// linux at command

> at 03:30 -v
> nohup php -f /x/x/x.php > /x/x/logs
> nohup php -f /rg/repos/trunk/import/importxx-2009.php > ~rbanh/importlogs2009
> (Ctrl+D)
> atq    // to view queue
> atrm 1 // cancel job 1
> at 1am tomorrow -v // tomorrow 1am

Linux Command find

The following examples illustrate typical uses of the command find for finding files on a computer.

 find / -name game

Looks for a file named "game" starting at the root directory (searching all directories including mounted filesystems). The `-name' option makes the search case sensitive. You can use the `-iname' option to find something regardless of case.

 find /home -user joe

Find every file under the directory /home owned by the user joe.

 find /usr -name *stat

Find every file under the directory /usr ending in "stat".

 find /var/spool -mtime +60

Find every file under the directory /var/spool that was modified more than 60 days ago.

 find /tmp -name core -type f -print | xargs /bin/rm -f

Find files named core in or below the directory /tmp and delete them. Note that this will work incorrectly if there are any filenames containing newlines, single or double quotes, or spaces.