Linux Commands
Linux Commands
Linux Commands
1) pwd
Syntax: pwd
2) cd
The "cd" stands for 'change directory' and this command is used to
change the current directory i.e; the directory in which the user is
currently working.
Syntax:
cd <dirname>
Example: cd student
The mkdir stands for 'make directory'. With the help of mkdir command,
you can create a new directory wherever you want in your system.
Example: mkdir r1 r2 r3
3
rmdir command is used remove empty directories from the file system
in Linux.
The rmdir command removes each and every directory specified in the
command line only if these directories are empty.
File related commands: cat, cp, rm, mv, ls, chmod, wc, diff, cmp
1) cat
1) hello
2) how are you
4
- Create a file
Syntax: cat >newfile
Output: Will create and a file named newfile
- Cat command can append the contents of one file to the end of
another file.
Syntax: cat file1 >> file2
Output: Will append the contents of one file to the end of another file
2) cp
3) rm
The 'rm' means remove. This command is used to remove a file. The
command line doesn't have a recycle bin or trash unlike other GUI's to
recover the files. Hence, be very much careful while using this
command. Once you have deleted a file, it is removed permanently.
Syntax:
rm <filename>
Example:
rm myfile1
4) mv
mv sample2 /home/stu/Documents
5) ls
If you want to see the list of files on your UNIX or Linux system, use
the 'ls' command.
Syntax: ls
6) chmod
Syntax:
= (set) the modes specified are to be made the exact modes for the
specified classes
7) wc
The 'wc' command helps in counting the lines, words and characters in a
file.
Syntax:
Usage: Counts number of characters, words and lines in given input file.
If file is not given, it takes input from standard input.
Example:
wc exm.txt
wc -l exm.txt
wc -w exm.txt
wc -c exm.txt
8) diff
diff stands for difference. This command is used to display the
differences in the files by comparing the files line by line.
Syntax: diff file1 file2
Usage: Compares two files, gives location of mismatch as well as
suggests changes to make two files identical.
9) cmp
Compare two files, and if they differ, tells the first byte and line number
where they differ.
Syntax: cmp file1 file2
Usage: compares two files and gives location of first mismatch.
1) cal
Calendar
If a user wants a quick view of calendar in Linux terminal, cal is the
command for you. By default, cal command shows current month
calendar as output.
cal command is a calendar command in Linux which is used to see the
calendar of a specific month or a whole year.
8
Syntax:
cal displays calendar of the current month
cal year# displays calendar of the particular year
cal month# year# displays calendar of the particular
month of a particular year
Usage: Display calendar.
2) date
date command is used to display the system date and time. date
command is also used to set date and time of the system. By default the
date command displays the date in the time zone on which linux
operating system is configured. You must be the super-user (root) to
change the date and time.
Syntax: date
Usage: Displays current date and time.
3) echo
echo command in linux is used to display line of text/string that are
passed as an argument . This is a built in command that is mostly used in
shell scripts and batch files to output status text to the screen or a file.
Syntax: echo message
Usage: Displays message as well as evaluates variables.
Example:
echo “hello world..!” //Displays message
echo $count //evaluates variable count
9
4) passwd
passwd command in Linux is used to change the user account
passwords. The root user reserves the privilege to change the password
for any user on the system, while a normal user can only change the
account password for his or her own account.
Syntax: passwd
Usage: changes password of an user
5) who
Syntax:
Usage: Displays information about all users who have logged in to the
system currently.
6) man
Usage: Print entries from the on-line reference manuals, find manual
entries by keyword
In short it displays on-line help about title, title can be a command name,
system call or function name.
Example: man ls
1) head
The head command, as the name implies, print the top N number of
data of the given input. By default, it prints the first 10 lines of the
specified files. If more than one file name is provided then data from
each file is preceded by its file name.
Syntax: head [-n] filename
Usage: Displays top of the file. By default, it displays first 10 lines of a
file, but if used with –n option display first n lines of a file.
Where, n indicates number of lines to be display from top of a file.
Example:
head test.txt by default displays first 10 lines of a file test.txt
head -20 test.txt displays first 20 lines of a file test.txt
2) tail
file name is provided then data from each file is precedes by its file
name.
Example:
tail test.txt by default displays last 10 lines of a file test.txt
tail -20 test.txt displays last 20 lines of a file test.txt
3) sort
4) grep
The grep filter searches a file for a particular pattern of characters, and
displays all lines that contain that pattern. The pattern that is searched
in the file is referred to as the regular expression (grep stands for global
regular expression print)
12
Syntax:
Example:
5) cut
The cut command in UNIX is a command for cutting out the sections
from each line of files and writing the result to standard output. It can be
used to cut parts of a line by byte position, character and field. Basically
the cut command slices a line and extracts the text. It is necessary to
specify option with command otherwise it gives error.
Syntax:
Example:
state.txt
Andhra Pradesh
Bihar
Chhattisgarh
13
6) paste
Examples:
Unix
Linux
Windows
Dedicated server
Virtual server
14
By default, the paste command merges the files in parallel. The paste
command writes corresponding lines from the files as a tab delimited on the
terminal.
Windows
Windows
Unix|Dedicated server
Linux|Virtual server
Windows|
7) tr
15
Examples:
tr –s ‘ ‘ < test.txt
it will compresses multiple consecutive spaces.
Process related: ps, time, kill
16
1) ps
ps is one of the basic Unix commands that helps you access information
about processes running on your system.
Syntax: ps [options]
Options:
f: full listing showing the PPID (parent process ID) of each process
2) time
I) Real time: total time from the invocation of the command till its
termination.
II) User time: actual time spent by program in execution of itself.
iii)System time: time spent by kernel in doing work behalf of the user
process, means providing services to requests such as reading data from
a file stored on disk.
3) kill
Examples:
kill 125
kill -9 127
Others: expr
1) expr
The expr command in linux evaluates a given expression and displays its
corresponding output. It is used for:
Options:
Examples:
expr 5 + 3
expr $x \* $y