0% found this document useful (0 votes)
2 views17 pages

IBT Linux Session 2 Part 2 Intro To Linux Sumir Panji

Bionformatiques skills

Uploaded by

emileyonli13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views17 pages

IBT Linux Session 2 Part 2 Intro To Linux Sumir Panji

Bionformatiques skills

Uploaded by

emileyonli13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

IBT Introduction to Linux –

File manipulation commands


(Session 2 part 2)

Sumir Panji
Acknowledgements: Amel Ghouila

<Presenter institution logo> <Event date>


Learning Objectives

● Learn how to view files content


● Learn basic commands to manage files and directories
● Learn some useful wildcards
Learning Outcomes

● Be able to view files content


● Be able to manage files and directories
● Be able to use some wildcards
Displaying file content (default + options)
• Please also refer to the man pages
• cat: view the content of a short file
syntax: cat <filename>
• more: view the content of a long file and navigate through it
syntax: more <filename>
• less: view the content of a long file, by portions
syntax: less <filename>
• head: view the first lines of a long file
syntax: head <filename>
• tail: view the last lines of a long file
syntax: tail <filename>
Displaying file content: less command

• 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

Structure: less filename e.g. less filename.fasta


• Move a page down: either use the page down key or space
• Move a page up: use the page up key
• To exit less, type q
• To go to the end of the text file, type g
• To find a pattern such as name in the file while using less, type /pattern e.g.
/aattcgg
Displaying file content: head / tail commands

•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, move and remove files or directories

• cp: copy files and directories


Structure cp <pathfrom> <path to>

• mv: move or rename files and directories


Structure mv <pathfrom> <path to>

• rm: remove files and directories


Structure rm pathname
File manipulation commands – Copy (cp)

● Simplest form: cp file1 file2

➔ 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

● Add the interactive mode to prompt user before deleting with –i


rm -i filename1 filename2

● Delete directories with all their contents


rm -r dir1 dir2
File manipulation commands – Remove (rm)
• The rm command deletes files and directories (beware!!)

• Linux does not have an undelete command

• 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

• A group of special characters called wildcards allow selecting filenames


based on pattern of characters
Wildcards
Wildcard Meaning
* Matches any characters
? Matches any single character
[!characters] Matches any character that is not a member of
the set characters
[characters] Matches any character that is a member of the set
characters. The set of characters may also be expressed
as a POSIX character class such as one of the following:
[:alnum:] Alphanumeric characters
[:alpha:] Alphabetic characters
[:digit:] Numerals
[:upper:] Uppercase alphabetic characters
[:lower:] Lowercase alphabetic characters
Source: http://linuxcommand.org
Wildcards examples
Wildcard Meaning
a* Any file name starting with a
* All possible filenames
A*.fasta All filenames that begin with A and end with .fasta
????.vcf Any filenames that contain exactly 4 characters and end
with .vcf
[abc]* Any filename that begins with "a" or "b" or "c" followed by
any other characters
[[:upper:]]* Any filename that begins with an uppercase letter. This is an
example of a character class
Activities

• 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).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy