Linux Commands

To increase/decrease the font size in terminal -> Ctrl +/


pwd

It will display the present working directory name


cd

Used to change the directory

  • To Change Directory – cd /cygdrive/D/VLSI/
  • To move previous directory – cd ..
  • To move two directory back – cd ../../
  • Pressing two times tab will provide list of directories

 

ls

To list all the files in the directory


mkdir

To make directory

    mkdir DFT 


rmdir

To remove directory

    rmdir DFT


history

To view history of commands we used


man

To view user manual page

    man pwd


touch

To create file

    touch file1.txt file2.v file3.txt

To create multiple files

    touch file_{1..10}.txt


rm

To remove files

    rm file.txt file.v


mv

To move files from one directory to another directory

       mv /D/VLSI/file.txt  /E/DFT/

To move directory inside another directory

    mv vlsi2020 vlsi2022

To move content of file1 to file2 and delete file1 (to rename file/directory)

    mv file1.txt file2.txt


clear

To clear the terminal


cp

To copy files or groups of files or directories

    cp <source_path><file.extension>[space]<destination _path>

    cp /D/VLSI/Linux/Linux.docx /E/

    cp –r /D/VLSI/Linux /E/ 

To copy directory with files use –r option


cat

To display the content of file

       cat file_name.txt

To write/overwrite the content

    cat>file_name.txt

To create new file and write content

    cat>file_name.txt

To add a content without overwriting the old content

    cat>>file_name.txt

(>  Redirecting Symbol, To copy/write a content to file)


Ctrl D

To exit


Ctrl Z

To stop the current job


head

To display top 10 lines of the file

    head suku.txt

To display top 4 lines of the file

    head -4 suku.txt


tail  

To display bottom 10 lines of the file

    tail suku.txt

To display bottom 4 lines of the file

    head -4 suku.txt


tac

To display content in reverse order

    tac file_name.txt


more

To reads files and displays the text one screen at a time

    more file_name.txt


nl

To display the content in the file with line number

    nl file_name.txt


wc

To count number of lines, words, and characters...

To display number of lines

    wc –l file_name.txt

To diplay number of characters

    wc –c file_name.txt

To display number of words

    wc –w file_name.txt


uniq

To ignore continuous duplicate entries in the file

    uniq file_name.txt


diff

Compare the two different file's content and display the difference between them

    diff file1.txt file2.txt


cmp

To compare two files content, byte by byte and help us to ensure two files are identical or not (if it doesn't match, it will display line number and character number)

    cmp file1.txt file2.txt


sort

To sort the things in ascending order

    sort file_name.txt


To sort the things in descending order

    sort –r file_name.txt


chmod

To change the access to the file or directory 

    r – read o – others

    w – write u – user

    x – execute     g – group


    chmod u+x file_name.txt

    chmod g+r file_name.txt

    chmod o+w file_name.txt

    chmod u-x file_name.txt

    chmod 777 file_name.txt (all permission for all)

    chmod 662 file_name.txt (read/write permission to user/group and write permission to others)


Command with Option:

Syntax: command –option file_name

To list out files details in long format

    ls –l


To list out hidden files

    ls –a


Piping Concept

Used to combine one or more commands.

Output of one command is to be input of next command by using symbol “|

command 1 | command 2

    cat file_name.txt | wc

If we use > (redirecting symbol) in between the pipe, will break the piping. To avoid this use tee command.


tee

it is used to avoid breaking in pipe concept


regex (Regular Expression)

to searc/match the patterns

to use meta/wild card characters

ls *.*

ls ???.*

ls *.txt

ls [a-z].*

ls [0-9].*

ls a*.*

ls a*s.*

ls ??.txt

ls [!abc]*.* (! - not)

ls [[:upper:]].txt

ls [A-Z][0-9][a-z].*

ls [![:alnum:]]*.txt (files not start with alphabets and numbers)

ls {*.java,*.PY}

ls [[:alphabet:]].txt

xargs

to pass arguments to the commands

Example:

cat test.txt

t1.txt

t2.txt

cat test.txt | xargs rm  

seq

seq 10 | xargs –i touch {}

find

find <file path>

find <file path> –type d “*”

find <file path> –type d -name “*” 

find <file path> –type d -name “[0-5]”

find <file path> –type f  -name “*.txt” –mmin  +60

find <file path> –type f -name “*.txt” –mtime  +60

find <file path> –type f –mmin +60

-cmin 

-mmin 

-amin 

-newer

-

Example:

find /cygdrive/D/ -name “VLSI” -type d 

find /cygdrive/D/ –type f –mmin +60

history

to list out previously used commands

alias

it is used to notate long command in short notation

alias m=”mkdir”

alias ll=”ls –ltr”

unalias

to remove alias

unalias ll

unalias m


to edit gvim files:

gvim ~/file name

gvim ~/.bashrc

source ~/.bashrc

popd 

To pop the directory in stack (LIFO)

pushd

To push the directory in stack (FILsO)

grep – global regular expression pattern

- It is used to search the pattern

Syntax:

grep option “pattern” file_name


Example:

grep –o “unix” file.txt

awk

It is used for database manipulation. It enables a programmer to write tiny but effective programs in the form of statements


Environment variable/Global Variable

$SHELL

$PATH


X = “hello”

echo x


Data Processing/Data Manipulation Command

sed – stream editor

- To inserter, search/replace, delete particular line or to delete lines in range

sed 5d test.txt

sed 1,3d test.txt

sed 5,$d test.txt

sed ‘s/unix/linux/ ’ test.txt

sed ‘s/linux/unix/g’ test.txt (g - global)

sed ‘s/unix/linux/ 2’ test.txt

sed ‘s/fish/a  “This is sukumar”’ file.txt

sed ‘s/fish/i  “This is sukumar”’ file.txt 

No comments:

Post a Comment

D-Algorithm

Inducing the fault in any node and propagating the fault effect from the fault site to the primary output is called D-Algorithm. D-Algorithm...