UNIX Commands
mkdir - make a directory
pwd - present working directory
cd - change directory
cd ~ - goes to home directory
cd ../ - goes to previous directory
cd - - between two directories
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
mv - move a file and also to rename a file
mv -i - prompt before overwrite
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
grep -->global regular expression print.
grep -i - search words case insensitively
grep -ir - search words within the directory
grep -l - list the files that has searched words
grep -n - shows the files with line number that has searched words
grep -c - shows the files with no of count of words that matches
find . -name "filename" --> searches the file in all directories.
find ./ -name "file.txt" - shows the path that has given file
find /pathname -perm 775 - to view the files with given permissions
find . -name word -print - to print the files that has given words -->not working
find ./ -name "direc name" - shows the path that has given directory
find ./ type f -empty - to list the files that is empty
find ./ type d -empty - to list the directory that is empty
find ./ -name "*.sql" --> show the path that has given file extension.
find . -type f -mtime -1 --> search files edited in the last 24 hours. here -1 represents 24
hours you can give -2 for 48 hrs and so on.
find . -type f -mtime -1 -delete -->delete all the files in the last 24 hours.
wc -l - shows the no of lines in a file
wc -c - shows the characters of a file
wc -w - count the no of words in a file
du -sh file.sql - shows the size of a file
tar --> the file storage will be in increased.
tar -cvf file.tar files - tar a file
tar -xvf file.tar - extract tar files
tar -tvf test.tar - show the extracted files from tar
zip -->the file storage will be reduced.
zip file.zip file - to zip a file
zip -d file.zip file1 - delete a file from zip
zip -u file.zip file3 - update a file inside zip
zip -m file.zip file1 - delete original file after zip
zip –r filename.zip directory name - zip a directory
unzip file.zip - to unzip the compressed files
head -n file - shows upper lines (default 10 lines)
head -100 file |tail -1 --> to print 100th line in a file
tail -n file - shows lower lines
tail -100 file | head -1--> to print 1st line in a file
touch file1 file2 - create files without opening
man command – help
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.
cat file - display the contents of a file
more file - display the contents of a file
diff file1 file2 - shows the difference between two files
ln - link the two files
clear - to clear the viewed files
cmp - to compare two files byte to byte to display the first mismatches
cut -c1,2 file - extract specific characters from the file
cut -d '|' -f1 filename ---> extract whole field from the file
uname -a - to find the operating system in Unix
date - to display the date
cal - to display the calendar
who am i - to know the user
12,18s/^/-- - to print -- in front of each line of the file line 12 to 18
12,18s/$/+ - to print ++ in back of each line of the file line 12 to 18
ftp - used to copy files across system
df - to check the disk space
du - to summarize the disk usage
ps -ef|grep processed/service name - to find currently running process in unix
kill -9 6806 - to kill a process from file_6806_0519.trc
kill -1 -9 - to kill all the running process (Please don’t use this command unless get the
approval)
cd $TBA_SQL - to go to product sql path
cd $TBA_SCRIPTS - to go to product script path
==========================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
- creates a new line for text entry below cursor location
- creates a new line for text entry above cursor location
=====================esc mode=========================
x - Deletes the character under the cursor location
X - Deletes the character before the cursor location.
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.