Basic Commands in Linux - PowerPoint PPT Presentation

About This Presentation
Title:

Basic Commands in Linux

Description:

Title: Basic Commands in Linux Author: shraddha Last modified by: Santosh Khadka Document presentation format: On-screen Show (4:3) Other titles: Arial Times New ... – PowerPoint PPT presentation

Number of Views:443
Avg rating:3.0/5.0
Slides: 30
Provided by: Shr64
Category:
Tags: basic | commands | linux

less

Transcript and Presenter's Notes

Title: Basic Commands in Linux


1
Linux Workshop Session 1
Khadka, Santosh and Panthi, Sanjeeb Computer
Science Department Lamar University
2
What is covered?
  • Working with files
  • Working with directories
  • Some basic commands
  • Process related commands
  • Working with vi editor
  • Brief Introduction to Nano Editor

3
Login!
  • 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 -gt shows the current working directory.
    You are in your home directory.

4
Tools 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

5
Working 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.

6
Working with files
  • vi ltfilenamegt -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 gt filename (overwritten)?
  • ls l gtgt filename (appended)?

7
Working with files
  • ls -l - this gives a long listing showing
    file attributes and file
  • permissions.
  • drwxrwxr-x 6 santoshk santoshk 4096 Sep 14
    1139 test
  • -rw-rw-r-- 1 santoshk santoshk 140 Nov 17
    0908 test1.c
  • cat ltfilenamegt
  • - displays the content of the file
  • - example cat filename
  • - cat n filename (-n option for giving the line
    number)d
  • cp ltsourcefilegt ltdestinationfilegt
  • - copy the content of the file
  • - example cp sourcefile.txt destnationfile.txt
    (source file is not deleted/modified)?

8
Working with files
  • script
  • - to make script file
  • - records everything printed on your screen.
    The record is
  • recorded to the filename specified.
  • - starts scripting, once done, type
    in ltctrlgtd 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 ltsourcefilegt ltdestinationfilegt
  • - example mv sourcefile.txt destiantionfile.txt
    (the sourcefile file is deleted)?

9
Working with files
  • 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

10
Working with files
.gzip compress the files Example
gzip ltfilenamegt .gunzip decompress the
file Example gunzip ltfilename.gzgt
11
Working with files
  • 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

12
Working with files
  • 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.

13
Working with directories
  • cd - changes the directory
  • - example cd ltfoldernamegt
  • mkdir - creates a directory under the current
    working
  • directory.
  • - example mkdir ltfoldernamegt
  • rmdir - remove files
  • - example rmdir ltdirectorynamegt
    (for empty directory)?
  • rmdir rf directoryname (recursive
    deletion with force)?

14
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

15
A few basic commands
  • man - help manual
  • - example man keyword
  • - press ltSpace bargt to view the next page
  • - press ltreturngt to view next line
  • - type q exit
  • date - display or change the date
  • - example date --date 2 days ago
  • date --set2009-9-4 1159
  • date 'DATE m/d/yn TIMEHMS'
  • DATE
    02/08/01
    TIME164455

16
A few basic commands
  • 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
    0908 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

17
A few basic commands
  • 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)

18
Process related commands
  • 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.

19
Brief Introduction to vi Editor
  • 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.

20
Brief Introduction to vi Editor contd..
  • 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

21
Brief 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.


22
Brief Introduction to vi Editor
  • 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

23
Brief Introduction to vi Editor
  • Global Searching and replace
  • /text - Search forward for some lttextgt
  • ?text - Search backward for some lttextgt
  • 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

24
Brief Introduction to vi Editor
  • 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

25
Brief Introduction to Nano Editor
  • 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

26
Compiling files in linux
  • 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

27
Debuggin c/c file
  • gdb outputfile
  • To set the break
  • (gdb) break filenameline 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

28
Debuggin c/c file
  • To watch the variables
  • (gdb) watch variablename
  • (gdb) watch expression
  • To quit
  • (gdb) q

29
Thank You !!!
Write a Comment
User Comments (0)
About PowerShow.com