Linux Workshop Session 1
description
Transcript of Linux Workshop Session 1
![Page 1: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/1.jpg)
Linux WorkshopLinux WorkshopSession 1Session 1
Khadka, Santosh and Panthi, SanjeebKhadka, Santosh and Panthi, SanjeebComputer Science DepartmentComputer Science Department
Lamar UniversLamar University
![Page 2: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/2.jpg)
What is covered?What is covered?
Working with files Working with directories Some basic commands Process related commands Working with vi editor
Brief Introduction to Nano EditorBrief Introduction to Nano Editor
![Page 3: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/3.jpg)
LoginLogin!!
Galaxy Account can be used to access all the Linux machines in the lab 208, both locally and remotely
• To access locally, go to the any machines in 208 and use your username and password to login.
• To access remotely, use any secure shell (ssh) software. Example puTTY .
• Open a terminal by right clicking on your desktop.
• Type pwd -> shows the current working directory. You are in your home directory.
![Page 4: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/4.jpg)
Tools Required for Remote AccessTools Required for Remote Access
• ssh client
- Example: putty for Windows platform
• sftp client
- Example: WinScp for Windows platform
• remote sftp compatible editor
- Example: jEdit for platform that supports java
![Page 5: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/5.jpg)
Working with filesWorking with files
• To list all the files and/or folders in a current directory by default.
ls [option]… [file]…
• Options:
• -a: to list all files
• -l: to list in long format showing file attributes and permission
• --author : gives the author name of the files. Better use with the combination of –l.
• File: Default is current working directory.
![Page 6: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/6.jpg)
Working with filesWorking with files
• vi <filename> -opens a file to edit if exist, otherwise creates new file to edit
• ls - lists contents in current directory
• ls /etc - lists contents in directory /etc
• ls -a - this will list all file including those beginning with
the'.' that would normally be hidden from view.
• Output redirection - Copies the output to some other file.
Example: ls –l > filename (overwritten)
ls –l >> filename (appended)
![Page 7: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/7.jpg)
• ls -l - this gives a long listing showing file attributes and file
permissions.
drwxrwxr-x 6 santoshk santoshk 4096 Sep 14 11:39 test
-rw-rw-r-- 1 santoshk santoshk 140 Nov 17 09:08 test1.c
• cat < <filename> filename>
- displays the content of the file
- example: cat filename
- cat –n filename (-n option for giving the line number)d
• cp <cp <sourcefile> <destinationfile>sourcefile> <destinationfile>
- copy the content of the file
- example: cp sourcefile.txt destnationfile.txt (source file is not deleted/modified)
Working with filesWorking with files
![Page 8: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/8.jpg)
• scriptscript- - to make script fileto make script file- - rrecords everything printed on your screen. The record
is recorded to the filename specified. - starts scripting, once done, type in <ctrl>+d to end scripting Example: script filename - makes a script file with the given filename script -a filename - append the session record to filename, rather than overwrite it• mv <mv <sourcefile> <destinationfile>sourcefile> <destinationfile>
- example: mv sourcefile.txt destiantionfile.txt (the sourcefile file is deleted)
Working with filesWorking with files
![Page 9: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/9.jpg)
• tar - create archives and add or extract files• tar –cvf output.tar inputfile
Example: tar –cvf aos.tar AOS• restore a tar file
- tar -xvf inputfile.tar - .tar file is not compressed by itself. It just bundles the list of
files in one folder.- add -z option to create a compressed tar file
Example: tar -cvzf file.tar.gz
Working with filesWorking with files
![Page 10: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/10.jpg)
.gzip – compress the files
Example gzip <filename>.gunzip –decompress the file Example
gunzip <filename.gz>
Working with filesWorking with files
![Page 11: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/11.jpg)
• wc - counts the number of lines,words and bytes in the file - example: wc –l filename
• head - outputs the first part of the file
- prints the first 10 lines by default
- example: head filename
head -n count filename
• tail - outputs the last part of the file.
- example: tail mylist.cpp
Working with filesWorking with files
![Page 12: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/12.jpg)
• lpr - print command
- command: lpr -p printername filename
Example: lpr -p lab208Printer -#2 file1.txt file2.txt
(this will print two copies of file1.txt and file2.txt)
Note: This is not available at present.
Working with filesWorking with files
![Page 13: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/13.jpg)
• cd - changes the directory
- example: cd <foldername>
• mkdir - creates a directory under the current working
directory.
- example: mkdir <foldername>
• rmdir - remove files
- example: rmdir <directoryname> (for empty directory)
rmdir –rf directoryname (recursive deletion with force)
Working with directoriesWorking with directories
![Page 14: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/14.jpg)
Working with files contd..Working with files contd..
• Absolute path: start with / (root) to go specific directory regardless of where you are now.
• Relative path : start with the current directory to go specific directory.
• Example:
• If, pwd: /home/myfolder then to go /home/myfolder/c++
• Absolute path : cd /home/myfolder/c++
• Relative path : cd c++
![Page 15: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/15.jpg)
• man - man - help manual
- example: man keyword
- press <Space bar> to view the next page
- press <return> to view next line
- type “q” exit
• date - display or change the date
- example: date --date =‘2 days ago’
date --set=“2009-9-4 11:59”
date '+DATE: %m/%d/%y%n TIME:%H:%M:%S'
DATE: 02/08/01 TIME:16:44:55
A few basic commandsA few basic commands
![Page 16: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/16.jpg)
• chmod - - used to change the access permission
- used to set file permissions to owner, group, and other
-rw-rw-r-- 1 santoshk santoshk 140 Nov 17 09:08 test1.c
- r = 4, w = 2, x = 1
- example: chmod 444 mylist
• clear
- clear the screen
• grep - search the file for the specific text
- example: grep string filname
A few basic commandsA few basic commands
![Page 17: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/17.jpg)
• hostname - displays or set the system name
- example: hostname [name]
- with no arguments prints the current host name.
- with arguments sets the current host name to the specified string.
• more
- display output one screen at a time
- related command: less
• quota - display disk usage and limits
- related command: du, df
du –estimate the file space uses
df – disk space uses (amount of disk space available)
A few basic commandsA few basic commands
![Page 18: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/18.jpg)
• ps - gives information about the running processes
- example: ps -ef
ps -fu username
• kill - sends a signal to a process to kill (ends the running process)
- example: kill -9 pid
• exit - exit from the shell. If there are suspended jobs one cannot exit from the shell , so kill the processes
using the kill command.
Process related commandsProcess related commands
![Page 19: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/19.jpg)
• vi filename
• esc - to enter vi command mode
• h: moves the cursor one character left (l right)
• j :moves the cursor one character down (k up)
• u :undo the last changes in the file
• x :deletes the character under the cursor
• d^: deletes all the characters from current cursor to beginning of the line
• d$ :deletes all the characters from current cursor to end of the line
• dw: deletes one word from the cursor.
Brief Introduction to vi EditorBrief Introduction to vi Editor
![Page 20: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/20.jpg)
• Insert text
Enter input mode and:
i a - insert text before ('i') or after ('a') the current character
I A - insert text at beginning ('I') or end ('A') of current line
o O - open new blank line after ('o') or before ('O') current line
r R - replace one(‘r’) or more character (‘R’) by overwriting
Brief Introduction to vi Editor contd..Brief Introduction to vi Editor contd..
![Page 21: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/21.jpg)
Brief Introduction to vi EditorBrief Introduction to vi Editor
• Exiting and Saving - Press esc and type
:q to quit :wq or ZZ to save and quit :q! to quit without saving (!= Forcefully) :w to save the file :w filename to save current file under name filename
• Copy and Paste text nyy or nY - 'copies' n number of line p P - insert the contents of the paste buffer [ after /
before ] the current line/character.
![Page 22: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/22.jpg)
• Delete text
x X - Delete current ('x') or previous ('X') character
dw - Delete the current word
dd - Delete the current line
D - Delete the rest of the line
5dd - Delete the next five lines
37Gdd - Delete line 37
J - Join lines
• Undo
u - Undo most recent change to the file
Brief Introduction to vi EditorBrief Introduction to vi Editor
![Page 23: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/23.jpg)
• Global Searching and replace:
/text - Search forward for some <text>
?text - Search backward for some <text>
n - Repeat the previous search for the 'next' occurrence
N - Repeat the previous search but in the opposite direction
' ' (two single quotes) - Go back to where you where previously
:1,$s/oldtext/newtext/g - global substitutions
Brief Introduction to vi EditorBrief Introduction to vi Editor
![Page 24: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/24.jpg)
• Other popular commands
^ - go to start of line
$ - go to end of line
:1 - goes to top of file
:5 - goes to fifth line of file
:$ - goes to bottom of file
:set nu - will number all your lines
:set nonu - turn off line numbering
Ctrl-g - show line number of current line
Brief Introduction to vi EditorBrief Introduction to vi Editor
![Page 25: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/25.jpg)
• To edit a file called filename, type nano filename.
• cntrl g - (^G) with display a Help file with a bunch of information about using nano.
• cntrl o - (^O) or (f3) will write or save the file
• cntrl x - (^X) will exit the program and return you to the prompt
• cntrl d - (^D) delete character currently under the cursor
• cntrl k - (^K) delete entire line
• cntrl u - (^U) paste text
• ^\ - search for (and replace) a string of characters
• BackSpace delete character currently in front of the cursor
Brief Introduction to Nano EditorBrief Introduction to Nano Editor
![Page 26: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/26.jpg)
• C++ file
g++ [options] source_file –o outputfile
g++ myfile.cpp
g++ -Wall myfile.cpp -o outputfile
• C file
gcc [options] source_file –o outputfile
gcc myfile.c
• java file
javac Myfile.java
java Myfile
Compiling files in linuxCompiling files in linux
![Page 27: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/27.jpg)
• gdb outputfile
• To set the break• (gdb) break filename:line number
• (gdb) functionname
• To remove the break• (gdb) clear function /line number
• To run• (gdb) r
• (gdb) step (each step)
• (gdb) next [count] // how many line
Debuggin c/c++ fileDebuggin c/c++ file
![Page 28: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/28.jpg)
• To watch the variables• (gdb) watch variablename
• (gdb) watch expression
• To quit• (gdb) q
Debuggin c/c++ fileDebuggin c/c++ file
![Page 29: Linux Workshop Session 1](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814887550346895db59991/html5/thumbnails/29.jpg)
Thank You !!!Thank You !!!