0% found this document useful (0 votes)
165 views12 pages

Unix Commands

This document provides a summary of common UNIX commands for file management, directory management, searching files with grep, remote file copying with scp, changing file permissions with chmod, using pipes to combine commands, and using the VIM text editor. It outlines commands for listing, viewing, copying, moving, deleting, renaming files and directories. It also describes commands for navigating, inserting, deleting, copying and pasting text in the VIM editor.

Uploaded by

Avirup Mullick
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
165 views12 pages

Unix Commands

This document provides a summary of common UNIX commands for file management, directory management, searching files with grep, remote file copying with scp, changing file permissions with chmod, using pipes to combine commands, and using the VIM text editor. It outlines commands for listing, viewing, copying, moving, deleting, renaming files and directories. It also describes commands for navigating, inserting, deleting, copying and pasting text in the VIM editor.

Uploaded by

Avirup Mullick
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 12

8/4/16

UNIX COMMANDS

File Management
ls

List of all files and folders present in the current directory

ls l

More information, like permissions, date, size, owner name

ls ch*.doc

Displays all the files whose name start with ch and ends
with .doc

ls a

Displays hidden files and folders

vim filename

Creates a new file named filename to be edited in Vim


editor

cat filename

Displays the content of a file filename

cat b filename

Displays the content of the file filename along with line


numbers

cp source_file
destination_file

Makes a copy of source_file and names it as


destination_file

mv old_file new_file

Renames the old_file to the given new_file name

rm filename

Deletes the file filename

8/4/16

Directory Management
ls dirname

Lists the files in the directory dirname

mkdir dirname

Creates a directory named dirname

rmdir dirname

Removes a directory named dirname

cd dirname

Change the current working directory to dirname

mv olddir
newdir
. (dot)

Renames olddir directory to newdir

.. (dot dot)

Represents the directory one level above the current working


directory

/ (slash)

Represents root directory

~ (tilde)

Represents home directory

pwd

Shows current working directory

8/4/16

Represents current working directory

grep command
Used to search a file or files for lines that have a certain pattern
grep pattern file/files
Some options are listed below

-v Print all lines that do not match pattern.


-n Print the matched line and its line number.
-l Print only the names of files with matching lines.
-c Print only the count of matching lines.
-i Match either upper or lowercase.
8/4/16

Some more Commands


scp : Allows files to be copied to, from, or between different hosts.
Remote to Local
scp your_username@remotehost.edu:foobar.txt
/some/local/directory
Local to Remote
scp foobar.txt
your_username@remotehost.edu:/some/remote/directory
scp -r foo
your_username@remotehost.edu:/some/remote/directory/bar

chmod : Used to change permissions (read, write, execute) for files


and directories
8/4/16

Example of pipes
ls -l | grep "Aug" | sort +4n
-rw-rw-r--rw-rw-r--rw-rw-rw-rw-rw-rw-

1
1
1
1

carol
john
john
john

doc
doc
doc
doc

1605
2488
8515
11008

Aug 23 07:35 macros


Aug 15 10:51 intro
Aug 6 15:30 ch07
Aug 6 14:10 ch02

Series of commands can be piped, output of one becomes the


input to next command
sort +4n sorts the results numerically after skipping first 4
fields (size field)
8/4/16

VIM editor
Two modes Command and Edit
Command Mode Used to perform tasks like saving, copy-paste, findreplace, etc.
Edit Mode Used to edit the file by writing into it
Some commands:-

8/4/16

:q
Quit vi, raises warning if file is changed
:q!
Quit without saving any changes
:w
Save all changes in the file
:wq
Save and quit
ZZ
Save and quit
:w nfile
Saves the current file with a different filename nfile

VIM editor - Some Commands


h, j, k, l : Used to navigate through the text
w moves to start of next word, e moves to end of word, b moves to
beginning of word

% finds matching parenthesis


0 moves to beginning of the line, $ moves to end of the line
* finds next occurrence of the word under cursor, # finds previous
gg

takes us to the beginning of the file,

to the end of the file

5G takes us to 5th line


8/4/16

VIM editor Edit commands


Some commands:i Inserts text before current cursor location.
a Inserts text after current cursor location.
I Inserts text at beginning of current line.
A Inserts text at end of current line.
o Creates a new line for text entry below cursor
location.

O Creates a new line for text entry above cursor


location.

8/4/16

VIM editor Delete commands


Some commands:x

Delete current character

dw Delete current word


dd Delete current line
5d Delete five lines
d
d$ Delete till end of the line
d0 Delete from beginning of the
line

8/4/16

10

VIM editor Copy/paste & Undo/Redo commands


Copy paste is done in following order
Position cursor at beginning of the text to be copied
Press

v to enter character based visual selection mode

Move the cursor to select the desired portion of text to be copied


Press

y to copy

Move the cursor to the location where the text has to be pasted
Press

p to paste

Press u for UNDO


Press Ctrl+R for REDO

8/4/16

11

THANK YOU
8/4/16

12

You might also like