IBT Linux Session 2 Part 2 Intro To Linux Sumir Panji
IBT Linux Session 2 Part 2 Intro To Linux Sumir Panji
Sumir Panji
Acknowledgements: Amel Ghouila
• The less command displays a text file content, one page at a time – differs
from more as allows backward and forward scrolling e.g. man less
•head command displays a text file content, by default: 10 first lines at a time
head [options] filename.fasta
•tail command displays a text file content, by default: 10 last lines at a time
tail [options] filename.fasta
• use –n switch to change the number of lines you want to display e.g.
tail –n 100 filename.fasta
head –n 100 filename.fasta
File manipulation commands
➔ Copy the contents of file1 into file2. If file2 does not exist, it is created.
Otherwise, file2 is silently overwritten with the contents of file1.
● cp filename dirpath
➔ Make a copy of the file (or directory) into the specified destination directory
File manipulation commands – Copy (cp)
● To prevent over writing file contents, can use the interactive mode with the cp
command with the option -i
● cp -i file1.fasta file2.fasta
➔ Same as the previous one. However, if file2 exists, the user is notified
before overwriting file2 with the content of file1
● cp –R pathdir1 pathdir2
➔ Copy the contents of the directory dir1. If directory dir2 does not exist, it is
created. Otherwise, it creates a directory named dir1 within directory dir2
File manipulation commands – Move (mv)
The mv command moves or renames files and directories depending on how it is used
● To rename a file:
mv filename1 filename2
If file2 exists, its contents are silently replaced with the contents of file1. To avoid overwriting,
use the interactive mode:
mv -i filename1 filename2
● To move a file (or a directory) to another directory:
mv file dirpath
● To move different files (or a directory) to another directory:
mv file1 file2 file3 dirpath
● To move directory to another directory:
mv dir1 dir2
If dir2 does not exist, then dir1 is renamed dir2. If dir2 exists, the directory dir1 is moved within
directory dir2
File manipulation commands – Remove (rm)
The rm command deletes files and directories (beware!!)
● To remove a file:
rm filename
● To remove many files:
rm filename1 filename2
• Once you delete something with rm, it's gone! There is no “trash bin” or
deleted items storage to retrieve it from
• You can inflict terrific damage on your system with rm if you are not careful,
particularly with wildcards
• Try this trick before using rm: construct your command using ls instead
first
Wildcards
• Since the shell uses filenames so much, it provides special
characters to help rapidly specifying groups of filenames
• Try the commands presented in this session to view the contents of the
file you downloaded from the previous session:
https://zivahub.uct.ac.za/ndownloader/files/54135611
• Make a copy of the file, mv a copy to a different directory, try and use the
relative path from your working directory to view the file using the less
command e.g. less ../../filename
Thank you for your patience and see at you for the first part
of the IBT Introduction to Linux Session 3 – Extracting
information from files (Session 3 part 1).