Linux Commands
Linux Commands
man --> short for manual, gives you context about what a command is capable of
syntax: [man <command>]
| --> this symbol gives the output of one command to another one as input.
syntax: [command1 | command2]
Example: cat file.txt | grep "hello|what" --> (cat reads content of file.txt
and the output is given to grep to find hello)
> --> this writes the ouput of a command to a file without displaying it on screen.
syntax: [command > <filename>]
Example: echp "hello" > new.txt --> prints hello into new.txt without
displaying it on screen.
cmp --> compares files byte by byte(character by character) and lists the first
line of difference(by default).
syntax: [cmp <file1> <file2>]
Attributes: -l --> lists all the difference in files {print format: <byte
number> <character in file 1> <character in file 2>}
-i --> used to ignore the firse N bytes
{Ex: cmp -i 10 <file1> <file2>} --> this will compare files
from 11th byte.
head -->used to display the lines from beginning of the file(by default 10 lines)
tail --> used to display the lines from end of the file(by default 10 lines)
syntax: [head <filename>]
[tail <filename>]
Attributes: -n --> determines the number of lines to display
Example: head -n 7 <filename> | tale -n 1 -->this prints only the 7th line
bcs the second command gives last line of result of
first command.
tar --> used to extract .tar archives and other compressed .tar archives
syntax: [tar (Attributes) <filename>]
Attributes:
Necessary: -x --> to extract a file
-t --> views the content of file without extracting it(like in
winrar)
-c --> creates the archive(i.e. to create a zipped folder)
{Ex: tar -cf <archive name> <filename>} --> creates a
zipped archive with <achive name> that
contains the file <filename>
Optional:
-z --> compress or decompress the archive using gzip(used for {.tar.gz}
or {.tgz}) - depending on x and c
-j --> compress or decompress the archive using bzip2(used for
{.tar.bz2}) - depending on x and c
-J --> compress or decompress the archive using xz(used for {.tar.xz})
- depending on x and c
-C --> extracts files to a specific directory(line Extract to.. button
of winrar)
{Ex: tar -xf archive.tar -C path/destination} --> extracts the
archive.tar into destination
-f --> to specify the file name or the archive name
--exclude --> to exclude a file while extracting or creating .tar(use
each time to exclude each file)
{Ex: tar --exclude='file.txt' --exclude='*.log' -xf archive.tar}
unzip --> used to extract {.zip} files
syntax: [unzip <filename>.zip]
Attributes: -d --> to unzip the files to a directory
{Ex: unzip <filename>.zip -d <directory path>}
-l --> list contents of the file without extracting(like opening
the .zip folder)
-x --> to exclude a file while extracting(selecting unzipping like
only unzipping a single file
{Ex: unzip <filename>.zip -x "file.txt"} --> excludes file.txt
and unzips everything else
{Ex: unzip <filename>.zip -x "*.txt"} --> excludes files ending
with .txt extension
Example: unzip <filename>.zip "file.txt" --> this extracts only file.txt from
<filename>.zip archive
tree --> displays the directory structure of a path in tree like format listing all
its subdirectories directories.
syntax: [tree <path>] --> lists all the
STRING SEARCHES:
| --> OR {Ex: hello|what - searches either hello or what}
[a-z0-9] --> string that contains characters with alphabets a-z and digits 0-
9
\{ --> interprets to '{' as in C because the normal bracket({) is a special
character in Linux like we do in C
Ex: unixit\{[a-z0-9]{32}\} --> a string that begins with 'unixit{' contains
a-z or 0-9 and is of 32 size and ends with '}'