Unix_Commands
Unix_Commands
rm - remove a file
rm * - delete all files in working directory
rm -r - delete a folder which have files inside it.
rmdir - delete only an empty folder
cp - copy a file
cp -i - prompt before overwrite
cp -p - copy file with same timestamp
cp -r - copy a directory
ls - List the files and directories in horizontal way and also in alphabetical
order.
ls -lrt - List the files and directories with permissions, date and time and size
ls -l |grep -v '^d' - To list only the files
ls -lrt |grep '^-' - To list only the files
ls -lrt |grep '^d' - To list only the directory
ls -d */ - To list only the directory without permissions
ls -lrta -To list the files and hidden files
ls -a - To list the files
ls * - Shows the files in subdirectory
ls -l path name - To list the files under the directory in same path
ls -l - Sort the files
ls -R - Shows the files in subdirectory
chmod 777 filename - To change permissions for user or owners, groups and others
read(r) - 4
write(w) - 2
execute(x) - 1
no permission(-) - 0
chmod u=rwx,go=rx file1 -->symbolic mode u-user, g-group, o-others
chown [options] user[:group] file -->change ownership
chgrp [options] group file-->change group
split -l file - split a file into many parts as per the line given
sort file - arrange files in ascending order
sort -d file - arrange files in dictionary order
sort -r file - arrange files in decending order
sed 's/find/replace/g' file - find a word and replace without going in vi editor (temporary
change)
sed '/^$/d' file - to remove blank/empty lines from a file and it will not save only for
display.
==========================vi editor===================
vi file.txt - create a new file or open an existing file
vi -R file - view a file in Read only mode
====================insert mode======================
i - insert mode to edit a file
I - inserts text at beginning of current line
a - inserts text after current cursor location
A - inserts text at end of current line
=====================esc mode=========================
esc d shift g -->to delete all the lines below from where the cursor is placed.
cc (or) S - delete a line and goes in insert mode
cw - delete a word and goes in insert mode
dd - delete a line
dw - delete a word
yy - copy a line
yw - copy a word
p - paste
shift + 4 - cursor moves to end of a line
shift + 6 - cursor moves to start of a line
w - cursor moves to start of the word in a line
e - cursor moves to end of the word in a line
J - join the current line with the next one
h - cursor moves to left
l - cursor moves to right
k - cursor moves to up
j - cursor moves to down
u - undo a process
ctrl + r - redo a process
r - replaces the character under the cursor
CTRL + u - Moves screen up 1/2 page
CTRL + d - Moves screen down 1/2 page
CTRL + b - Moves screen up one page
CTRL + f - Moves screen down one page
============command mode========================
:e! - undo a process
:f filename - renames current file to new filename
:w filename - write to file filename
:e filename - opens another file with filename
:cd dirname - changes current working directory to dirname
:e# - use to toggle between two opened files
:n - in case you open multiple files using vi, use :n to go to next file in the series
:p - in case you open multiple files using vi, use :p to go to previous file in the
series
:N - in case you open multiple files using vi, use :N to go to previous file in the
series
:set ic - ignores case when searching
:set number - displays lines with line numbers on the left side
:set nonumber - removes line numbers
:%s/search/replace/g - find and replace the words in a file
:w - save
:q - quit
:w! - save & overwrite
:q! - quit quit
:wq - save and exit
:wq! - save and exit overwrite
:x! - save and exit
esc + shift + zz - to save and exit without going in command mode
. profile - contains set of instructions when user logged in (It will change based on the
OS).
.bash_profile --> To see aliases which have been set (It will change based on the OS).
. .profile --> to run the aliases set file using this command.