Module 1 Session 1 Part 2 Linux
Module 1 Session 1 Part 2 Linux
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Text editors
nano
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Get started with nano
• nano file1
• Type “my first test file with nano”
• Hit enter to move to another line and type “the second
line of test”
• One you finish typing, hit Ctrl+x
• Save modified buffer (ANSWERING "No" WILL
DESTROY CHANGES) ?
• Hit Y
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Basic manupulating file commands
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Displaying whole content of a file or parts of it (default + options)
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
View file content: less command
• cp filename dirpath
🡺 Make a copy of the file (or directory) into the specified
destination directory
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Copying command: 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
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
The rm command
The rm command deletes files and directories
To remove a file:
rm filename
To remove many files:
rm filename1 filename2
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Some statistics about your file content: wc command
<options> <filename>
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
grep command
Example:
Extract lines containing the term sequence from a file: grep
sequence <filename>
Extract lines that do not contain pattern xxx from a file: grep
–v sequence <filename>
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
grep example
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
cut command
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Practical 2
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Instructions
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Additional details about cp and nano
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Some nano shortcuts
• To search for a text string, hit Ctrl+W, and enter your search term
• This search can then be cancelled mid-execution by hitting Ctrl+C
without destroying your buffer
• Ctrl+X: finish typing and close an open file
Remember: nano
- Opens the file if it’s already existing, you can modify and save
changes
- Creates a new file in the specified path if it does not exist
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS
Other examples: cp
Current Attribution:https://github.com/WCSCourses/GSBAfrica2023
Original Attribution: https://github.com/WTAC-NGS