Wednesday, 1 April 2015

Linux Commands

Linux Commands :

1 ) alias command
The alias command can be useful if you want to create a 'shortcut' to a command.
The format is alias name='command'

> alias home='cd /home/dave/public_html'

This will create an alias called home which will put you in the /home/dave/public_html directory whenever you type home at the command prompt. You can alias any command you want, and include options for the command.

> alias list='ls -la'


This will create an alias called list, which will use the ls command to print a long-style listing of all files in the current directory (the -l gives a long-style list, and the -a shows all files - including hidden files).
(Find out more about the ls command)

To see a list of aliases set up on your linux box, just type alias at the prompt.

> alias
alias attrib='chmod'
alias chdir='cd'
alias copy='cp'
alias cp='cp -i'
alias d='dir'
alias del='rm'
alias deltree='rm -r'
alias dir='/bin/ls $LS_OPTIONS --format=vertical'
alias edit='pico'
alias ff='whereis'
alias ls='/bin/ls $LS_OPTIONS'
alias mem='top'
alias move='mv'
alias mv='mv -i'
alias pico='pico -w -z'
alias rm='rm -i'
alias search='grep'
alias v='vdir'
alias vdir='/bin/ls $LS_OPTIONS --format=long'
alias which='type -path'
alias wtf='watch -n 1 w -hs'
alias wth='ps -uxa | more'


2 ) apropos Command

apropos find

Display all manual entries with the word "find" in the page name or description. Output will resemble the following:

aa_find_mountpoint - find where the apparmor interface filesystem is mounted
chkdupexe         - find duplicate executables
ffs               - find first bit set in a word
ffsl              - find first bit set in a word
ffsll              - find first bit set in a word
find                - search for files in a directory hierarchy
find2perl          - translate find command lines to Perl code
findaffix          - Interactive spelling checking
findfs             - find a filesystem by label or UUID
findmnt             - find a filesystem
findsmb           - list info about machines that respond to SMB name quer...
glob               - find pathnames matching a pattern, free memory from gl...
globfree         - find pathnames matching a pattern, free memory from gl...
ippfind           - find internet printing protocol printers
lfind             - linear search of an array
locate            - find files by name
memdiskfind        - utility to search for a MEMDISK instance
mlocate            - find files by name
mysql_find_rows     - extract SQL statements from files
oldfind           - search for files in a directory hierarchy
pidof              - find the process ID of a running program.
texdoc              - find & view documentation in TeX Live
tfind             - manage a binary tree
tracediff        - find and print differences between two traces
ttyslot            - find the slot of the current user's terminal in some file 


3 ) date Command

1. Name

date [man page] - print or set the system date and time

2. Synopsis

date [OPTION]... [+FORMAT]

date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

3. Frequently used options

-u, --utc, --universal : print or set Coordinated Universal Time

+%F : full date; same as %Y-%m-%d 

4. Examples

date command is used to set and display time. By typing date command without any options and arguments the date command will display a current time:

linuxconfig.org:~$ date

Wed May 12 12:30:55 EST 2010

date command can also be used to set time. However, this requires superuser permissions. To set time to 20th March 2010 23:45:28 a following date command can be used:


linuxconfig.org ~# date 032023452010.28

Sat Mar 20 23:45:28 EST 2010

Linux date command can be very flexible as it offers more ways on how to set a time on your Linux systems: the next example we set date and time to "05 JUL 2021 01:55:56".

linuxconfig.org ~# date -s "05 JUL 2021 01:55:56"

Mon Jul  5 01:55:56 EST 2021

In case that we want to set just time but date a following syntax to date command can be applied:

Example:

linuxconfig.org ~# date +%T -s "18:30:01"

18:30:01

linuxconfig.org ~# date

Mon Jul  5 18:30:05 EST 2021


Linux date command is also capable to do some simple arithmetics as shown in the following example:

linuxconfig.org:~$ echo "Today is `date +%A` `date +%e`th of `date +%B` \ 

`date +%G` which is `date +%j`th day since 1th of January `date +%G`"

Today is Wednesday 12th of May 2010 which is 132th day since 1th of January 2010