Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

linux commands:

--------------------------
1)/ ->root or parent directory
2)pwd ->it displays present working directory
3)/root -->Is the default home directory for user root
4)cd ->to change the directory

creation of files:
-----------------------
->we can create files in three ways..1)cat 2)touch 3)vi

touch :-it is used to create empty files.


------
->we can't append data into files by using touch command

syntax:touch filename

ex:
----
1)creation of single file:
---------------------------
-> touch aws (here aws is the file name)

how to check whether file is created or not:


---------------------------------------------
ls:it list current directory all files and sub directories
->ls

ll:it list the files and directories in long format


->ll

2)creation of multiple files:


-----------------------------
->touch file1 file2 file3
->ls

cat:- it is used to create new files or to open existing files or to append data to
the existing files.
-----
syntax:cat > filename

how to save data into file :


-----------------------------
ctrl d

how to crate a file by using cat command:


-------------------------------------------
1)cat > sample (here sample is the file name)
linux is an operating system
it is easy
2)ctrl d (to save the content in a file)

How to view the content in the file:


-----------------------------------------
cat sample (cat filename)

How to add content already existing file:


---------------------------------------------
cat >> sample (here sample is already existing file and some content is there)
linux mostly used in portble devices
current version is 3.10

ctrl d

cat sample

How to redirect the content from one file to another file:


------------------------------------------------------------

cat > linux


hi good morning

ctrl d

cat sample > linux (here the content of sample redirect to linux)

How to see the content more than one files at a time:


-----------------------------------------------------
cat sample linux

Deleting Files:
----------------
rm:- this command is used to delete a file
syntax: rm filename

->whenver you are using rm command to delete a file it is asking a permission


->then you just type 'y'
->then the file is removed

ex: rm aws
->rm: remove regular empty file 'aws' ? y
->file is deleted

I don't need ask a permission to delete a file:


------------------------------------------------
-> rm -rf linux (file is deleted without asking permission)

How to delete a multiple files at a time:


------------------------------------------
-> rm -rf file1 file2 file3

creation of directories:
-------------------------
->mkdir: this command is used to create a new directory
syntax: mkdir dirname

ex: mkdir abc

How to change a directory:


-------------------------
-> cd abc
->mkdir aws

NOTE:
-----
# cd --to come out the directory

# cd ../.. --to change two directories back

# cd ../../.. --to change three directories back

# cd (enter) --to goto the user home directory

# cd / --to goto the / directory

How to create multiple directories at a single time:


-----------------------------------------------------
-> mkdir abc def ghi jkl

Removing directories:
----------------------
rmdir: to remove a directory but directory must be empty

ex: rmdir abc

ex1:i craeted abc directory in my root


cd abc (abc directory change to root)
under abc directory i created mkdir xyz (i created xyz under abc directory)
cd (i come out abc directory)

how to delete abc directory:


------------------------------
rm -rf abc

Copying a files:
----------------
cp: this command is used to copy a files

syntax: cp source file target file

->source file must be existing file and target file may be new file or may be a
existing file.

NOTE:
------
1)Any path starts from ("/") root directory known as Absolute path.
2)If path not started with ("/") root directory known as Relative path.

ex:-
-----
1) cp notepad notepad1 (here not is al existing file and notepad1 is the new
file)

2)cp -r abc d1 (here abc directory copied into d1 directory)

3)cp f1 f2 d2 (here f1 , f2 files copied into d2 directory)

Moving files or Rename a files:


------------------------------------
mv: to rename a file / directory (or) to move a file / directory
ex:
1)mv file1 file2 (here file1 is renamed by file2)
2)mv dir1 dir2 (here dir1 is renamed by dir2)

some commands:
---------------

1)ls -l filename (this command used to see the particular file)

2)ls -Q (this command used to make the all files in quatations)

3)ls -r (this command used to reverse the files)

4)ls - R (it list all files Recursively)

5)ls -t (it list all files based on date and time of creation)

6)ls -i (it display the inode numbers)

7)ls -sh (to display the file size)

8)whoami (it display the switched user name or child user name)

9)exit (to logout from current user account)

10)man commandname (it displays help pages of given command)

11)clear (to clear the screen)

12)cal (it displays current month calender)

13)date (it displays system date and time)

14)uname (it displays operating system name)

15)uname -r (it displays kernel version)

16)hostname (it displays server name)

17)hostname -i (it displays server IP address)

18)history (it displays previously executed commands list)

19)ls -ltrah (to display last modified files)

Creating Hidden files:


------------------------
->Any filename or directory name start with "." character is called hidden files

how to create hidden files:


-----------------------------

cat > .filename

ctrl d

how see hidden files:


---------------------
ls -a

ls -l f* (it displays all files with start 'm' character)

WORKING WITH VI-EDITOR :


--------------------------
-> vi is visual editor

->it is used for to create new files ,to open files or to modify existing files

->it has 3 modes

1)command modes
2)input or insert modes
3)Ex command mode

->The default mode is command mode


->vi is the command to open vi editor

How to create a file:


---------------------

-> vi filename

modes:
--------

1)Esc i (it is the insert mode to write the data)

2)Esc :se nu (to set the line numbers in the file)

3)Esc :se nonu (to remove the line numbers)

4)Esc :wq! (to save the file and quit)

5)Esc :q! (quit without save if the file is modified or updated)

6)Esc o (to add the line below the cursor)

7)Esc O (to add the line above the cursor)

8)Esc G (move the cursor file line to last line)

9)Esc gg (move the cursor last line to first line)

10)Esc yy (to copy the line)

11)Esc p (to paste the line)

12)Esc dd (to delete the line)

13)Esc dw (to delete the word)

14)Esc x (to delete a character)

15)Esc A (to move the cursor end of the line)

16)Esc W (move the cursor word by word)


17)Esc yw (to copy the word)

How to open multiple files at a time:


-----------------------------------------
vi -o filename filename

You might also like