0% found this document useful (0 votes)
12 views

Linux Commands

Uploaded by

rahulraj2901nks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Linux Commands

Uploaded by

rahulraj2901nks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

cat --> to read the contents of a file

cd --> directory move

find --> finds a file or directory in the current directory


syntax : [find <directory name> -name <file name>]:{replace -name with '-
iname' if the casing of name is not remembered}
Example: find usr -name flag.txt --> finds a file named "flag.txt" in the
directory usr and all its sub-directories.

ls --> list all the directory and file in current directory


Attributes: -a or -A --> to get hidden files
-l --> lists files with their information

man --> short for manual, gives you context about what a command is capable of
syntax: [man <command>]

strings --> this converts image file into readable text


syntax: [strings <image name>]
Example: strings flag.jpg --> converts the flag.jpg image into readable text.

grep --> this find a certain patterns of strings in a file


syntax: [grep "<string to find>" <file name>]
Attributes: -i --> ignores the case while searching {Ex: grep -i "<string to
find>" <file name>}
-E --> allows using special search functions inside string {Ex:
grep -E "hello|what" <file name>} - [this will see the string
with either hello or what in the file]
-o --> this returns only the needed string only instead of the
whole line where the string is present
{Ex: grep -o "hello" <file name>}
-r --> this searches the string in directories too {Ex: grep -r
"hello" <directory>}
Example: grep unixit flag.txt

| --> 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.

base64 --> used to encode or decode a file


syntax: [base64 <filename>]
Attributes: -d --> to decode a file
Example: base64 -d flag.txt

steghide --> performs steganography(art of storing one file into another).


syntax: [steghide <first argument> <argument options>]
First arguments: extract --> to extract a one file from another.
syntax: [steghide extract -sf <file> -xf <file2> -p
<password>]
embed --> to embed one file into another
syntax: [steghide embed -cf <file1> -ef <file2> -p
<password>]
info --> to get the information about the encryption of a file
syntax: [steghide info <file name>]
Attributes:
for extract:-
-sf --> to specify the stego file(file containing the hidden
data)
*-xf --> to specify the file for extracted data(not necessary).
*-p --> to give the password.
for embed:-
-cf --> to specify the cover file(the one which will store data).
-ef --> to specify the embeded file.
*-sf --> results of cover and embed file are stored in another
specified file
*-p --> to give the password.
for info:-
*-p --> to give the password.

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

zip --> to zip a file


syntax: [zip <directory name you want to contain zipped files> <files>]
Attributes: -r --> to include a directory and its components in the zipped
folder
-x --> to exclude certain files while zipping
Example: zip archive.zip file1 file2 file3 --> creates zipped file named
archive.zip containing file1,file2 and file3
zip archive.zip -r <dirctory name> --> creates archive.zip containing
<directory name> and its contents.
zip archive.zip file.txt --> if archive.zip already exists this will
add file.txt into it
zip archive.zip * --> this zips all contents of current directory into
archive.zip
zip -r archive.zip <folder> -x "*.log" --> zips folder and its content
into archive.zip except those ending with .log

7z --> to compress or decompress .7z files


syntax : [7z <first argument> <argument options> <filename>.7z]
First Arguments: x --> to extract .7z file
a --> to create .7z file
l --> to view the contents without extracting them
Attributes: -o --> to specify the destination to compress or decompress files
-x! --> exclude file while creating or extracting 7z archive
Example: 7z x archive.7z file1 file2 --> extracts only file1 and file2 from
archive.7z if they exist
7z a archive.7z directory -x!*log -x!file.txt --> creates and
archive.7z containing directory but excludes
file.txt and files ending with .log
7z x archive.7z -o path --> extracts archive.7z to path

gzip | bzip2 | xz --> compression methods


syntax: [Command <filename>]
Commands: Compression- | Decompression-
gzip | gunzip
bzip2 | bunzip2
xz | unxz

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 '}'

You might also like