In this post, I am going to share very useful and commonly used basic UNIX/Linux commands.
Basic UNIX Commands
man
The man command displays the online manual pages. Reads the manual page for a command.
Syntax: man command_name
Syntax: man command_name
ls
This command is used to list all the files and directories.
ls – l
It is called as the long list. It displays or lists all the files with their preferences.
ls – a
This command is used to view all the hidden files.
mkdir
This command is used to create a directory.
Syntax: mkdir dirname.
cd
This command is used for changing the directory
cd .
Changes the home directory.
cd ..
Changes the parent directory.
pwd
This command displays the path of the current directory.
cp
Copies the contents of one file to another.
Syntax: cp file1 file2
mv
This command is used to move or rename the files.
Syntax: mv file1 file2
rm
This command is used for removing or deleting a directory.
Syntax: rm file
rmdir
This command is used for removing or deleting a directory.
Syntax: rmdir directory
cat
This command is used to display a file.
Syntax: cat filename
Syntax: cat filename
cat:
This command is used to concatenate the files.
Syntax: cat file1 file2 >file3
more
This command is used to display a file a page at a time.
Syntax: more filename
head
This command is used to display the first few lines of a file.
Syntax: head -n/+n filename
-n: n lines from the beginning are printed.
+n: n-1 lines are skipped or start from the nth line.
-n: n lines from the beginning are printed.
+n: n-1 lines are skipped or start from the nth line.
tail
This command is used to display the last few lines of a file.
Syntax: tail -n filename
-n: n lines from the end are displayed.
-n: n lines from the end are displayed.
wc
This command is used to count the number of lines/words/characters in the file.
Syntax: wc <option(s)> filename
-w: To do a word count.
-l: To find out how many lines the file has.
-w: To do a word count.
-l: To find out how many lines the file has.
grep
This command is used to grap regular expressions and patterns. It is used to search for a particular word in a file.
Syntax: grep <option(s)> keyword filename
-i: Ignores the case of the word.
-v: Prints the lines that do not match.
Syntax: grep <option(s)> keyword filename
-i: Ignores the case of the word.
-v: Prints the lines that do not match.
pipe
It is used to join two or more commands where the output of command1 is the input of command2.
Syntax: command1| command2
Syntax: command1| command2
sort
This command is used to sort the content or data.
Syntax: sort <option(s)> filename
-n: Numeric sort.
-r: Reverse sort.
-d: Directory sort.
who
Lists users currently logged in.
Syntax: who >filename
?: Matches one character.
*: Matches any number of records.
?: Matches one character.
*: Matches any number of records.
what is
Offers a brief description of a command.
apropos
Matches command with the specified keyword in their man pages.
Syntax: apropos keyword.
Syntax: apropos keyword.
ps
This command is used to list the current processes.
chmod
This command is used to change the access rights for the named file.
Syntax: chmod [options] filename
-u: User
-g: Group
-o: Others
-a: All
-r: Read
-w: Write
-x: Execute
-+: Add permission
--: Take away permission
-u: User
-g: Group
-o: Others
-a: All
-r: Read
-w: Write
-x: Execute
-+: Add permission
--: Take away permission
df
This command is used to report the space left on the file system.
Syntax: %df
du
The number of kilobytes used by each subdirectory.
Syntax: %du
nl
Appends line number. No number for empty files.
egrep
Useful for multiple patterns matching can be made file-based by –f option.
Syntax: egrep <options> filename
-c+: One or more occurrences of character.
-c+: One or more occurrences of character.
-c?: Zero or one occurrence of a character. -a/b: Either a or b.
-(a): Regular expression.
-(a): Regular expression.
fgrep
Fast or fixed grep. It does not accept regular expression. In this one command is separated from the other by new line.
Syntax: fgerp ‘abc newline xyz’
Syntax: fgerp ‘abc newline xyz’
tee
Directs the output to the standard output device. Syntax: tee <option> filename
-a: Appends to a file.
-a: Appends to a file.
find
This command is used to search for a file.
Syntax: find <option> filename
-atimen: True if file was accessed n days ago
Syntax: find <option> filename
-atimen: True if file was accessed n days ago
-ctimen: True if file was created n days ago.
-namepattern: True if filename matches the pattern.
-print: Print names of files found.
Cmp
This command is used to compare two files.
Syntax: cmp file1 file2 [skip1 [skip2] ]
ReturnType:
0-files are identical
0-files are identical
1-files are different.
>1-an error occurred.
Diff
This command is used to find differences between two files.
Syntax: diff [options] from-file to-file.
Return Type:
Return Type:
-0 no difference
-1 some differences were found
-2 trouble.
-1 some differences were found
-2 trouble.
Comments
Post a Comment
Leave Comment