Monday, 10 September 2012

Few Basic linux Commands

1.                   cat -concatenate files and print on the standard Output


cat [OPTION] [FILE]...


Concatenate FILE(s), or standard input, to standard Output.
-A, --show-all
equivalent to -vET
number nonempty Output lines
equivalent to -vE
-E, --show-ends
display $ at end of each line
-n, --number
number all Output lines
-s, --squeeze-blank
suppress repeated empty Output lines
equivalent to -vT
-T, --show-tabs
display TAB characters as ^I
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
display this help and exit
Output version information and exit
With no FILE, or when FILE is -, read standard input.

sunshine@ubuntu:/home$ cat /home/sunshine/Desktop/hello1 /home/sunshine/Desktop/hello2
how are you?
how are you?


2.                   man- Display information from the online reference manuals. man locates and prints the named title from the
man [options] [section] [title]
sunshine@ubuntu:/$ man
What manual page do you want?

.Output:  Print a 12-month calendar (beginning with January) for the given year, or a one-month calendar of the given month and year. month ranges from 1 to 12. year ranges from 1 to 9999. With no arguments, print a calendar for the current month.
cal [options] [[month] year]


Display Julian dates (days numbered 1 to 365, starting from January 1).
Display Monday as the first day of the week.
Display entire year.

sunshine@ubuntu:~$ cal
    August 2012      
Su Mo Tu We Th Fr Sa 
          1  2  3  4 
 5  6  7  8  9 10 11 
12 13 14 15 16 17 18 
19 20 21 22 23 24 25 
26 27 28 29 30 31    


3.            date -print or set the system date and time
date [options] [+format] [date]

sunshine@ubuntu:~$ date
Sun Aug 19 08:11:01 PDT 2012


4.            ls - List contents of directories. If no names are given, list the files in the current directory. With one or more names, list files contained in a directory name or that match a file name.names can include filename metacharacters. The options let you display a variety of information in different formats. The most useful options include -F, -R, -l, and -s. Some options don't make sense together (e.g., -u and -c).
ls [options] [names]
-1, --format=single-column
Print one entry per line of Output.
-a, --all
List all files, including the normally hidden files whose names begin with a period.
-b, --escape
Display nonprinting characters in octal and alphabetic format.
-c, --time-ctime, --time=status
List files by status change time (not creation/modification time).
--color =when
Colorize the names of files depending on the type of file. Accepted values forwhen are never, always, or auto.
-d, --directory
Report only on the directory, not its contents.
Print directory contents in exactly the order in which they are stored, without attempting to sort them.
List times in full, rather than using the standard abbreviations.
Long listing like -l, but don't show file owners.
Print sizes in kilobytes and megabytes.
Print a help message and then exit.
-i, --inode
List the inode for each file.
Display filenames without the flags assigned by -p or -f (default).
-k, --kilobytes
If file sizes are being listed, print them in kilobytes. This option overrides the environment variable POSIXLY_CORRECT.
-l, --format=long, --format=verbose
Long format listing (includes permissions, owner, size, modification time, etc.).
-m, --format=commas
Merge the list into a comma-separated series of names.
-n, --numeric-uid-gid
Like -l, but use group ID and user ID numbers instead of owner and group names.
Long listing like -l, but don't show group information.
-p, --filetype, --indicator-style=file-type
Mark directories by appending / to them.
-q, --hide-control-chars
Show nonprinting characters as ? (default for display to a terminal).
-r, --reverse
List files in reverse order (by name or by time).
-s, --size
Print file size in blocks.
Show nonprinting characters verbatim (default for printing to a file).
Similar to -h, but uses powers of 1,000 instead of 1,024.
-t, --sort=time
Sort files according to modification time (newest first).
-u, --time=atime, --time=access, --time=use
Sort files according to file-access time.
Print version information on standard Output, then exit.
-x, --format=across, --format=horizontal
List files in rows going across the screen.
-v, --sort=version
Interpret the digits in names such as file.6 and file.6.1 as versions, and order filenames by version.
-w, --width=n
Format Output to fit n columns.
-A, --almost-all
List all files, including the normally hidden files whose names begin with a period. Does not include the . and .. directories.
-B, --ignore-backups
Do not list files ending in ~ unless given as arguments.
-C, --format=vertical
List files in columns (the default format).
-D, --dired
List in a format suitable for Emacs dired mode.
-F, --classify, --indicator-style=classify
Flag filenames by appending / to directories, * to executable files, @ to symbolic links, | to FIFOs, and = to sockets.
-G, --no-group
In long format, do not display group name.
-H, --dereference-command-line
When symbolic links are given on the command line, follow the link and list information from the actual file.
-I, --ignore pattern
Do not list files whose names match the shell pattern pattern, unless they are given on the command line.
-L, --dereference
List the file or directory referenced by a symbolic link rather than the link itself.
-N, --literal
Display special graphic characters that appear in filenames.
-Q, --quote-name
Quote filenames with "; quote nongraphic characters.
-R, --recursive
List directories and their contents recursively.
-Rfile, --reload-state file
Load state from file before starting execution.
-S, --sort=size
Sort by file size, largest to smallest.
-U, sort=none
Do not sort files.
-X, sort=extension
Sort by file extension, then by filename.
sunshine@ubuntu:/$ ls
bin    dev   initrd.img  media  proc  sbin     sys  var
boot   etc   lib         mnt    root  selinux  tmp  vmlinuz
cdrom  home  lost+found  opt    run   srv      usr


5.                   write - write user [tty] message
Initiate or respond to an interactive conversation with user. A write session is terminated with EOF. If the user is logged into more than one terminal, specify a tty number. See also talk; use mesg to keep other users from writing to your terminal.
6.           Echo –
echo [options] [string]
Send (echo) the input string to standard Output. This is the /bin/echo command. echoalso exists as a command built into bash.


-eEnable character sequences with special meaning. (In some versions, this option is not required in order to make the sequences work.)
-E Disable character sequences with special meaning.
-nSuppress printing of newline after text.
--helpPrint help message and then exit.
--versionPrint version information and then exit.

sunshine@ubuntu:~$ echo hello


7.           df
sunshine@ubuntu:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       30858908 3180476  26131784  11% /
udev              246496       4    246492   1% /dev
tmpfs             101508     756    100752   1% /run
none                5120       0      5120   0% /run/lock
none              253768     272    253496   1% /run/shm
/dev/sr0           21066   21066         0 100% /media/CDROM
/dev/sr1          718124  718124         0 100% /media/Ubuntu 12.04 LTS i386


8.            pwd-  print name of current/working directory
sunshine@ubuntu:~$ pwd


9.            free - Display statistics about memory usage: total free, used, physical, swap, shared, and buffers used by the kernel.
Syantax: free [options]
-b Calculate memory in bytes.
-k Default. Calculate memory in kilobytes.
-m Calculate memory in megabytes.
-o Do not display "buffer adjusted" line. The -o switch disables the display "-/+ buffers" line that shows buffer memory subtracted from the amount of memory used and added to the amount of free memory.
-s time Check memory usage every time seconds.
-t Display all totals on one line at the bottom of Output.
-VDisplay version information.

sunshine@ubuntu:~$ free
             total       used       free     shared    buffers     cached
Mem:        507536     501372       6164          0       5692      86872
-/+ buffers/cache:     408808      98728
Swap:       521212     226836     294376


10.         gzip - Compress specified files (or data read from standard input) with Lempel-Ziv coding (LZ77). Rename compressed file to filename.gz; keep ownership modes and access/modification times. Ignore symbolic links
gzip [options] [files] gunzip [options] [files] zcat[options] [files]
 -r, --recursive
When given a directory as an argument, recursively compress or decompress files within it.
-S suffix, --suffix suffix
Append .suffix. Default is gz. A null suffix while decompressing causesgunzip to attempt to decompress all specified files, regardless of suffix.
-t, --test
Test compressed file integrity.
-v, --verbose
Print name and percent size reduction for each file.
-V, --version
Display the version number and compilation options.
sunshine@ubuntu:/$ gzip /home/sunshine/sample1.odt


11.         clear - Clear the terminal display. Equivalent to pressing Ctrl-L.
12.         more - Display the named files on a terminal, one screenful at a time. See less for an alternative to more
more [options] [files]
Begin displaying at line number num.
-num number
Set screen size to number lines.
Begin displaying two lines before pattern.
Repaint screen from top instead of scrolling.
Display the prompt "[Press space to continue, `q' to quit] " instead of ringing the bell. Also display "[Press `h' for instructions] " in response to illegal commands.
Count logical rather than screen lines. Useful when long lines wrap past the width of the screen.
Ignore form-feed (Ctrl-L) characters.
Page through the file by clearing each window instead of scrolling. This is sometimes faster.
Squeeze; display multiple blank lines as one.
Suppress underline characters.

sunshine@ubuntu:~$ more
Usage: more [options] file...


  -d        display help instead of ring bell
  -f        count logical, rather than screen lines
  -l        suppress pause after form feed
  -p        suppress scroll, clean screen and disblay text
  -c        suppress scroll, display text and clean line ends
  -u        suppress underlining
  -s        squeeze multiple blank lines into one
  -NUM      specify the number of lines per screenful
  +NUM      display file beginning from line number NUM
  +/STRING  display file beginning from search string match
  -V        Output version information and exit

13.         who - Show who is logged into the system. With no options, list the names of users currently logged in, their terminal, the time they have been logged in, and the name of the host from which they have logged in. An optional system file (default is /etc/utmp) can be supplied to give additional information.
who [options] [file] who

-p, --process
Print active processes spawned by init.
-q, --count
"Quick." Display only the usernames and total number of users.
-r, --runlevel
Print the current runlevel.
-s, --short
Print only name, line, and time. This is the default behaviour.
-t, --time
Print the last system clock change.
-u, --users
Print a list of the users who are logged in.
Print version information and then exit.

sunshine@ubuntu:~$ who
sunshine pts/0        2012-08-19 08:10 (:0)


14.         whatis who-Search the short manual page descriptions in the whatis database for each keyword and print a one-line description to standard Output for each match. Like apropos, except that it searches only for complete words. Equivalent to man -f.

whatis keywords
sunshine@ubuntu:~$ whatis who
who (1)              - show who is logged on



15.               cd ..Takes you to the root directory
sunshine@ubuntu:~$ cd ..

16.         sleep - Wait a specified amount of time before executing another command. units may be s(seconds), m (minutes), h (hours), or d (days). The default for units is seconds.

sleep amount[units] sleep option
Print usage information and exit.
Print version information and exit.
17.         whoami- Print current user ID. Equivalent to id -un.
sunshine@ubuntu:~$ whoami

18.         bc -is a language (and compiler) whose syntax  resembles that of C, but with unlimited-precision arithmetic. bc consists of identifiers, keywords, and symbols, which are briefly described in the following entries. Examples are given at the end.
19.               Interactively perform arbitrary-precision arithmetic or convert numbers from one base to another. Input can be taken from files or read from the standard input. To exit, type quit or EOF.
bc [options] [files]
-h, --help
Print help message and exit.
-i, --interactive
Interactive mode.
-l, --mathlib
Make functions from the math library available.
-s, --standard
Ignore all extensions, and process exactly as in POSIX.
-w, --warn
When extensions to POSIX bc are used, print a warning.
-q, --quiet
Do not display welcome message.
-v, --version
Print version number.
sunshine@ubuntu:~$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 


20.         ls *odt - Lists all the odt  files in the current directory.

sunshine@ubuntu:/home$ ls *


21.         uname - Print information about the machine and operating system. Without options, print the name of the kernel (Linux).
uname [options]
-a, --all
Combine all the system information from the other options.
-i, --hardware-platform
Print the system's hardware platform.
-m, --machine
Print the name of the hardware that the system is running on.
-n, --nodename
Print the machine's hostname.
-o, --operating-system
Print the operating system name.
-p, --processor
Print the type of processor.
-r, --kernel-release
Print the release number of the kernel.
-s, --kernel-name
Print the name of the kernel (Linux). This is the default action.
-v, --kernel-version
Print build information about the kernel.
Display a help message and then exit.
Print version information and then exit.
sunshine@ubuntu:~$ uname -m
sunshine@ubuntu:~$ uname -i


22.         comm -1 file1 file2-Compare lines common to the sorted files file1 and file2. Output is in three columns, from left to right: lines unique to file1, lines unique to file2, and lines common to both files.comm is similar to diff in that both commands compare two files. But comm can also be used like uniq; comm selects duplicate or unique lines between two sorted files, whereasuniq selects duplicate or unique lines within the same sorted file.
comm [options] file1 file2
Read the standard input.
Suppress printing of column num. Multiple columns may be specified and should not be space-separated.
Print help message and exit.
Print version information and exit.
sunshine@ubuntu:~$ comm /home/sunshine/Desktop/hello1 /home/sunshine/Desktop/hello2
comm: file 1 is not in sorted order
how are you?
comm: file 2 is not in sorted order
    I am fine


23.         ps -Report on active processes. ps has three types of options. GNU long options start with two hyphens, which are required. BSD options may be grouped and do not start with a hyphen, while Unix98 options may be grouped and require an initial hyphen. The meaning of the short options can vary depending on whether or not there is a hyphen. In options, list arguments should either be comma-separated or space-separated and placed inside double quotes. In comparing the amount of Output produced, note that e prints more than a and lprints more than f for each entry.
ps [options]
sunshine@ubuntu:~$ ps
  PID TTY          TIME CMD
 1927 pts/0    00:00:00 bash
 2266 pts/0    00:00:00 ps


24.         diff-Compare two text files. diff reports lines that differ between file1 and file2. Output consists of lines of context from each file, with file1 text flagged by a < symbol and file2 text by a >symbol. Context lines are preceded by the ed command (a, c, or d) that would be used to convert file1 to file2. If one of the files is -, standard input is read. If one of the files is a directory, diff locates the filename in that directory corresponding to the other argument (e.g., diff my_dir junk is the same as diff my_dir/junk junk). If both arguments are directories, diff reports lines that differ between all pairs of files having equivalent names (e.g., olddir/program and newdir/program); in addition, diff lists filenames unique to one directory, as well as subdirectories common to both
diff [options] [diroptions] file1 file2
sunshine@ubuntu:~$ diff /home/sunshine/Desktop/hello1 /home/sunshine/Desktop/hello2
< hi 
< kiran
< how are you?
> Hi 
> ravi 
> I am fine



25.         topProvide information (frequently refreshed) about the most CPU-intensive processes currently running. You do not need to include a - before options.
top [options]
Run in batch mode; don't accept command-line input. Useful for sending Output to another command or to a file.
Show command line in display instead of just command name.
-d delay
Specify delay between refreshes.
Add or remove fields or columns.
Print a help message and exit.


Swap:   521212k total,   188748k used,   332464k free,    83616k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
  886 root      20   0  244m 105m 3304 S  5.8 21.3   2:37.32 Xorg               
 2469 sunshine  20   0 54724  17m 8896 S  2.9  3.6   0:01.04 python             
 1920 sunshine  20   0 89612 7632 4460 S  1.6  1.5   0:05.18 gnome-terminal     
 2043 sunshine  20   0  424m 108m  14m S  1.6 21.8   1:18.76 firefox            
 1575 sunshine  20   0  6756 2184  564 S  1.3  0.4   0:06.38 dbus-daemon        
 1525 sunshine  20   0 54904 1188  944 S  1.0  0.2   0:00.16 gnome-keyring-d    
 1624 sunshine  20   0  273m  24m 6052 S  1.0  4.9   0:27.95 unity-2d-shell     
 1647 sunshine  20   0 49824 2288 1088 S  1.0  0.5   0:14.47 bamfdaemon  

26.               init - System administration command. Initialize system. Usually run from the boot loader—e.g.,lilo or grub.
Boot flags
Set the AUTOBOOT environment variable to yes. The boot loader will do this automatically when booting with the default command line.
Boot directly into a single-user shell for emergency recovery.
Single-user mode.
Boot into single-user mode but do not run any other startup scripts.
-z characters
The specified characters are ignored, but will make the command line take up a bit more room on the stack. init uses the extra space to show the current runlevel when running the ps command.
init is the first process run by any Unix machine at boot time. It verifies the integrity of all filesystems and then creates other processes, using fork and exec, as specified by/etc/inittab. Which processes may be run is controlled by runlevel. All process terminations are recorded in /var/run/utmp and /var/log/wtmp. When the runlevel changes, init sends SIGTERM and then, after 20 seconds, SIGKILL to all processes that cannot be run in the new runlevel.
The current runlevel may be changed by telinit, which is often just a link to init. The default runlevels vary from distribution to distribution, but these are standard:
Halt the system.
1, s, S
Single-user mode.
Multiuser mode, console login. This is commonly used in server configurations.
Full graphical mode. This is a common default for desktop configurations.
Reboot the system. Never set the default runlevel to 6.
q, Q
Reread /etc/inittab.
Check the /etc/inittab file for runlevels on your system.

sunshine@ubuntu:~$ init
init: Need to be root


27.         su-Create a shell with the effective user ID user. If no user is specified, create a shell for a privileged user (i.e., become a superuser). Enter EOF to terminate. You can run the shell with particular options by passing them as shell_args (e.g., if the shell runs bash, you can specify -c command to execute command via bash, or -r to create a restricted shell).
-, -l, --login
Go through the entire login sequence (i.e., change to user's environment).
-c command, --command=command
Execute command in the new shell and then exit immediately. If command is more than one word, it should be enclosed in quotes. For example:
su -c 'find / -name \*.c -print' nobody
-f, --fast
Start the shell with the -f option, which suppresses the reading of the .cshrcor .tcshrc file. Applies to csh and tcsh.
-m, -p, --preserve-environment
Do not reset environment variables.
-s shell, --shell=shell
Execute shell, not the shell specified in /etc/passwd, unless shell is restricted.
Print a help message and then exit.
Print version information and then exit.

su [option] [user] [shell_args]

28.         runlevel-System administration command. Display the previous and current system runlevels as reported in the utmp file. The default utmp file is /var/run/utmp. See init for a summary of runlevels.

runlevel [utmp]
sunshine@ubuntu:/$ runlevel
N 2


29.         history – Displays the history of the commands executed on the shell.
sunshine@ubuntu:~$ history 5

   42  time
   43  bc
   44  history
   45  $PATH
   46  history 5


30.         $PATH
sunshine@ubuntu:~$ $PATH
bash: /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: No such file or directory


31.         Touch-change file timestamps
For one or more files, update the access time and modification time (and dates) to the current time and date. touch is useful in forcing other commands to handle files a certain way; for example, the operation of make, and sometimes find, relies on a file's access and modification time. If a file doesn't exist, touch creates it with a file size of 0.
touch [options] files
-a, --time=atime, --time=access, --time=use
Update only the access time.
-c, --no-create
Do not create any file that doesn't already exist.
-d time, --date time
Change the time value to the specified time instead of the current time. timecan use several formats and may contain month names, time zones, a.m. and p.m. strings, etc.
-m, --time=mtime, --time=modify
Update only the modification time.
-r file, --reference file
Change times to be the same as those of the specified file, instead of the current time.
-t time
Use the time specified in time instead of the current time. This argument must be of the format [[ccyymmddhhmm[.ss] , indicating optional century and year, month, date, hours, minutes, and optional seconds.
Print help message and then exit.
Print the version number and then exit.

sunshine@ubuntu:~$ touch /home/Desktop/sunshine/hello1


32.         tail-Output the last part of files
tail [options] [files]
sunshine@ubuntu:~$ tail /home/sunshine/Desktop/hello1
been long 
we have 
not spoken
to each

33.         head- Output the first few lines of files

head [options] [files]
sunshine@ubuntu:~$ head /home/sunshine/Desktop/hello1
how are you?
to talk

34.         sort -Sort the lines of the named files. Compare specified fields for each pair of lines; if no fields are specified, compare them by byte, in machine-collating sequence. If no files are specified or if the file is -, the input is taken from standard input. See also uniq, comm, and join.
sort [options] [files]
-b, --ignore-leading-blanks
Ignore leading spaces and tabs.
-c, --check
Check whether files are already sorted and, if so, produce no output.
-d, --dictionary-order
Sort in dictionary order.
-f, --ignore-case
Fold; ignore uppercase/lowercase differences.
-g, --general-numeric-sort
Sort in general numeric order.
Print a help message and then exit.

sunshine@ubuntu:~$ sort -c /home/sunshine/Desktop/hello1
sort: /home/sunshine/Desktop/hello1:3: disorder: how are you?

35.         yes- Output a string repeatedly until killed

36.         Cp- copy files and directories
Copy file1 to file2, or copy one or more files to the same names under directory. If the destination is an existing file, the file is overwritten; if the destination is an existing directory, the file is copied into the directory (the directory is not overwritten).
cp [options] file1 file2 cp [options] files directory
-a, --archive
Preserve attributes of original files where possible. The same as -dpr.
-b, --backup
Back up files that would otherwise be overwritten.
-d, --no-dereference
Do not dereference symbolic links; preserve hard-link relationships between source and copy.
-f, --force
Remove existing files in the destination.
-i, --interactive
Prompt before overwriting destination files. On most systems, this flag is turned off by default except for the root user, who is normally prompted before overwriting files.
-l, --link
Make hard links, not copies, of nondirectories.
-p, --preserve
Preserve all information, including owner, group, permissions, and timestamps.

sunshine@ubuntu:~$ cp /home/sunshine/Desktop/hello1 /home/sunshine/Desktop/hello2

37.         whoami -print effective userid

sunshine@ubuntu:~$ whoami

38.         tar- Copy files to or restore files from an archive medium. If any files are directories, tar acts on the entire subtree. Options need not be preceded by - (though they may be). The exception to this rule is when you are using a long-style option (such as --modification-time).
tar [options] [tarfile] [other-files]
39.         time-run programs and summarize system resource usage
time [options] command [arguments]
sunshine@ubuntu:~$ time

real    0m0.001s
user    0m0.000s
sys    0m0.000s


40.         ping - System administration command. Confirm that a remote host is online and is intended for use in network testing, measurement, and management. Because of the load it can impose on the network, it is unwise to use ping during normal operations or from automated scripts.
ping [options] host
Make ping audible. Beep each time response is received.
Adapt to return interval of packets. Like -f ping, sends packets at approximately the rate at which they are received. This option may be used by an unprivileged user.
Ping a broadcast address.
Bind to original source address and do not change.
-c count
Stop after sending (and receiving) count ECHO_RESPONSE packets.

sunshine@ubuntu:/home$ ping -B
Usage: ping [-LRUbdfnqrvVaAD] [-c count] [-i interval] [-w deadline]
            [-p pattern] [-s packetsize] [-t ttl] [-I interface]
            [-M pmtudisc-hint] [-m mark] [-S sndbuf]
            [-T tstamp-options] [-Q tos] [hop1 ...] destination

No comments:

Post a Comment