Amazon Affiliate

Wednesday 28 March 2012

LINUX COMMAND CHEATSHEET..


          Chown(Changing the Owner of a File or Directory):

chown is a standard Unix/Linux command that allows you to change the owner of a file/directory. To view the current owner of a file, execute the command ls -l. This will display the files in the current directory in long format. The third column in the table is the owner of the file or directory.
Using chown
To change the owner of a file/directory, become root by either logging in directly as the user root or use the su command as a normal user. Type the following command:
chown owner linuxhq (where owner is the new owner and linuxhq is the name of the file or directory you want to change the owner of)
Thus, chown tchin linuxhq would change the owner of the file linuxhq to tchin.

 

           Chgrp(Changing the Group of a File or Directory):

chgrp is a standard Unix/Linux command that allows you to change the group of a file/directory. To view the current group of a file, execute the following command:
ls -l.
This will display the files in the current directory in long format. The fourth column in the table is the group that the file/directory is associated with.
      To change the group of a file/directory, you must either be the owner and a member of the group you want to change the file/directory for or you must be root. Execute the following command:
chgrp group hello (where group is the new group and hello is the name of the file or directory you want to change the owner for)
Thus, chgrp linuxhq chgrp.html would change the group of the file chgrp.html to linuxhq.





                  Chmod(Changing File and Directory Permissions):

chmod is a standard Unix/Linux command that allows you to change the permissions of a file/directory.
Using chmod
There are two arguments for chmod: the permissions and the file/directory name. The permission argument for chmod is based on numbers.
1 stands for execute.
2 stands for write.
4 stands for read.
To set more than one permission on a file/directory, you just add up the permissions. For example, 7 means read, write, and execute permissions. Chmod takes the permissions as the first argument in the order user, group, global. Thus, the command chmod 777 hello will change the permissions of the file hello to read, write and execute by user, group, and everyone else.
Note: To change the permissions of a file/directory, you must be the owner of that file/directory. However, root can change permissions on any file/directory.

                         cd command

                              (Change directory)

Use the cd command to change to another directory.
The syntax is cd followed by the name of the directory you want to go to.
Example: cd /home/user/www will change the directory you are in to /home/user/www.
> cd /home/rich/www
> pwd
/home/rich/www
>
Line 1 shows the command cd /home/rich/www, which should put me in the folder /home/rich/www
Line 2 is the pwd command (print working directory) to see if we are in the right directory
Line 3 is the output of the pwd command - which shows that we are indeed in /home/rich/www
Line 4 is the prompt again
Wildcards are also permitted.
Example: cd /home/ri*/www would also take you to /home/rich/www, assuming there was no other folder in /home beginning with ri.
You can also use ../ to move you up one level in the file structure, or ../../ to move up two levels etc.
Example 1: If you are in /home/rich/www, then cd ../ will take you to /home/rich, and ../../ will take you to /home.
Example 2: From /home/rich/www, cd ../../bob will take you to /home/bob

                                   cat COMMAND


     cat linux command concatenates files and print it on the standard output.

SYNTAX:
  The Syntax is
     cat [OPTIONS] [FILE]...

OPTIONS:
     
-A
Show all.
-b
Omits line numbers for blank space in the output.
-e
A $ character will be printed at the end of each line prior to a new line.
-E
Displays a $ (dollar sign) at the end of each line.
-n
Line numbers for all the output lines.
-s
If the output has multiple empty lines it replaces it with one empty line.
-T
Displays the tab characters in the output.
-v
Non-printing characters (with the exception of tabs, new-lines and form-feeds) are printed visibly.



EXAMPLE:
     
  1. To Create a new file:
cat > file1.txt
This command creates a new file file1.txt. After typing into the file press control+d (^d) simultaneously to end the file.
  1. To Append data into the file:
cat >> file1.txt
To append data into the same file use append operator >> to write into the file, else the file will be overwritten (i.e., all of its contents will be erased).
  1. To display a file:
cat file1.txt
This command displays the data in the file.
  1. To concatenate several files and display:
cat file1.txt file2.txt
The above cat command will concatenate the two files (file1.txt and file2.txt) and it will display the output in the screen. Some times the output may not fit the monitor screen. In such situation you can print those files in a new file or display the file using less command.
cat file1.txt file2.txt | less
  1. To concatenate several files and to transfer the output to another file.
cat file1.txt file2.txt > file3.txt
In the above example the output is redirected to new file file3.txt. The cat command will create new file file3.txt and store the concatenated output into file3.txt.


Clear  COMMAND:
     This command clears the terminal screen.

SYNTAX:
  The Syntax is
     clear

OPTIONS:
     There is no options for clearscreen command.


EXAMPLE:
     
1.  clear
clear command clearscreen like cls command.
  1. You can also have alias for this command.
alias c='clear'
c is the alias name for clear command.
 
 
 

 

                                       cal- displays a calendar  

DESCRIPTION

Cal displays a simple calendar. If arguments are not specified, the current month is displayed. The options are as follows:
-1
Display single month output. (This is the default.)
-3
Display prev/current/next month output.
-s
Display Sunday as the first day of the week. (This is the default.)
-m
Display Monday as the first day of the week.
-j
Display Julian dates (days one-based, numbered from January 1).
-y
Display a calendar for the current year.
A single parameter specifies the year (1 - 9999) to be displayed; note the year must be fully specified: ``cal 89 '' will not display a calendar for 1989. Two parameters denote the month (1 - 12) and year. If no parameters are specified, the current month's calendar is displayed.

bc - An arbitrary precision calculator language

OPTIONS

-h, --help
Print the usage and exit.
-i, --interactive
Force interactive mode.
-l, --mathlib
Define the standard math library.
-w, --warn
Give warnings for extensions to POSIX bc.
-s, --standard
Process exactly the POSIX bc language.
-q, --quiet
Do not print the normal GNU bc welcome.
-v, --version
Print the version number and copyright and quit.

NUMBERS

The most basic element in bc is the number. Numbers are arbitrary precision numbers. This precision is both in the integer part and the fractional part. All numbers are represented internally in decimal and all computation is done in decimal. (This version truncates results from divide and multiply operations.) There are two attributes of numbers, the length and the scale. The length is the total number of significant decimal digits in a number and the scale is the total number of decimal digits after the decimal point. For example:
 .000001 has a length of 6 and scale of 6.
 1935.000 has a length of 7 and a scale of 3.
 
 
 
 
 

                                   cp(copy command)

To copy files and directories use cp command under Linux, UNIX, and BSD operating systems. cp is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
To make a copy of a file in the current directory, enter:
$ cp file.doc file.doc.bak
To copy a file in your current directory into another directory, enter:
$ cp filename /tmp
$ ls /tmp/filename
$ cd /tmp
$ ls
$ rm filename

To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
$ cp -p filename /path/to/new/location/myfile
To copy all the files in a directory to a new directory, enter:
$ cp * /home/tom/backup
To copy a directory, including all its files and subdirectories, to another directory, enter (copy directories recursively):
$ cp -R * /home/tom/backup.


                           Date command

date [options] [+format] [date]
Print the current date and time. You may specify a display format. format can consist of literal text strings (blanks must be quoted) as well as field descriptors, whose values will appear as described in the following entries (the listing shows some logical groupings). A privileged user can change the system's date and time.

Options

+format
Display current date in a nonstandard format. For example:
$date +"%A %j %n%k %p" Tuesday 248 15 PM
The default is %a %b %e %T %Z %Y (e.g., Tue Sep 5 14:59:37 EDT 2005).
-d date, --date date
Display date, which should be in quotes and may be in the format d days or m months d days, to print a date in the future. Specify ago to print a date in the past. You may include formatting (see the following section).
-f datefile, --file=datefile
Like -d, but printed once for each line of datefile.
-I [timespec] , --iso-8601[=timespec]
Display in ISO-8601 format. If specified, timespec can have one of the following values: date (for date only), hours, minutes, or seconds to get the indicated precision.
-r file, --reference=file
Display the time file was last modified.
-R, --rfc-822
Display the date in RFC 822 format.
--help
Print help message and exit.
--version
Print version information and exit.
-s date, --set date
Set the date.
-u, --universal
Set the date to Greenwich Mean Time, not local time.

Format

The exact result of many of these codes is locale-specific and depends upon your language setting, particularly the LANG environment variable. See locale.
%
Literal %.
- (hyphen)
Do not pad fields (default: pad fields with zeros).
_ (underscore)
Pad fields with space (default: zeros).
%a
Abbreviated weekday.
%b
Abbreviated month name.
%c
Country-specific date and time format.
%d
Day of month (01-31).
%h
Same as %b.
%j
Julian day of year (001-366).
%k
Hour in 24-hour format, without leading zeros (0-23).
%l
Hour in 12-hour format, without leading zeros (1-12).
%m
Month of year (01-12).
%n
Insert a new line.
%p
String to indicate a.m. or p.m.
%r
Time in %I:%M:%S %p (12-hour) format.
%s
Seconds since "the Epoch," which is 1970-01-01 00:00:00 UTC (a nonstandard extension).
%t
Insert a tab.
%w
Day of week (Sunday = 0).
%x
Country-specific date format based on locale.
%y
Last two digits of year (00-99).
%z
RFC 822-style numeric time zone.
%A
Full weekday.
%B
Full month name.
%D
Date in %m/%d/%y format.
%H
Hour in 24-hour format (00-23).
%I
Hour in 12-hour format (01-12).
%M
Minutes (00-59).
%S
Seconds (00-59).
%T
Time in %H:%M:%S format.
%U
Week number in year (00-53); start week on Sunday.
%V
Week number in year (01-52); start week on Monday.
%W
Week number in year (00-53); start week on Monday.
%X
Country-specific time format based on locale.
%Y
Four-digit year (e.g., 2006).
%Z
Time-zone name.

Strings for setting date

Strings for setting the date may be numeric or nonnumeric. Numeric strings consist of time, day, and year in the format MMDDhhmm[[CC] YY] [.ss] . Nonnumeric strings may include month strings, time zones, a.m., and p.m.
time
A two-digit hour and two-digit minute (hhmm); hh uses 24-hour format.
day
A two-digit month and two-digit day of month (MMDD); default is current day and month.
year
The year specified as either the full four-digit century and year or just the two-digit year; the default is the current year.

Examples

Set the date to July 1 (0701), 4 a.m. (0400), 2005 (05):
date 0701040095
The command:
date +"Hello%t Date is %D %n%t Time is %T"
produces a formatted date as follows:
Hello Date is 05/09/05 Time is 17:53:39


The ps Command

The ps (i.e., process status) command is used to provide information about the currently running processes including their process identification numbers (PIDs).
A process, also referred to as a task, is an executing (i.e., running) instance of a program. Every process is assigned a unique PID by the system.
The basic syntax of ps is
ps [options]
When ps is used without any options, it sends to standard output, which is the display monitor by default, four items of information for at least two processes currently on the system: the shell and ps. A shell is a program that provides the traditional, text-only user interface in  Unix-likeoperating system for issuing commands and interacting with the system, and it is bash by default on Linux. ps itself is a process and it dies (i.e., is terminated) as soon as its output is displayed.
     The -a option tells ps to list the processes of all users on the system rather than just those of the current user, with the exception of group leaders and processes not associated with a terminal. A group leader is the first member of a group of related processes.
The -u option tells ps to provide detailed information about each process. The -x option adds to the list processes that have no controlling terminal, such as daemons, which are programs that are launched during booting (i.e., computer startup) and run unobtrusively in the background until they are activated by a particular event or condition.








 
 

 










No comments:

Post a Comment