3. Files
cat filename prints file contents in the terminal for reading
less filename paginate the file. space to advance
touch filename create a new file
tail filename –n 10 prints the last 10 lines of the file
mv f1 f2 renames f1 to f2
cp f1 f2 copies f1 to f2
ls –l lists files with permissions
scp –rq user1@host1:/some/f1 user2@host2:some/f2 Securely copy a file between remote destinations
rq – Recursive Quiet
1/23/2016 3
4. Pattern Search
egrep –c ’update_user’ file1 Counts the number of lines with the pattern
Flags
-i ignore case
-l print name of files
-w search for words
-A 3 3 lines after the match
-B 3 3 lines before the match
-C 3 3 lines around the match
-r Search recursively
-n show line number
-v invert the match
-s return if the pattern is matched
1/23/2016 4
5. vi Editor
vi +89 file1 Opens file from line 89
Modes Command Mode – esc
Insert Mode – I
dd Delete line
yy Copy line
p paste
:16 Go to line 16
$ Go to end of line
^ Go to beginning of line
:q
:q!
:wq
Quit
Quit without saving
Save & quit
G Jump to end of file
1/23/2016 5
6. File Compression
tar –zcvf file1.tar.gz input_folder Compress the input folder & archive
tar –zxvf file1.tar.gx Decompress the arvhive into the folder
zip –r app.zip . Compress the current folder into a zip file
1/23/2016 6
7. Links
ln -s abc.txt abc_soft.txt Creates a Soft Link
Soft link points to the file in its current location. Just a
hyperlink. Does not work if the file is moved
ln abc.txt abc_hard.txt Creates a Hard link
Hard link points to the file wherever it is. They have
the same inode value
rm abc_soft.txt Removes the link
rm abc_hard.txt Removes the file
1/23/2016 7