os file
os file
1. ECHO COMMAND :-
echo is a built-in command in the bash and C shells that writes its
arguments to standard output.
SYNTAX :-
echo [option(s)] [string(s)]
echo -
EXAMPLE :-
c. \n - New line
EXAMPLE :-
d. \t - Horizontal tab
EXAMPLE :-
e. \v - Vertical tab
1
EXAMPLE :-
f. \\ - Backslash
EXAMPLE :-
2. DATE :-
Linux “date” command returns you the date and time when you call
it without any options.
Use the date command to display the current date and time or set the
system date / time over ssh session.
SYNTAX :-
date [OPTION]... [+FORMAT]
2
EXAMPLE :-
These are a few of the many possibilities that the “date” command
offers you. Check out “date –help for options”. Some interesting ones
are :-
%D date (mm/dd/yy)
%d day of month (01..31)
%m month (01..12)
%y last two digits of year (00..99)
%a locale’s abbreviated weekday name (Sun..Sat)
%A locale’s full weekday name, variable length (Sunday..Saturday)
%b locale’s abbreviated month name (Jan..Dec)
%B locale’s full month name, variable length (January..December)
%H hour (00..23)
%I hour (01..12)
%Y year (1970…)
3
c. date +”%a%d%m%y” - to get the day of the week along with
the rest of the date
EXAMPLE :-
e. ho
EXAMPLE :-
3. HOSTNAME :-
Hostname is the program that is used to either set or display the
current host, domain or node name of the system. These names are
used by many of the networking programs to identify the machine.
SYNTAX:-
Hostname - to see the host
4
EXAMPLE :-
4. ARCH :-
The arch command will print the type of computer architecture .
EXAMPLE :-
5. UNAME :-
Print na# of the current system .
EXAMPLE :-
6. UPTIME :-
Uptime gunives a one line display of the following information. The
current time, how long the system has been running, how many users
are currently logged on, and the system load averages for the past 1,
5, and 15 minutes.
EXAMPLE :-
5
7. WHOAMI :-
Whoami prints the user name associated with the current effective
user ID.
EXAMPLE :-
8. WHO :-
Displays who is on the system.
SYNTAX :-
who [-H] [-m] [am i] [ file ]
-H Output column headings above the regular output.
-m Output only information about the current terminal.
-u List only those users who are currently logged in.
-am i In the locale, limit the output to describing the invoking user,
equivalent to the -m option. The am and I or I must be separate
arguments.
EXAMPLE :-
6
Directory Commands :-
9. PWD :-
Display name of current directory in the linux system .
EXAMPLE :-
10.CHANGE DIRECTORY(cd) :-
Switch to another directory .
EXAMPLE :-
EXAMPLE :-
7
cd /EXAMPLE :-
11.LIST(ls) :-
List the Contents of a directory .
SYNTAX :-
ls [option]
cd
EXAMPLE :-
8
c. ls -It - list all files, sorted by most recent accessed first
EXAMPLE :-
SYNTAX :-
mkdir [directory name]
13.REMOVE FILES(rmdir) :-
The command rmdir or rm -r is used to delete a directory or
directories .
SYNTAX :-
9
rmdir [directory name]
EXAMPLE :-
File Commands :-
14.WILDCARDS :-
Wildcard characters are used to help find file or directory names .
Various Wilcards that are used as an option are as follows :-
l
*a all files where the last character is ‘a’ .
a*r all files that start with the letter ‘a’ and end with ‘r’ .
10
c. [from-to ] - Values entered within square brackets represent a
range (from-to) for a single character .
EXAMPLE :-
[a -n]* all files that start with ‘a’ , ‘b’ and so on till ‘n’ .
EXAMPLE :-
[!a-n]* - all files that start with ‘a’ , ‘b’ and so on till ‘n’ are not
be displayed .
15.COPY FILES(cp) :-
To copy a file, the command cp is used .
SYNTAX :-
cp [oldfile] [newfile]
EXAMPLE :-
11
16.RENAME FILES(mv) :-
The command mv is used to rename a file .
SYNTAX :-
mv [old name] [new name]
EXAMPLE :-
17.REMOVE(rm) :-
This command removes the file from the directory .
SYNTAX :-
rm filename
EXAMPLE :-
12
rm am* - remove all files in current directory starting with ‘am’
automatically
SYNTAX :-
wc OPTION... [FILE]...
EXAMPLE :-
13
a. wc -l - This option prints the number of lines present in a file .
Hello is 1 line .
SYNTAX :-
file [filename]
EXAMPLE :-
14
20.CONCANTENATE FILES(cat) :-
The command cat is a multi-purpose utility and is mostly used with
TEXT files.
a. Create a new file and optionally allow the manual entry of
contents
EXAMPLES :-
15
d. Delete the contents of a file --cat /dev/null >a file
EXAMPLE :-
21.TOUCH COMMANDS :-
Touch command is used to create a file .It can change file access and
modification time. It is also used to change the timestamps (i.e., dates
and times of the most recent access and modification)on existing files
and directories.
SYNTAX :-
touch [option] file_name(s)
EXAMPLE :-
Touch’s options :-
a. -a - Change the access time . Do not change the modification
time unless -m is also specified.
EXAMPLE :-
16
b. -c - Do not create a specified file if it does not exist. Do not
write any diagnostic
messages concerning this condition.
EXAMPLE :-
22.PASTE COMMAND :-
Merge corresponding or subsequent lines of files.
SYNTAX :-
paste file1 file 2
17
EXAMPLE :-
23.SORT COMMANDS :-
Sort sorts, merges, or compares all the lines from the given files, or
the standard input if no files are given.
SYNTAX :-
sort [options] [file...]
EXAMPLE :-
18
b. -r - Reverse the result of comparison, so that lines with greater
key values appear earlier in the output instead of later.
EXAMPLE :-
24.CUT COMMANDS :-
The cut command takes a vertical slice of a file, printing only the
specified columns or fields.
Like the sort command, the cut command defines a field as a word
set off by blanks, unless you specify your own delimiter.
19
SYNTAX :-
cut OPTION... [FILE]...
20
EXAMPLE
EXAMPLE :-
touch
The tail command displays the last few lines of a file. Like head, it
can save you time, because it’s a lot quicker than calling up a file with
a text editor and scrolling all the way down to the bottom.
21
SYNTAX FOR TAIL :-
tail [ number of lines] [file]
EXAMPLE :-
EXAMPLE :-
26.SPELL COMMAND :-
Looks through a text file and reports any words that it finds in the
text file that are not in the
dictionary.
SYNTAX :-
spell FILENAME
EXAMPLE :-
22
27.FINGER COMMAND :-
Lists information about the user.
SYNTAX :-
finger [username]
EXAMPLE :-
28.GREP COMMAND :-
grep searches the input files for lines containing a match to a given
pattern list. When it finds a match in a line, it copies the line to
standard output (by default), or whatever other sort of output you
have requested with options.
SYNTAX :-
grep [option] pattern [file_name]
pattern - at what pattern will it be displayed
EXAMPLE :-
23
Various options that helps the grep command to give the suitable
output are as follows :-
a. -i - It prints the matches pattern having both uppercase and
lowercase .
EXAMPLE :-
29.CLEAR COMMAND :-
It clears the screen .
SYNTAX :-
24
clear
EXAMPLE :-
BEFORE : -
AFTER :-
30.CHANGE MODE :-
In Unix operating systems, the chmod command is used to change the
access mode of a file. The name is an abbreviation of change mode.
Which states that every file and directory has a set of permissions
that control the permissions like who can read, write or execute the
file.
25
The second set of flags ([-+=]), the operation flags, defines whether
the permissions are to be removed, added, or set :-
- Removes the specified permissions.
+ Adds specified permissions.
= Changes the current permissions to the specified permissions. If no
permissions are specified after the = symbol, all permissions from the
specified user class are removed.
:-
26
SYNTAX :- (NUMBERIC METHOD)
chmod [OPTIONS] NUMBER FILE...
Each write, read, and execute permissions have the following number
value:
The NUMBER can be a 3 or 4-digits number. When 3 digits number
is used, the first digit represents the permissions of the file’s owner,
the second one the file’s group, and the last one all other users.
r (read) = 4
w (write) = 2
x (execute) = 1
no permissions = 0
When the 4 digits number is used, the first digit has the following
meaning:
setuid=4
setgid=2
sticky=1
no changes = 0
27
stat -c "%a" filename
EXAMPLE :-
a. chmod 100 dirname - Give the file’s owner read and write
permissions and only read permissions to group members and
all other users .
EXAMPLE :-
b. chmod 750 dirname - Give the file’s owner read, write and
execute permissions, read and execute permissions to group
members and no permissions to all other users .
EXAMPLE :-
SYNTAX:-
# free
EXAMPLE:-
28
Free command with option -b, display the size of memory in Bytes.
SYNTAX:-
# free -b
EXAMPLE:-
SYNTAX:-
# free -k
EXAMPLE:-
SYNTAX:-
#free -m
EXAMPLE:-
29
35.DISPLAY MEMORY IN GIGABYTES:-
Using -g option with free command, would display the size of the
memory in GB(Gigabytes).
SYNTAX:-
#free -g
EXAMPLE:-
SYNTAX:-
#free -t
EXAMPLE:-
30
SYNTAX:-
#free -o
EXAMPLE:-
SYNTAX:-
# free -s 5
EXAMPLE:-
SYNTAX:-
# free -l
EXAMPLE:-
31
40.CHECK FREE VERSIONS:-
The -V option, display free command version information.
SYNTAX:-
# free -V
EXAMPLE:-
32
33