File Commands

ls     //listout directory and file name only
ls -l or ll     //long listing
ls -lrt or ll -rt     //reverse order use time
ls -lS or ll -S     //sort by file size
ls -la or ll -a     //list out the hidden files and directory

pwd     //current/working directory
cd     //default home directory
cd directory_name     //open directory
cd ..     //change back to one step
cd -     //change previous path
cd /dir_1/dir_2/dir_3/dir_4
vdir -l     /sample/ //list the directory

mkdir directory_name     //create a directory
makdir directory_1 directory_2 directory_3     //create a multiple directory in same location
mkdir -p /dir_1/dir_2/dir_3/     //create a Parental with Subdirectory

File Create and Edit:

  1. cat     //concatenate
  2. touch
  3. vi editor
  4. nano

cat command     //(only file create, add text and extra add text)

cat > file_name     //create a new file and add the text
cat file_name     //only view the file
cat >> file_name     //old file add text
cat file_1 > file_2     //copy the file
cat -n file_name     //number all output lines
tac file_name     //reverse print

touch command (create single,multiple empty file and change file timestamps)

touch file_empty
touch file1 file2 file3     // create multiple empty files
touch -t 2001011230 file_name     //use YYMMDDhhmm instead of current time

vi editor (vi Command)

vi editor modes:


insert mode
escape mode
command mode


Insert Mode:

vi file_name (press any one a,s,i,o letter to insert)

Escape Mode:

w     //only save file
q     //unsave and quit(exit file)
!     //force
wq     //save and quit
wq!     //force save and quit

Command Mode: (Press ESC Key)

gg     //cursor goes to first lines
shfit + g     //cursor goes to last line
10gg     //cursor goes to 10th line
yy     //current line copy
3yy     //3 line copy
pp     //paste
dd     //delete the line
5dd     //delete five lines
dw     //delete single word
d5w     //delete 5 words
x     //delete single letter
10x     //delete 10 letters

Find and Replace: (Press ESC Key)

%s/source_text/target_text/g

Copy Commands:

cp file1 file2     //copy file f1 to file f2
cp oldfile /home/siva/newfile
cp -rf file1 file2

cp -R /home/siva/d1 /home/muthu/d2
nohup cp -rf /zzz/ /xxx
cp -rf /zzz/ /xxx &     //background copy
jobs     //list background process

Move Commands:

mv old_file new_file
mv old_file /home/siva/newfile
mv /home/muthu/d1 /home/siva/d2


Remove Commands:

rm filename
rm -rf filename
rmdir dir_name
//remove empty directory
rm -rf dir_name //directory which have contents

Head and Tail Commands:

head file_name     //display first 10 lines
head -5 file_name     //display first 5 lines
tail file_name     //display last 10 lines
tail -5 file_name     //display lst 5 lines
head -6 file_name|tail -2     //display 5th and 6th line only
cat file_name|head -6|tail-2

Word Commands:

wc file_name     //list of lines,words,letters
wc -c filename     //show letters only
wc -l file_name     //show lines only
wc -w file_name     //show words only
less filename
more file_name

nl file_name     //number lines of file
sort file_name     //sort lines of text files
sort file_name|uniq     //remove duplicate text
comm file_1 file_2
diff file1 file2
diff3 file1 file2 file3
cmp file1 file2
    //compare two files byte by byte
dd if=file1 of=file2 conv=ucase or lcase     //Data duplicator and used for copying and converting data

Comments