Custom Search

Unix Basic Commands

<< Back to Main Page                    << Back to UNIX Page


Page1 Page2 Page3


mkdir : Make/Create a new directory.
i.e. mkdir mydir

___________________________________________________________________________________________


cd : This command is used to change working directory. If directory is not specified the value of shell parameter HOME is used as the new working directory.
i.e. cd mydir
cd /home/work

___________________________________________________________________________________________


touch : touch command used to create zero length file. It also updates the access, modification, and last-change times of each argument.
Various options are available with touch command.
-a : Change the access date/time of file_name to new date/time, or to the current time if time is not specified.
-m : Change the modification date/time of file_name to new date/time, or to the current time if time is not specified.
-t : Use the specified date/time instead of the current time.

The option argument is a decimal number of the form:
[[CC]YY]MMDDhhmm[.SS]

CC : The first two digits of the year.
YY : The second two digits of the year.
MM : The month of the year (01-12).
DD : The day of the month (01-31).
hh : The hour of the day (00-23).
mm : The minute of the hour (00-59).
SS : The second of the minute (00-61).

touch filename
- creates zero length file.
touch -m 200801010000 filename
- updates modification time

___________________________________________________________________________________________


cat : It is a short form of catenate means "to connect in a series". cat reads each file in sequence and writes it on the standard output.
cat file
- prints file on the default standard output device
cat file1 file2 > file3
- concatenates file1 and file2, and places the result in file3

___________________________________________________________________________________________


pg(page) & more : pg and more are both used as a filter for examining continuous text, one screenful at a time, on screen.
more and page differ only slightly. more scrolls the screen upward as it prints the next page.
page clears the screen and prints a new screenful of text when it prints a new page.
Both provide one line of overlap between screenfuls.
example:
pg filename
more filename
ls -l | pg
ls -l | more

___________________________________________________________________________________________


rev : This command prints reverse lines of a file.
rev filename

___________________________________________________________________________________________


ls : This command lists the files and subdirectories located in working directory.
Various options are available with ls command. These options can be used along with each other i.e. (ls -l; ls -la; ls -lar etc)
-l : List in long format, giving mode, number of links, owner, group, size in bytes, and time of last modification for each file.
If the time of last modification is greater than six months ago, or any time in the future, the year is substituted for the hour and minute of the modification time.
If the file is a symbolic link, the filename is printed, followed by -> and the pathname of the referenced file.
-a : List all entries; usually entries whose names begin with a period (.) are not listed. Such files get listed with this option.
-t : Sort by time modified (latest first) before sorting alphabetically.
-r : Reverse the order of sort to get reverse (descending) collation or oldest first, as appropriate.
-A : The same as -a, except that the current directory . and parent directory .. are not listed.
For a user with appropriate privileges, this flag defaults to on, and is turned off by -A.
-F : After each file name, put one of:
   - A slash (/) if the file is a directory or a symbolic link to a directory.
   - An asterisk (*) if the file is executable;
   - An at-sign (@) if the file is a symbolic link to a file;
   - A vertical bar (|) if the file is a fifo.

___________________________________________________________________________________________


chmod : The chmod command changes the permissions of one or more files according to the value of symbolic_mode_list or numeric_mode.
A symbolic_mode_list is a comma-separated list of operations in the following form. Whitespace is not permitted.
   [who]op[permission][,...]
  The variable fields can have the following values:
  who - One or more of the following letters:
    u - Modify permissions for user (owner).
    g - Modify permissions for group.
    o - Modify permissions for others.
    a - Modify permissions for all users (a is equivalent to ugo).
  op - Required; one of the following symbols:
    + Add permission to the existing file mode bits of who.
    - Delete permission from the existing file mode bits of who.
    = Replace the existing mode bits of who with permission.
  permission - One or more of the following letters:
    r - Add or delete the read permission for who.
    w - Add or delete the write permission for who.
    x - Add or delete the execute file (search directory) permission for who.

i.e. chmod u+w test.txt (Gives write permission to user)
chmod g-x test.sh (Delete execute permission from group)
chmod a+rwx test.dat (Gives read, write, execute permission to all)
chmod u=g test.txt (Gives permission to group same as user)

Absolute permissions can be set by specifying a numeric_mode, an octal number constructed from the logical OR (sum) of the following mode bits:
400 (= u=r) Read by owner
200 (= u=w) Write by owner
100 (= u=x) Execute by owner
040 (= g=r) Read by group
020 (= g=w) Write by group
010 (= g=x) Execute by group
004 (= o=r) Read by others
002 (= o=w) Write by others
001 (= o=x) Execute by others

i.e. chmod 200 test.txt (Gives write permission to user)
chmod 777 test.dat (Gives read, write, execute permission to all)
chmod 551 test.sh (Gives read, execute permission to user and group and only execute permission to other)

___________________________________________________________________________________________


cp : copy files and directory subtrees.
Various options are available with this command.
-i : interactive copy. Prompt for user response incase of standard error like overwrite an existing file.
-f : Force existing destination pathnames to be removed before copying, without prompting for confirmation.
This option has the effect of destroying and replacing any existing file whose name and directory location conflicts with the name and location of the new file created by the copy operation.
-r : recursive subtree copy. Cause cp to copy the subtree rooted at each source directory to dest_directory.

example:
cp /home/test.txt /home/mylocation/test.csv
- Copy test.txt file from home directory to home/mylocation directory as test.csv
cp /home/test.txt /home/mylocation
- Copy test.txt file from home directory to home/mylocation directory with same name.
If mylocation does not exist then test.txt will be copied within home directory as mydirectory filename.
If mylocation is not a directory then cp will try to override the file or give error message.

___________________________________________________________________________________________


mv : move or rename files and directories.
Various options are available with this command.
-i : interactive move. Prompt for user response incase of standard error like overwrite an existing file.
-f : Perform move command without prompt.

example:
mv /home/test.txt /home/mylocation/test.csv
- move test.txt file from home directory to home/mylocation directory as test.csv
mv /home/test.txt /home/test.csv
- rename file test.txt to test.csv (as file location is same)
mv -f mv /home/test.txt /home/mylocation/test.csv
- move and overwrite file without prompt, if the file already exists in destination.



Page1 Page2 Page3


<< Back to Main Page                    << Back to UNIX Page